2 * Copyright (c) 2020 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>
25 #include <dali/integration-api/debug.h>
28 #include <dali-toolkit/internal/text/character-set-conversion.h>
29 #include <dali-toolkit/internal/text/layouts/layout-parameters.h>
30 #include <dali-toolkit/internal/text/markup-processor.h>
31 #include <dali-toolkit/internal/text/text-controller-event-handler.h>
32 #include <dali-toolkit/internal/text/text-controller-impl.h>
33 #include <dali-toolkit/internal/text/text-controller-input-font-handler.h>
34 #include <dali-toolkit/internal/text/text-controller-placeholder-handler.h>
35 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
40 #if defined(DEBUG_ENABLED)
41 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
44 const float MAX_FLOAT = std::numeric_limits<float>::max();
46 const std::string EMPTY_STRING("");
48 float ConvertToEven( float value )
50 int intValue(static_cast<int>( value ));
51 return static_cast<float>( intValue + ( intValue & 1 ) );
54 int ConvertPixelToPint( float pixel )
56 unsigned int horizontalDpi = 0u;
57 unsigned int verticalDpi = 0u;
58 Dali::TextAbstraction::FontClient fontClient = Dali::TextAbstraction::FontClient::Get();
59 fontClient.GetDpi( horizontalDpi, verticalDpi );
61 return ( pixel * 72.f ) / static_cast< float >( horizontalDpi );
75 // public : Constructor.
77 ControllerPtr Controller::New()
79 return ControllerPtr( new Controller() );
82 ControllerPtr Controller::New( ControlInterface* controlInterface )
84 return ControllerPtr( new Controller( controlInterface ) );
87 ControllerPtr Controller::New( ControlInterface* controlInterface,
88 EditableControlInterface* editableControlInterface,
89 SelectableControlInterface* selectableControlInterface )
91 return ControllerPtr( new Controller( controlInterface,
92 editableControlInterface,
93 selectableControlInterface ) );
96 // public : Configure the text controller.
98 void Controller::EnableTextInput( DecoratorPtr decorator, InputMethodContext& inputMethodContext )
102 delete mImpl->mEventData;
103 mImpl->mEventData = NULL;
105 // Nothing else to do.
109 if( NULL == mImpl->mEventData )
111 mImpl->mEventData = new EventData( decorator, inputMethodContext );
115 void Controller::SetGlyphType( TextAbstraction::GlyphType glyphType )
117 // Metrics for bitmap & vector based glyphs are different
118 mImpl->mMetrics->SetGlyphType( glyphType );
120 // Clear the font-specific data
123 mImpl->RequestRelayout();
126 void Controller::SetMarkupProcessorEnabled( bool enable )
128 if( enable != mImpl->mMarkupProcessorEnabled )
130 //If Text was already set, call the SetText again for enabling or disabling markup
131 mImpl->mMarkupProcessorEnabled = enable;
138 bool Controller::IsMarkupProcessorEnabled() const
140 return mImpl->mMarkupProcessorEnabled;
143 void Controller::SetAutoScrollEnabled( bool enable )
145 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 );
147 if( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX )
151 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled for SINGLE_LINE_BOX\n" );
152 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
162 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled Disabling autoscroll\n");
163 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
170 mImpl->mIsAutoScrollEnabled = enable;
171 mImpl->RequestRelayout();
175 DALI_LOG_WARNING( "Attempted AutoScrolling on a non SINGLE_LINE_BOX, request ignored\n" );
176 mImpl->mIsAutoScrollEnabled = false;
180 bool Controller::IsAutoScrollEnabled() const
182 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::IsAutoScrollEnabled[%s]\n", mImpl->mIsAutoScrollEnabled?"true":"false" );
184 return mImpl->mIsAutoScrollEnabled;
187 CharacterDirection Controller::GetAutoScrollDirection() const
189 return mImpl->mIsTextDirectionRTL;
192 float Controller::GetAutoScrollLineAlignment() const
196 if( mImpl->mModel->mVisualModel &&
197 ( 0u != mImpl->mModel->mVisualModel->mLines.Count() ) )
199 offset = ( *mImpl->mModel->mVisualModel->mLines.Begin() ).alignmentOffset;
205 void Controller::SetHorizontalScrollEnabled( bool enable )
207 if( ( NULL != mImpl->mEventData ) &&
208 mImpl->mEventData->mDecorator )
210 mImpl->mEventData->mDecorator->SetHorizontalScrollEnabled( enable );
213 bool Controller::IsHorizontalScrollEnabled() const
215 if( ( NULL != mImpl->mEventData ) &&
216 mImpl->mEventData->mDecorator )
218 return mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
224 void Controller::SetVerticalScrollEnabled( bool enable )
226 if( ( NULL != mImpl->mEventData ) &&
227 mImpl->mEventData->mDecorator )
229 if( mImpl->mEventData->mDecorator )
231 mImpl->mEventData->mDecorator->SetVerticalScrollEnabled( enable );
236 bool Controller::IsVerticalScrollEnabled() const
238 if( ( NULL != mImpl->mEventData ) &&
239 mImpl->mEventData->mDecorator )
241 return mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
247 void Controller::SetSmoothHandlePanEnabled( bool enable )
249 if( ( NULL != mImpl->mEventData ) &&
250 mImpl->mEventData->mDecorator )
252 mImpl->mEventData->mDecorator->SetSmoothHandlePanEnabled( enable );
256 bool Controller::IsSmoothHandlePanEnabled() const
258 if( ( NULL != mImpl->mEventData ) &&
259 mImpl->mEventData->mDecorator )
261 return mImpl->mEventData->mDecorator->IsSmoothHandlePanEnabled();
267 void Controller::SetMaximumNumberOfCharacters( Length maxCharacters )
269 mImpl->mMaximumNumberOfCharacters = maxCharacters;
272 int Controller::GetMaximumNumberOfCharacters()
274 return mImpl->mMaximumNumberOfCharacters;
277 void Controller::SetEnableCursorBlink( bool enable )
279 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "TextInput disabled" );
281 if( NULL != mImpl->mEventData )
283 mImpl->mEventData->mCursorBlinkEnabled = enable;
286 mImpl->mEventData->mDecorator )
288 mImpl->mEventData->mDecorator->StopCursorBlink();
293 bool Controller::GetEnableCursorBlink() const
295 if( NULL != mImpl->mEventData )
297 return mImpl->mEventData->mCursorBlinkEnabled;
303 void Controller::SetMultiLineEnabled( bool enable )
305 const Layout::Engine::Type layout = enable ? Layout::Engine::MULTI_LINE_BOX : Layout::Engine::SINGLE_LINE_BOX;
307 if( layout != mImpl->mLayoutEngine.GetLayout() )
309 // Set the layout type.
310 mImpl->mLayoutEngine.SetLayout( layout );
312 // Set the flags to redo the layout operations
313 const OperationsMask layoutOperations = static_cast<OperationsMask>( LAYOUT |
318 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
319 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | layoutOperations );
321 // Need to recalculate natural size
322 mImpl->mRecalculateNaturalSize = true;
324 mImpl->RequestRelayout();
328 bool Controller::IsMultiLineEnabled() const
330 return Layout::Engine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
333 void Controller::SetHorizontalAlignment( Text::HorizontalAlignment::Type alignment )
335 if( alignment != mImpl->mModel->mHorizontalAlignment )
337 // Set the alignment.
338 mImpl->mModel->mHorizontalAlignment = alignment;
340 // Set the flag to redo the alignment operation.
341 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
343 if( mImpl->mEventData )
345 mImpl->mEventData->mUpdateAlignment = true;
347 // Update the cursor if it's in editing mode
348 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
350 mImpl->ChangeState( EventData::EDITING );
351 mImpl->mEventData->mUpdateCursorPosition = true;
355 mImpl->RequestRelayout();
359 Text::HorizontalAlignment::Type Controller::GetHorizontalAlignment() const
361 return mImpl->mModel->mHorizontalAlignment;
364 void Controller::SetVerticalAlignment( VerticalAlignment::Type alignment )
366 if( alignment != mImpl->mModel->mVerticalAlignment )
368 // Set the alignment.
369 mImpl->mModel->mVerticalAlignment = alignment;
371 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
373 mImpl->RequestRelayout();
377 VerticalAlignment::Type Controller::GetVerticalAlignment() const
379 return mImpl->mModel->mVerticalAlignment;
382 bool Controller::IsIgnoreSpacesAfterText() const
384 return mImpl->mModel->mIgnoreSpacesAfterText;
387 void Controller::SetIgnoreSpacesAfterText( bool ignore )
389 mImpl->mModel->mIgnoreSpacesAfterText = ignore;
392 bool Controller::IsMatchSystemLanguageDirection() const
394 return mImpl->mModel->mMatchSystemLanguageDirection;
397 void Controller::SetMatchSystemLanguageDirection( bool match )
399 mImpl->mModel->mMatchSystemLanguageDirection = match;
402 void Controller::SetLayoutDirection( Dali::LayoutDirection::Type layoutDirection )
404 mImpl->mLayoutDirection = layoutDirection;
407 bool Controller::IsShowingRealText() const
409 return mImpl->IsShowingRealText();
413 void Controller::SetLineWrapMode( Text::LineWrap::Mode lineWrapMode )
415 if( lineWrapMode != mImpl->mModel->mLineWrapMode )
417 // Set the text wrap mode.
418 mImpl->mModel->mLineWrapMode = lineWrapMode;
421 // Update Text layout for applying wrap mode
422 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
427 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
428 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
429 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
432 mImpl->RequestRelayout();
436 Text::LineWrap::Mode Controller::GetLineWrapMode() const
438 return mImpl->mModel->mLineWrapMode;
441 void Controller::SetTextElideEnabled( bool enabled )
443 mImpl->mModel->mElideEnabled = enabled;
446 bool Controller::IsTextElideEnabled() const
448 return mImpl->mModel->mElideEnabled;
451 void Controller::SetTextFitEnabled(bool enabled)
453 mImpl->mTextFitEnabled = enabled;
456 bool Controller::IsTextFitEnabled() const
458 return mImpl->mTextFitEnabled;
461 void Controller::SetTextFitMinSize( float minSize, FontSizeType type )
467 mImpl->mTextFitMinSize = minSize;
472 mImpl->mTextFitMinSize = ConvertPixelToPint( minSize );
478 float Controller::GetTextFitMinSize() const
480 return mImpl->mTextFitMinSize;
483 void Controller::SetTextFitMaxSize( float maxSize, FontSizeType type )
489 mImpl->mTextFitMaxSize = maxSize;
494 mImpl->mTextFitMaxSize = ConvertPixelToPint( maxSize );
500 float Controller::GetTextFitMaxSize() const
502 return mImpl->mTextFitMaxSize;
505 void Controller::SetTextFitStepSize( float step, FontSizeType type )
511 mImpl->mTextFitStepSize = step;
516 mImpl->mTextFitStepSize = ConvertPixelToPint( step );
522 float Controller::GetTextFitStepSize() const
524 return mImpl->mTextFitStepSize;
527 void Controller::SetTextFitContentSize(Vector2 size)
529 mImpl->mTextFitContentSize = size;
532 Vector2 Controller::GetTextFitContentSize() const
534 return mImpl->mTextFitContentSize;
537 void Controller::SetPlaceholderTextElideEnabled( bool enabled )
539 PlaceholderHandler::SetPlaceholderTextElideEnabled(*this, enabled);
542 bool Controller::IsPlaceholderTextElideEnabled() const
544 return PlaceholderHandler::IsPlaceholderTextElideEnabled(*this);
547 void Controller::SetSelectionEnabled( bool enabled )
549 mImpl->mEventData->mSelectionEnabled = enabled;
552 bool Controller::IsSelectionEnabled() const
554 return mImpl->mEventData->mSelectionEnabled;
557 void Controller::SetShiftSelectionEnabled( bool enabled )
559 mImpl->mEventData->mShiftSelectionFlag = enabled;
562 bool Controller::IsShiftSelectionEnabled() const
564 return mImpl->mEventData->mShiftSelectionFlag;
567 void Controller::SetGrabHandleEnabled( bool enabled )
569 mImpl->mEventData->mGrabHandleEnabled = enabled;
572 bool Controller::IsGrabHandleEnabled() const
574 return mImpl->mEventData->mGrabHandleEnabled;
577 void Controller::SetGrabHandlePopupEnabled(bool enabled)
579 mImpl->mEventData->mGrabHandlePopupEnabled = enabled;
582 bool Controller::IsGrabHandlePopupEnabled() const
584 return mImpl->mEventData->mGrabHandlePopupEnabled;
589 void Controller::SetText( const std::string& text )
591 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" );
593 // Reset keyboard as text changed
594 mImpl->ResetInputMethodContext();
596 // Remove the previously set text and style.
602 CharacterIndex lastCursorIndex = 0u;
604 if( NULL != mImpl->mEventData )
606 // If popup shown then hide it by switching to Editing state
607 if( ( EventData::SELECTING == mImpl->mEventData->mState ) ||
608 ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
609 ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) ||
610 ( EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState ) )
612 mImpl->ChangeState( EventData::EDITING );
618 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mTextColor );
620 MarkupProcessData markupProcessData( mImpl->mModel->mLogicalModel->mColorRuns,
621 mImpl->mModel->mLogicalModel->mFontDescriptionRuns,
622 mImpl->mModel->mLogicalModel->mEmbeddedItems );
624 Length textSize = 0u;
625 const uint8_t* utf8 = NULL;
626 if( mImpl->mMarkupProcessorEnabled )
628 ProcessMarkupString( text, markupProcessData );
629 textSize = markupProcessData.markupProcessedText.size();
631 // This is a bit horrible but std::string returns a (signed) char*
632 utf8 = reinterpret_cast<const uint8_t*>( markupProcessData.markupProcessedText.c_str() );
636 textSize = text.size();
638 // This is a bit horrible but std::string returns a (signed) char*
639 utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
642 // Convert text into UTF-32
643 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
644 utf32Characters.Resize( textSize );
646 // Transform a text array encoded in utf8 into an array encoded in utf32.
647 // It returns the actual number of characters.
648 Length characterCount = Utf8ToUtf32( utf8, textSize, utf32Characters.Begin() );
649 utf32Characters.Resize( characterCount );
651 DALI_ASSERT_DEBUG( textSize >= characterCount && "Invalid UTF32 conversion length" );
652 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", this, textSize, mImpl->mModel->mLogicalModel->mText.Count() );
654 // The characters to be added.
655 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
657 // To reset the cursor position
658 lastCursorIndex = characterCount;
660 // Update the rest of the model during size negotiation
661 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
663 // The natural size needs to be re-calculated.
664 mImpl->mRecalculateNaturalSize = true;
666 // The text direction needs to be updated.
667 mImpl->mUpdateTextDirection = true;
669 // Apply modifications to the model
670 mImpl->mOperationsPending = ALL_OPERATIONS;
674 ShowPlaceholderText();
677 // Resets the cursor position.
678 ResetCursorPosition( lastCursorIndex );
680 // Scrolls the text to make the cursor visible.
681 ResetScrollPosition();
683 mImpl->RequestRelayout();
685 if( NULL != mImpl->mEventData )
687 // Cancel previously queued events
688 mImpl->mEventData->mEventQueue.clear();
691 // Do this last since it provides callbacks into application code.
692 if( NULL != mImpl->mEditableControlInterface )
694 mImpl->mEditableControlInterface->TextChanged();
698 void Controller::GetText( std::string& text ) const
700 if( !mImpl->IsShowingPlaceholderText() )
702 // Retrieves the text string.
703 mImpl->GetText( 0u, text );
707 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this );
711 void Controller::SetPlaceholderText( PlaceholderType type, const std::string& text )
713 PlaceholderHandler::SetPlaceholderText(*this, type, text);
716 void Controller::GetPlaceholderText( PlaceholderType type, std::string& text ) const
718 PlaceholderHandler::GetPlaceholderText(*this, type, text );
721 void Controller::UpdateAfterFontChange( const std::string& newDefaultFont )
723 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
725 if( !mImpl->mFontDefaults->familyDefined ) // If user defined font then should not update when system font changes
727 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
728 mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
732 mImpl->RequestRelayout();
736 // public : Default style & Input style
738 void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
740 if( NULL == mImpl->mFontDefaults )
742 mImpl->mFontDefaults = new FontDefaults();
745 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
746 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
747 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
749 if( mImpl->mEventData )
751 // Update the cursor position if it's in editing mode
752 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
754 mImpl->mEventData->mDecoratorUpdated = true;
755 mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font family is updated.
759 // Clear the font-specific data
762 mImpl->RequestRelayout();
765 const std::string& Controller::GetDefaultFontFamily() const
767 if( NULL != mImpl->mFontDefaults )
769 return mImpl->mFontDefaults->mFontDescription.family;
775 void Controller::SetPlaceholderFontFamily( const std::string& placeholderTextFontFamily )
777 PlaceholderHandler::SetPlaceholderFontFamily(*this, placeholderTextFontFamily);
780 const std::string& Controller::GetPlaceholderFontFamily() const
782 return PlaceholderHandler::GetPlaceholderFontFamily(*this);
785 void Controller::SetDefaultFontWeight( FontWeight weight )
787 if( NULL == mImpl->mFontDefaults )
789 mImpl->mFontDefaults = new FontDefaults();
792 mImpl->mFontDefaults->mFontDescription.weight = weight;
793 mImpl->mFontDefaults->weightDefined = true;
795 if( mImpl->mEventData )
797 // Update the cursor position if it's in editing mode
798 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
800 mImpl->mEventData->mDecoratorUpdated = true;
801 mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font weight is updated.
805 // Clear the font-specific data
808 mImpl->RequestRelayout();
811 bool Controller::IsDefaultFontWeightDefined() const
813 if( NULL != mImpl->mFontDefaults )
815 return mImpl->mFontDefaults->weightDefined;
821 FontWeight Controller::GetDefaultFontWeight() const
823 if( NULL != mImpl->mFontDefaults )
825 return mImpl->mFontDefaults->mFontDescription.weight;
828 return TextAbstraction::FontWeight::NORMAL;
831 void Controller::SetPlaceholderTextFontWeight( FontWeight weight )
833 PlaceholderHandler::SetPlaceholderTextFontWeight(*this, weight);
836 bool Controller::IsPlaceholderTextFontWeightDefined() const
838 return PlaceholderHandler::IsPlaceholderTextFontWeightDefined(*this);;
841 FontWeight Controller::GetPlaceholderTextFontWeight() const
843 return PlaceholderHandler::GetPlaceholderTextFontWeight(*this);
846 void Controller::SetDefaultFontWidth( FontWidth width )
848 if( NULL == mImpl->mFontDefaults )
850 mImpl->mFontDefaults = new FontDefaults();
853 mImpl->mFontDefaults->mFontDescription.width = width;
854 mImpl->mFontDefaults->widthDefined = true;
856 if( mImpl->mEventData )
858 // Update the cursor position if it's in editing mode
859 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
861 mImpl->mEventData->mDecoratorUpdated = true;
862 mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font width is updated.
866 // Clear the font-specific data
869 mImpl->RequestRelayout();
872 bool Controller::IsDefaultFontWidthDefined() const
874 if( NULL != mImpl->mFontDefaults )
876 return mImpl->mFontDefaults->widthDefined;
882 FontWidth Controller::GetDefaultFontWidth() const
884 if( NULL != mImpl->mFontDefaults )
886 return mImpl->mFontDefaults->mFontDescription.width;
889 return TextAbstraction::FontWidth::NORMAL;
892 void Controller::SetPlaceholderTextFontWidth( FontWidth width )
894 PlaceholderHandler::SetPlaceholderTextFontWidth(*this, width);
897 bool Controller::IsPlaceholderTextFontWidthDefined() const
899 return PlaceholderHandler::IsPlaceholderTextFontWidthDefined(*this);
902 FontWidth Controller::GetPlaceholderTextFontWidth() const
904 return PlaceholderHandler::GetPlaceholderTextFontWidth(*this);
907 void Controller::SetDefaultFontSlant( FontSlant slant )
909 if( NULL == mImpl->mFontDefaults )
911 mImpl->mFontDefaults = new FontDefaults();
914 mImpl->mFontDefaults->mFontDescription.slant = slant;
915 mImpl->mFontDefaults->slantDefined = true;
917 if( mImpl->mEventData )
919 // Update the cursor position if it's in editing mode
920 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
922 mImpl->mEventData->mDecoratorUpdated = true;
923 mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font slant is updated.
927 // Clear the font-specific data
930 mImpl->RequestRelayout();
933 bool Controller::IsDefaultFontSlantDefined() const
935 if( NULL != mImpl->mFontDefaults )
937 return mImpl->mFontDefaults->slantDefined;
942 FontSlant Controller::GetDefaultFontSlant() const
944 if( NULL != mImpl->mFontDefaults )
946 return mImpl->mFontDefaults->mFontDescription.slant;
949 return TextAbstraction::FontSlant::NORMAL;
952 void Controller::SetPlaceholderTextFontSlant( FontSlant slant )
954 PlaceholderHandler::SetPlaceholderTextFontSlant(*this, slant);
957 bool Controller::IsPlaceholderTextFontSlantDefined() const
959 return PlaceholderHandler::IsPlaceholderTextFontSlantDefined(*this);
962 FontSlant Controller::GetPlaceholderTextFontSlant() const
964 return PlaceholderHandler::GetPlaceholderTextFontSlant(*this);
967 void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
969 if( NULL == mImpl->mFontDefaults )
971 mImpl->mFontDefaults = new FontDefaults();
978 mImpl->mFontDefaults->mDefaultPointSize = fontSize;
979 mImpl->mFontDefaults->sizeDefined = true;
984 // Point size = Pixel size * 72.f / DPI
985 unsigned int horizontalDpi = 0u;
986 unsigned int verticalDpi = 0u;
987 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
988 fontClient.GetDpi( horizontalDpi, verticalDpi );
990 mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
991 mImpl->mFontDefaults->sizeDefined = true;
996 if( mImpl->mEventData )
998 // Update the cursor position if it's in editing mode
999 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
1001 mImpl->mEventData->mDecoratorUpdated = true;
1002 mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font size is updated.
1006 // Clear the font-specific data
1009 mImpl->RequestRelayout();
1012 float Controller::GetDefaultFontSize( FontSizeType type ) const
1015 if( NULL != mImpl->mFontDefaults )
1021 value = mImpl->mFontDefaults->mDefaultPointSize;
1026 // Pixel size = Point size * DPI / 72.f
1027 unsigned int horizontalDpi = 0u;
1028 unsigned int verticalDpi = 0u;
1029 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1030 fontClient.GetDpi( horizontalDpi, verticalDpi );
1032 value = mImpl->mFontDefaults->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1042 void Controller::SetPlaceholderTextFontSize( float fontSize, FontSizeType type )
1044 PlaceholderHandler::SetPlaceholderTextFontSize(*this, fontSize, type);
1047 float Controller::GetPlaceholderTextFontSize( FontSizeType type ) const
1049 return PlaceholderHandler::GetPlaceholderTextFontSize(*this, type);
1052 void Controller::SetDefaultColor( const Vector4& color )
1054 mImpl->mTextColor = color;
1056 if( !mImpl->IsShowingPlaceholderText() )
1058 mImpl->mModel->mVisualModel->SetTextColor( color );
1060 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
1062 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1064 mImpl->RequestRelayout();
1068 const Vector4& Controller::GetDefaultColor() const
1070 return mImpl->mTextColor;
1073 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
1075 PlaceholderHandler::SetPlaceholderTextColor(*this, textColor);
1078 const Vector4& Controller::GetPlaceholderTextColor() const
1080 return PlaceholderHandler::GetPlaceholderTextColor(*this);
1083 void Controller::SetShadowOffset( const Vector2& shadowOffset )
1085 mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
1087 mImpl->RequestRelayout();
1090 const Vector2& Controller::GetShadowOffset() const
1092 return mImpl->mModel->mVisualModel->GetShadowOffset();
1095 void Controller::SetShadowColor( const Vector4& shadowColor )
1097 mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
1099 mImpl->RequestRelayout();
1102 const Vector4& Controller::GetShadowColor() const
1104 return mImpl->mModel->mVisualModel->GetShadowColor();
1107 void Controller::SetShadowBlurRadius( const float& shadowBlurRadius )
1109 if ( fabsf( GetShadowBlurRadius() - shadowBlurRadius ) > Math::MACHINE_EPSILON_1 )
1111 mImpl->mModel->mVisualModel->SetShadowBlurRadius( shadowBlurRadius );
1113 mImpl->RequestRelayout();
1117 const float& Controller::GetShadowBlurRadius() const
1119 return mImpl->mModel->mVisualModel->GetShadowBlurRadius();
1122 void Controller::SetUnderlineColor( const Vector4& color )
1124 mImpl->mModel->mVisualModel->SetUnderlineColor( color );
1126 mImpl->RequestRelayout();
1129 const Vector4& Controller::GetUnderlineColor() const
1131 return mImpl->mModel->mVisualModel->GetUnderlineColor();
1134 void Controller::SetUnderlineEnabled( bool enabled )
1136 mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
1138 mImpl->RequestRelayout();
1141 bool Controller::IsUnderlineEnabled() const
1143 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
1146 void Controller::SetUnderlineHeight( float height )
1148 mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
1150 mImpl->RequestRelayout();
1153 float Controller::GetUnderlineHeight() const
1155 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
1158 void Controller::SetOutlineColor( const Vector4& color )
1160 mImpl->mModel->mVisualModel->SetOutlineColor( color );
1162 mImpl->RequestRelayout();
1165 const Vector4& Controller::GetOutlineColor() const
1167 return mImpl->mModel->mVisualModel->GetOutlineColor();
1170 void Controller::SetOutlineWidth( uint16_t width )
1172 mImpl->mModel->mVisualModel->SetOutlineWidth( width );
1174 mImpl->RequestRelayout();
1177 uint16_t Controller::GetOutlineWidth() const
1179 return mImpl->mModel->mVisualModel->GetOutlineWidth();
1182 void Controller::SetBackgroundColor( const Vector4& color )
1184 mImpl->mModel->mVisualModel->SetBackgroundColor( color );
1186 mImpl->RequestRelayout();
1189 const Vector4& Controller::GetBackgroundColor() const
1191 return mImpl->mModel->mVisualModel->GetBackgroundColor();
1194 void Controller::SetBackgroundEnabled( bool enabled )
1196 mImpl->mModel->mVisualModel->SetBackgroundEnabled( enabled );
1198 mImpl->RequestRelayout();
1201 bool Controller::IsBackgroundEnabled() const
1203 return mImpl->mModel->mVisualModel->IsBackgroundEnabled();
1206 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
1208 if( NULL == mImpl->mEmbossDefaults )
1210 mImpl->mEmbossDefaults = new EmbossDefaults();
1213 mImpl->mEmbossDefaults->properties = embossProperties;
1216 const std::string& Controller::GetDefaultEmbossProperties() const
1218 if( NULL != mImpl->mEmbossDefaults )
1220 return mImpl->mEmbossDefaults->properties;
1223 return EMPTY_STRING;
1226 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
1228 if( NULL == mImpl->mOutlineDefaults )
1230 mImpl->mOutlineDefaults = new OutlineDefaults();
1233 mImpl->mOutlineDefaults->properties = outlineProperties;
1236 const std::string& Controller::GetDefaultOutlineProperties() const
1238 if( NULL != mImpl->mOutlineDefaults )
1240 return mImpl->mOutlineDefaults->properties;
1243 return EMPTY_STRING;
1246 bool Controller::SetDefaultLineSpacing( float lineSpacing )
1248 if( std::fabs( lineSpacing - mImpl->mLayoutEngine.GetDefaultLineSpacing() ) > Math::MACHINE_EPSILON_1000 )
1250 mImpl->mLayoutEngine.SetDefaultLineSpacing(lineSpacing);
1251 mImpl->mRecalculateNaturalSize = true;
1257 float Controller::GetDefaultLineSpacing() const
1259 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
1262 bool Controller::SetDefaultLineSize( float lineSize )
1264 if( std::fabs( lineSize - mImpl->mLayoutEngine.GetDefaultLineSize() ) > Math::MACHINE_EPSILON_1000 )
1266 mImpl->mLayoutEngine.SetDefaultLineSize(lineSize);
1267 mImpl->mRecalculateNaturalSize = true;
1273 float Controller::GetDefaultLineSize() const
1275 return mImpl->mLayoutEngine.GetDefaultLineSize();
1278 void Controller::SetInputColor( const Vector4& color )
1280 if( NULL != mImpl->mEventData )
1282 mImpl->mEventData->mInputStyle.textColor = color;
1283 mImpl->mEventData->mInputStyle.isDefaultColor = false;
1285 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1287 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
1289 // Get start and end position of selection
1290 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
1291 const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
1293 // Add the color run.
1294 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1295 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
1297 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
1298 colorRun.color = color;
1299 colorRun.characterRun.characterIndex = startOfSelectedText;
1300 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1302 // Request to relayout.
1303 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1304 mImpl->RequestRelayout();
1306 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1307 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1308 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1313 const Vector4& Controller::GetInputColor() const
1315 if( NULL != mImpl->mEventData )
1317 return mImpl->mEventData->mInputStyle.textColor;
1320 // Return the default text's color if there is no EventData.
1321 return mImpl->mTextColor;
1325 void Controller::SetInputFontFamily( const std::string& fontFamily )
1327 InputFontHandler::SetInputFontFamily(*this, fontFamily);
1330 const std::string& Controller::GetInputFontFamily() const
1332 return InputFontHandler::GetInputFontFamily(*this);
1335 void Controller::SetInputFontWeight( FontWeight weight )
1337 InputFontHandler::SetInputFontWeight(*this, weight);
1340 bool Controller::IsInputFontWeightDefined() const
1342 return InputFontHandler::IsInputFontWeightDefined(*this);
1345 FontWeight Controller::GetInputFontWeight() const
1347 return InputFontHandler::GetInputFontWeight(*this);
1350 void Controller::SetInputFontWidth( FontWidth width )
1352 InputFontHandler::SetInputFontWidth(*this, width);
1355 bool Controller::IsInputFontWidthDefined() const
1357 return InputFontHandler::IsInputFontWidthDefined(*this);
1360 FontWidth Controller::GetInputFontWidth() const
1362 return InputFontHandler::GetInputFontWidth(*this);
1365 void Controller::SetInputFontSlant( FontSlant slant )
1367 InputFontHandler::SetInputFontSlant(*this, slant);
1370 bool Controller::IsInputFontSlantDefined() const
1372 return InputFontHandler::IsInputFontSlantDefined(*this);
1375 FontSlant Controller::GetInputFontSlant() const
1377 return InputFontHandler::GetInputFontSlant(*this);
1380 void Controller::SetInputFontPointSize( float size )
1382 InputFontHandler::SetInputFontPointSize(*this, size);
1385 float Controller::GetInputFontPointSize() const
1387 return InputFontHandler::GetInputFontPointSize(*this);
1390 void Controller::SetInputLineSpacing( float lineSpacing )
1392 if( NULL != mImpl->mEventData )
1394 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1395 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1399 float Controller::GetInputLineSpacing() const
1401 if( NULL != mImpl->mEventData )
1403 return mImpl->mEventData->mInputStyle.lineSpacing;
1409 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1411 if( NULL != mImpl->mEventData )
1413 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1417 const std::string& Controller::GetInputShadowProperties() const
1419 if( NULL != mImpl->mEventData )
1421 return mImpl->mEventData->mInputStyle.shadowProperties;
1424 return EMPTY_STRING;
1427 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1429 if( NULL != mImpl->mEventData )
1431 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1435 const std::string& Controller::GetInputUnderlineProperties() const
1437 if( NULL != mImpl->mEventData )
1439 return mImpl->mEventData->mInputStyle.underlineProperties;
1442 return EMPTY_STRING;
1445 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
1447 if( NULL != mImpl->mEventData )
1449 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1453 const std::string& Controller::GetInputEmbossProperties() const
1455 if( NULL != mImpl->mEventData )
1457 return mImpl->mEventData->mInputStyle.embossProperties;
1460 return GetDefaultEmbossProperties();
1463 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
1465 if( NULL != mImpl->mEventData )
1467 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1471 const std::string& Controller::GetInputOutlineProperties() const
1473 if( NULL != mImpl->mEventData )
1475 return mImpl->mEventData->mInputStyle.outlineProperties;
1478 return GetDefaultOutlineProperties();
1481 void Controller::SetInputModePassword( bool passwordInput )
1483 if( NULL != mImpl->mEventData )
1485 mImpl->mEventData->mPasswordInput = passwordInput;
1489 bool Controller::IsInputModePassword()
1491 if( NULL != mImpl->mEventData )
1493 return mImpl->mEventData->mPasswordInput;
1498 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
1500 if( NULL != mImpl->mEventData )
1502 mImpl->mEventData->mDoubleTapAction = action;
1506 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1508 NoTextTap::Action action = NoTextTap::NO_ACTION;
1510 if( NULL != mImpl->mEventData )
1512 action = mImpl->mEventData->mDoubleTapAction;
1518 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
1520 if( NULL != mImpl->mEventData )
1522 mImpl->mEventData->mLongPressAction = action;
1526 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1528 NoTextTap::Action action = NoTextTap::NO_ACTION;
1530 if( NULL != mImpl->mEventData )
1532 action = mImpl->mEventData->mLongPressAction;
1538 bool Controller::IsUnderlineSetByString()
1540 return mImpl->mUnderlineSetByString;
1543 void Controller::UnderlineSetByString( bool setByString )
1545 mImpl->mUnderlineSetByString = setByString;
1548 bool Controller::IsShadowSetByString()
1550 return mImpl->mShadowSetByString;
1553 void Controller::ShadowSetByString( bool setByString )
1555 mImpl->mShadowSetByString = setByString;
1558 bool Controller::IsOutlineSetByString()
1560 return mImpl->mOutlineSetByString;
1563 void Controller::OutlineSetByString( bool setByString )
1565 mImpl->mOutlineSetByString = setByString;
1568 bool Controller::IsFontStyleSetByString()
1570 return mImpl->mFontStyleSetByString;
1573 void Controller::FontStyleSetByString( bool setByString )
1575 mImpl->mFontStyleSetByString = setByString;
1578 // public : Queries & retrieves.
1580 Layout::Engine& Controller::GetLayoutEngine()
1582 return mImpl->mLayoutEngine;
1585 View& Controller::GetView()
1587 return mImpl->mView;
1590 Vector3 Controller::GetNaturalSize()
1592 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
1593 Vector3 naturalSize;
1595 // Make sure the model is up-to-date before layouting
1596 ProcessModifyEvents();
1598 if( mImpl->mRecalculateNaturalSize )
1600 // Operations that can be done only once until the text changes.
1601 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1607 GET_GLYPH_METRICS );
1609 // Set the update info to relayout the whole text.
1610 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1611 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1613 // Make sure the model is up-to-date before layouting
1614 mImpl->UpdateModel( onlyOnceOperations );
1616 // Layout the text for the new width.
1617 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT | REORDER );
1619 // Store the actual control's size to restore later.
1620 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
1622 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
1623 static_cast<OperationsMask>( onlyOnceOperations |
1625 naturalSize.GetVectorXY() );
1627 // Do not do again the only once operations.
1628 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1630 // Do the size related operations again.
1631 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1634 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1636 // Stores the natural size to avoid recalculate it again
1637 // unless the text/style changes.
1638 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
1640 mImpl->mRecalculateNaturalSize = false;
1642 // Clear the update info. This info will be set the next time the text is updated.
1643 mImpl->mTextUpdateInfo.Clear();
1644 mImpl->mTextUpdateInfo.mClearAll = true;
1646 // Restore the actual control's size.
1647 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
1649 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1653 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
1655 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1658 naturalSize.x = ConvertToEven( naturalSize.x );
1659 naturalSize.y = ConvertToEven( naturalSize.y );
1664 bool Controller::CheckForTextFit( float pointSize, Size& layoutSize )
1667 mImpl->mFontDefaults->mFitPointSize = pointSize;
1668 mImpl->mFontDefaults->sizeDefined = true;
1671 // Operations that can be done only once until the text changes.
1672 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1678 GET_GLYPH_METRICS );
1680 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1681 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1683 // Make sure the model is up-to-date before layouting
1684 mImpl->UpdateModel( onlyOnceOperations );
1686 DoRelayout( Size( layoutSize.width, MAX_FLOAT ),
1687 static_cast<OperationsMask>( onlyOnceOperations | LAYOUT),
1690 // Clear the update info. This info will be set the next time the text is updated.
1691 mImpl->mTextUpdateInfo.Clear();
1692 mImpl->mTextUpdateInfo.mClearAll = true;
1694 if( textSize.width > layoutSize.width || textSize.height > layoutSize.height )
1701 void Controller::FitPointSizeforLayout( Size layoutSize )
1703 const OperationsMask operations = mImpl->mOperationsPending;
1704 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) || mImpl->mTextFitContentSize != layoutSize )
1706 bool actualellipsis = mImpl->mModel->mElideEnabled;
1707 float minPointSize = mImpl->mTextFitMinSize;
1708 float maxPointSize = mImpl->mTextFitMaxSize;
1709 float pointInterval = mImpl->mTextFitStepSize;
1711 mImpl->mModel->mElideEnabled = false;
1712 Vector<float> pointSizeArray;
1715 if( pointInterval < 1.f )
1717 mImpl->mTextFitStepSize = pointInterval = 1.0f;
1720 pointSizeArray.Reserve( static_cast< unsigned int >( ceil( ( maxPointSize - minPointSize ) / pointInterval ) ) );
1722 for( float i = minPointSize; i < maxPointSize; i += pointInterval )
1724 pointSizeArray.PushBack( i );
1727 pointSizeArray.PushBack( maxPointSize );
1729 int bestSizeIndex = 0;
1730 int min = bestSizeIndex + 1;
1731 int max = pointSizeArray.Size() - 1;
1734 int destI = ( min + max ) / 2;
1736 if( CheckForTextFit( pointSizeArray[destI], layoutSize ) )
1738 bestSizeIndex = min;
1744 bestSizeIndex = max;
1748 mImpl->mModel->mElideEnabled = actualellipsis;
1749 mImpl->mFontDefaults->mFitPointSize = pointSizeArray[bestSizeIndex];
1750 mImpl->mFontDefaults->sizeDefined = true;
1755 float Controller::GetHeightForWidth( float width )
1757 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
1758 // Make sure the model is up-to-date before layouting
1759 ProcessModifyEvents();
1762 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ||
1763 mImpl->mTextUpdateInfo.mFullRelayoutNeeded ||
1764 mImpl->mTextUpdateInfo.mClearAll )
1766 // Operations that can be done only once until the text changes.
1767 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1773 GET_GLYPH_METRICS );
1775 // Set the update info to relayout the whole text.
1776 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1777 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1779 // Make sure the model is up-to-date before layouting
1780 mImpl->UpdateModel( onlyOnceOperations );
1783 // Layout the text for the new width.
1784 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
1786 // Store the actual control's width.
1787 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
1789 DoRelayout( Size( width, MAX_FLOAT ),
1790 static_cast<OperationsMask>( onlyOnceOperations |
1794 // Do not do again the only once operations.
1795 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1797 // Do the size related operations again.
1798 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1802 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1804 // Clear the update info. This info will be set the next time the text is updated.
1805 mImpl->mTextUpdateInfo.Clear();
1806 mImpl->mTextUpdateInfo.mClearAll = true;
1808 // Restore the actual control's width.
1809 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
1811 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
1815 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
1816 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
1819 return layoutSize.height;
1822 int Controller::GetLineCount( float width )
1824 GetHeightForWidth( width );
1825 int numberofLines = mImpl->mModel->GetNumberOfLines();
1826 return numberofLines;
1829 const ModelInterface* const Controller::GetTextModel() const
1831 return mImpl->mModel.Get();
1834 float Controller::GetScrollAmountByUserInput()
1836 float scrollAmount = 0.0f;
1838 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
1840 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
1841 mImpl->mEventData->mCheckScrollAmount = false;
1843 return scrollAmount;
1846 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
1848 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
1851 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
1852 layoutHeight = layout.height;
1853 scrollPosition = mImpl->mModel->mScrollPosition.y;
1854 isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
1858 void Controller::SetHiddenInputOption(const Property::Map& options )
1860 if( NULL == mImpl->mHiddenInput )
1862 mImpl->mHiddenInput = new HiddenText( this );
1864 mImpl->mHiddenInput->SetProperties(options);
1867 void Controller::GetHiddenInputOption(Property::Map& options )
1869 if( NULL != mImpl->mHiddenInput )
1871 mImpl->mHiddenInput->GetProperties(options);
1875 void Controller::SetPlaceholderProperty( const Property::Map& map )
1877 PlaceholderHandler::SetPlaceholderProperty(*this, map);
1880 void Controller::GetPlaceholderProperty( Property::Map& map )
1882 PlaceholderHandler::GetPlaceholderProperty(*this, map);
1885 Toolkit::DevelText::TextDirection::Type Controller::GetTextDirection()
1887 // Make sure the model is up-to-date before layouting
1888 ProcessModifyEvents();
1890 if ( mImpl->mUpdateTextDirection )
1892 // Operations that can be done only once until the text changes.
1893 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1899 GET_GLYPH_METRICS );
1901 // Set the update info to relayout the whole text.
1902 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1903 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1905 // Make sure the model is up-to-date before layouting
1906 mImpl->UpdateModel( onlyOnceOperations );
1908 Vector3 naturalSize;
1909 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
1910 static_cast<OperationsMask>( onlyOnceOperations |
1911 LAYOUT | REORDER | UPDATE_DIRECTION ),
1912 naturalSize.GetVectorXY() );
1914 // Do not do again the only once operations.
1915 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1917 // Clear the update info. This info will be set the next time the text is updated.
1918 mImpl->mTextUpdateInfo.Clear();
1920 // FullRelayoutNeeded should be true because DoRelayout is MAX_FLOAT, MAX_FLOAT.
1921 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
1923 mImpl->mUpdateTextDirection = false;
1926 return mImpl->mIsTextDirectionRTL ? Toolkit::DevelText::TextDirection::RIGHT_TO_LEFT : Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT;
1929 Toolkit::DevelText::VerticalLineAlignment::Type Controller::GetVerticalLineAlignment() const
1931 return mImpl->mModel->GetVerticalLineAlignment();
1934 void Controller::SetVerticalLineAlignment( Toolkit::DevelText::VerticalLineAlignment::Type alignment )
1936 mImpl->mModel->mVerticalLineAlignment = alignment;
1939 // public : Relayout.
1941 Controller::UpdateTextType Controller::Relayout( const Size& size, Dali::LayoutDirection::Type layoutDirection )
1943 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
1945 UpdateTextType updateTextType = NONE_UPDATED;
1947 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
1949 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
1951 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
1952 updateTextType = MODEL_UPDATED;
1955 // Clear the update info. This info will be set the next time the text is updated.
1956 mImpl->mTextUpdateInfo.Clear();
1958 // Not worth to relayout if width or height is equal to zero.
1959 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
1961 return updateTextType;
1964 // Whether a new size has been set.
1965 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
1969 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
1971 if( ( 0 == mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd ) &&
1972 ( 0 == mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) &&
1973 ( ( mImpl->mModel->mVisualModel->mControlSize.width < Math::MACHINE_EPSILON_1000 ) || ( mImpl->mModel->mVisualModel->mControlSize.height < Math::MACHINE_EPSILON_1000 ) ) )
1975 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
1978 // Layout operations that need to be done if the size changes.
1979 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1982 UPDATE_LAYOUT_SIZE |
1984 // Set the update info to relayout the whole text.
1985 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
1986 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
1988 // Store the size used to layout the text.
1989 mImpl->mModel->mVisualModel->mControlSize = size;
1992 // Whether there are modify events.
1993 if( 0u != mImpl->mModifyEvents.Count() )
1995 // Style operations that need to be done if the text is modified.
1996 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2000 // Set the update info to elide the text.
2001 if( mImpl->mModel->mElideEnabled ||
2002 ( ( NULL != mImpl->mEventData ) && mImpl->mEventData->mIsPlaceholderElideEnabled ) )
2004 // Update Text layout for applying elided
2005 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2008 UPDATE_LAYOUT_SIZE |
2010 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2011 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2014 if( mImpl->mModel->mMatchSystemLanguageDirection && mImpl->mLayoutDirection != layoutDirection )
2016 // Clear the update info. This info will be set the next time the text is updated.
2017 mImpl->mTextUpdateInfo.mClearAll = true;
2018 // Apply modifications to the model
2019 // Shape the text again is needed because characters like '()[]{}' have to be mirrored and the glyphs generated again.
2020 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2027 mImpl->mLayoutDirection = layoutDirection;
2030 // Make sure the model is up-to-date before layouting.
2031 ProcessModifyEvents();
2032 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
2036 updated = DoRelayout( size,
2037 mImpl->mOperationsPending,
2038 layoutSize ) || updated;
2043 updateTextType = MODEL_UPDATED;
2046 // Do not re-do any operation until something changes.
2047 mImpl->mOperationsPending = NO_OPERATION;
2048 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
2050 // Whether the text control is editable
2051 const bool isEditable = NULL != mImpl->mEventData;
2053 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
2055 if( newSize && isEditable )
2057 offset = mImpl->mModel->mScrollPosition;
2060 if( !isEditable || !IsMultiLineEnabled() )
2062 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
2063 CalculateVerticalOffset( size );
2070 // If there is a new size, the scroll position needs to be clamped.
2071 mImpl->ClampHorizontalScroll( layoutSize );
2073 // Update the decorator's positions is needed if there is a new size.
2074 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
2077 // Move the cursor, grab handle etc.
2078 if( mImpl->ProcessInputEvents() )
2080 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
2084 // Clear the update info. This info will be set the next time the text is updated.
2085 mImpl->mTextUpdateInfo.Clear();
2086 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
2088 return updateTextType;
2091 void Controller::RequestRelayout()
2093 mImpl->RequestRelayout();
2096 // public : Input style change signals.
2098 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
2100 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
2103 void Controller::ProcessInputStyleChangedSignals()
2105 if( NULL == mImpl->mEventData )
2111 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
2112 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
2116 const InputStyle::Mask mask = *it;
2118 if( NULL != mImpl->mEditableControlInterface )
2120 // Emit the input style changed signal.
2121 mImpl->mEditableControlInterface->InputStyleChanged( mask );
2125 mImpl->mEventData->mInputStyleChangedQueue.Clear();
2128 // public : Text-input Event Queuing.
2130 void Controller::KeyboardFocusGainEvent()
2132 EventHandler::KeyboardFocusGainEvent(*this);
2135 void Controller::KeyboardFocusLostEvent()
2137 EventHandler::KeyboardFocusLostEvent(*this);
2140 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
2142 return EventHandler::KeyEvent(*this, keyEvent);
2145 void Controller::TapEvent( unsigned int tapCount, float x, float y )
2147 EventHandler::TapEvent(*this, tapCount, x, y);
2150 void Controller::PanEvent( GestureState state, const Vector2& displacement )
2152 EventHandler::PanEvent(*this, state, displacement);
2155 void Controller::LongPressEvent( GestureState state, float x, float y )
2157 EventHandler::LongPressEvent(*this, state, x, y);
2160 void Controller::SelectEvent( float x, float y, SelectionType selectType )
2162 EventHandler::SelectEvent(*this, x, y, selectType);
2165 void Controller::SetTextSelectionRange(const uint32_t *start, const uint32_t *end)
2167 if( mImpl->mEventData )
2169 mImpl->mEventData->mCheckScrollAmount = true;
2170 mImpl->mEventData->mIsLeftHandleSelected = true;
2171 mImpl->mEventData->mIsRightHandleSelected = true;
2172 mImpl->SetTextSelectionRange(start, end);
2173 mImpl->RequestRelayout();
2174 KeyboardFocusGainEvent();
2178 Uint32Pair Controller::GetTextSelectionRange() const
2180 return mImpl->GetTextSelectionRange();
2183 void Controller::SelectWholeText()
2185 SelectEvent( 0.f, 0.f, SelectionType::ALL );
2188 void Controller::SelectNone()
2190 SelectEvent( 0.f, 0.f, SelectionType::NONE );
2193 string Controller::GetSelectedText() const
2196 if( EventData::SELECTING == mImpl->mEventData->mState )
2198 mImpl->RetrieveSelection( text, false );
2203 InputMethodContext::CallbackData Controller::OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
2205 return EventHandler::OnInputMethodContextEvent(*this, inputMethodContext, inputMethodContextEvent);
2208 void Controller::PasteClipboardItemEvent()
2210 EventHandler::PasteClipboardItemEvent(*this);
2213 // protected : Inherit from Text::Decorator::ControllerInterface.
2215 void Controller::GetTargetSize( Vector2& targetSize )
2217 targetSize = mImpl->mModel->mVisualModel->mControlSize;
2220 void Controller::AddDecoration( Actor& actor, bool needsClipping )
2222 if( NULL != mImpl->mEditableControlInterface )
2224 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
2228 bool Controller::IsEditable() const
2230 return mImpl->IsEditable();
2233 void Controller::SetEditable( bool editable )
2235 mImpl->SetEditable( editable );
2236 if(mImpl->mEventData && mImpl->mEventData->mDecorator)
2238 mImpl->mEventData->mDecorator->SetEditable( editable );
2242 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
2244 EventHandler::DecorationEvent(*this, handleType, state, x, y);
2247 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
2249 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
2251 EventHandler::TextPopupButtonTouched(*this, button);
2254 void Controller::DisplayTimeExpired()
2256 mImpl->mEventData->mUpdateCursorPosition = true;
2257 // Apply modifications to the model
2258 mImpl->mOperationsPending = ALL_OPERATIONS;
2260 mImpl->RequestRelayout();
2263 // private : Update.
2265 void Controller::InsertText( const std::string& text, Controller::InsertType type )
2267 bool removedPrevious = false;
2268 bool removedSelected = false;
2269 bool maxLengthReached = false;
2271 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
2273 if( NULL == mImpl->mEventData )
2278 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
2279 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
2280 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
2282 // TODO: At the moment the underline runs are only for pre-edit.
2283 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
2285 // Remove the previous InputMethodContext pre-edit.
2286 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
2288 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
2289 mImpl->mEventData->mPreEditLength,
2290 DONT_UPDATE_INPUT_STYLE );
2292 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
2293 mImpl->mEventData->mPreEditLength = 0u;
2297 // Remove the previous Selection.
2298 removedSelected = RemoveSelectedText();
2302 Vector<Character> utf32Characters;
2303 Length characterCount = 0u;
2307 // Convert text into UTF-32
2308 utf32Characters.Resize( text.size() );
2310 // This is a bit horrible but std::string returns a (signed) char*
2311 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
2313 // Transform a text array encoded in utf8 into an array encoded in utf32.
2314 // It returns the actual number of characters.
2315 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
2316 utf32Characters.Resize( characterCount );
2318 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
2319 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
2322 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
2324 // The placeholder text is no longer needed
2325 if( mImpl->IsShowingPlaceholderText() )
2330 mImpl->ChangeState( EventData::EDITING );
2332 // Handle the InputMethodContext (predicitive text) state changes
2333 if( COMMIT == type )
2335 // InputMethodContext is no longer handling key-events
2336 mImpl->ClearPreEditFlag();
2340 if( !mImpl->mEventData->mPreEditFlag )
2342 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
2344 // Record the start of the pre-edit text
2345 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
2348 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
2349 mImpl->mEventData->mPreEditFlag = true;
2351 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
2354 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
2356 // Restrict new text to fit within Maximum characters setting.
2357 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
2358 maxLengthReached = ( characterCount > maxSizeOfNewText );
2360 // The cursor position.
2361 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
2363 // Update the text's style.
2365 // Updates the text style runs by adding characters.
2366 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
2368 // Get the character index from the cursor index.
2369 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
2371 // Retrieve the text's style for the given index.
2373 mImpl->RetrieveDefaultInputStyle( style );
2374 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
2376 // Whether to add a new text color run.
2377 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor ) && !mImpl->mEventData->mInputStyle.isDefaultColor;
2379 // Whether to add a new font run.
2380 const bool addFontNameRun = ( style.familyName != mImpl->mEventData->mInputStyle.familyName ) && mImpl->mEventData->mInputStyle.isFamilyDefined;
2381 const bool addFontWeightRun = ( style.weight != mImpl->mEventData->mInputStyle.weight ) && mImpl->mEventData->mInputStyle.isWeightDefined;
2382 const bool addFontWidthRun = ( style.width != mImpl->mEventData->mInputStyle.width ) && mImpl->mEventData->mInputStyle.isWidthDefined;
2383 const bool addFontSlantRun = ( style.slant != mImpl->mEventData->mInputStyle.slant ) && mImpl->mEventData->mInputStyle.isSlantDefined;
2384 const bool addFontSizeRun = ( style.size != mImpl->mEventData->mInputStyle.size ) && mImpl->mEventData->mInputStyle.isSizeDefined ;
2389 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
2390 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
2392 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
2393 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
2394 colorRun.characterRun.characterIndex = cursorIndex;
2395 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
2398 if( addFontNameRun ||
2404 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
2405 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
2407 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
2409 if( addFontNameRun )
2411 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
2412 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
2413 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
2414 fontDescriptionRun.familyDefined = true;
2416 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
2419 if( addFontWeightRun )
2421 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
2422 fontDescriptionRun.weightDefined = true;
2425 if( addFontWidthRun )
2427 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
2428 fontDescriptionRun.widthDefined = true;
2431 if( addFontSlantRun )
2433 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
2434 fontDescriptionRun.slantDefined = true;
2437 if( addFontSizeRun )
2439 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
2440 fontDescriptionRun.sizeDefined = true;
2443 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
2444 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
2447 // Insert at current cursor position.
2448 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
2450 if( cursorIndex < numberOfCharactersInModel )
2452 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
2456 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
2459 // Mark the first paragraph to be updated.
2460 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
2462 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
2463 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2464 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
2465 mImpl->mTextUpdateInfo.mClearAll = true;
2469 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
2470 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
2473 // Update the cursor index.
2474 cursorIndex += maxSizeOfNewText;
2476 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 );
2479 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
2480 mImpl->IsPlaceholderAvailable() )
2482 // Show place-holder if empty after removing the pre-edit text
2483 ShowPlaceholderText();
2484 mImpl->mEventData->mUpdateCursorPosition = true;
2485 mImpl->ClearPreEditFlag();
2487 else if( removedPrevious ||
2489 ( 0 != utf32Characters.Count() ) )
2491 // Queue an inserted event
2492 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
2494 mImpl->mEventData->mUpdateCursorPosition = true;
2495 if( removedSelected )
2497 mImpl->mEventData->mScrollAfterDelete = true;
2501 mImpl->mEventData->mScrollAfterUpdatePosition = true;
2505 if( maxLengthReached )
2507 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
2509 mImpl->ResetInputMethodContext();
2511 if( NULL != mImpl->mEditableControlInterface )
2513 // Do this last since it provides callbacks into application code
2514 mImpl->mEditableControlInterface->MaxLengthReached();
2519 void Controller::PasteText( const std::string& stringToPaste )
2521 InsertText( stringToPaste, Text::Controller::COMMIT );
2522 mImpl->ChangeState( EventData::EDITING );
2523 mImpl->RequestRelayout();
2525 if( NULL != mImpl->mEditableControlInterface )
2527 // Do this last since it provides callbacks into application code
2528 mImpl->mEditableControlInterface->TextChanged();
2532 bool Controller::RemoveText( int cursorOffset,
2533 int numberOfCharacters,
2534 UpdateInputStyleType type )
2536 bool removed = false;
2538 if( NULL == mImpl->mEventData )
2543 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
2544 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
2546 if( !mImpl->IsShowingPlaceholderText() )
2548 // Delete at current cursor position
2549 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
2550 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
2552 CharacterIndex cursorIndex = 0;
2554 // Validate the cursor position & number of characters
2555 if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
2557 cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
2560 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
2562 numberOfCharacters = currentText.Count() - cursorIndex;
2565 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.
2566 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
2568 // Mark the paragraphs to be updated.
2569 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
2571 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
2572 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2573 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
2574 mImpl->mTextUpdateInfo.mClearAll = true;
2578 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
2579 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
2582 // Update the input style and remove the text's style before removing the text.
2584 if( UPDATE_INPUT_STYLE == type )
2586 // Keep a copy of the current input style.
2587 InputStyle currentInputStyle;
2588 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
2590 // Set first the default input style.
2591 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
2593 // Update the input style.
2594 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
2596 // Compare if the input style has changed.
2597 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
2599 if( hasInputStyleChanged )
2601 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
2602 // Queue the input style changed signal.
2603 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
2607 // If the number of current text and the number of characters to be deleted are same,
2608 // it means all texts should be removed and all Preedit variables should be initialized.
2609 if( ( currentText.Count() - numberOfCharacters == 0 ) && ( cursorIndex == 0 ) )
2611 mImpl->ClearPreEditFlag();
2612 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0;
2615 // Updates the text style runs by removing characters. Runs with no characters are removed.
2616 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
2618 // Remove the characters.
2619 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
2620 Vector<Character>::Iterator last = first + numberOfCharacters;
2622 currentText.Erase( first, last );
2624 // Cursor position retreat
2625 oldCursorIndex = cursorIndex;
2627 mImpl->mEventData->mScrollAfterDelete = true;
2629 if( EventData::INACTIVE == mImpl->mEventData->mState )
2631 mImpl->ChangeState( EventData::EDITING );
2634 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
2642 bool Controller::RemoveSelectedText()
2644 bool textRemoved( false );
2646 if( EventData::SELECTING == mImpl->mEventData->mState )
2648 std::string removedString;
2649 mImpl->RetrieveSelection( removedString, true );
2651 if( !removedString.empty() )
2654 mImpl->ChangeState( EventData::EDITING );
2661 // private : Relayout.
2663 bool Controller::DoRelayout( const Size& size,
2664 OperationsMask operationsRequired,
2667 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
2668 bool viewUpdated( false );
2670 // Calculate the operations to be done.
2671 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
2673 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
2674 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
2676 // Get the current layout size.
2677 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
2679 if( NO_OPERATION != ( LAYOUT & operations ) )
2681 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
2683 // Some vectors with data needed to layout and reorder may be void
2684 // after the first time the text has been laid out.
2685 // Fill the vectors again.
2687 // Calculate the number of glyphs to layout.
2688 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
2689 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
2690 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
2691 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
2693 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
2694 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
2696 // Make sure the index is not out of bound
2697 if ( charactersToGlyph.Count() != glyphsPerCharacter.Count() ||
2698 requestedNumberOfCharacters > charactersToGlyph.Count() ||
2699 ( lastIndex > charactersToGlyph.Count() && charactersToGlyph.Count() > 0u ) )
2701 std::string currentText;
2702 GetText( currentText );
2704 DALI_LOG_ERROR( "Controller::DoRelayout: Attempting to access invalid buffer\n" );
2705 DALI_LOG_ERROR( "Current text is: %s\n", currentText.c_str() );
2706 DALI_LOG_ERROR( "startIndex: %u, lastIndex: %u, requestedNumberOfCharacters: %u, charactersToGlyph.Count = %lu, glyphsPerCharacter.Count = %lu\n", startIndex, lastIndex, requestedNumberOfCharacters, charactersToGlyph.Count(), glyphsPerCharacter.Count());
2711 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
2712 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
2714 if( 0u == totalNumberOfGlyphs )
2716 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
2718 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
2721 // Nothing else to do if there is no glyphs.
2722 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
2726 // Set the layout parameters.
2727 Layout::Parameters layoutParameters( size,
2730 // Resize the vector of positions to have the same size than the vector of glyphs.
2731 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
2732 glyphPositions.Resize( totalNumberOfGlyphs );
2734 // Whether the last character is a new paragraph character.
2735 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
2736 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
2737 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
2739 // The initial glyph and the number of glyphs to layout.
2740 layoutParameters.startGlyphIndex = startGlyphIndex;
2741 layoutParameters.numberOfGlyphs = numberOfGlyphs;
2742 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
2743 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
2745 // Update the ellipsis
2746 bool elideTextEnabled = mImpl->mModel->mElideEnabled;
2748 if( NULL != mImpl->mEventData )
2750 if( mImpl->mEventData->mPlaceholderEllipsisFlag && mImpl->IsShowingPlaceholderText() )
2752 elideTextEnabled = mImpl->mEventData->mIsPlaceholderElideEnabled;
2754 else if( EventData::INACTIVE != mImpl->mEventData->mState )
2756 // Disable ellipsis when editing
2757 elideTextEnabled = false;
2760 // Reset the scroll position in inactive state
2761 if( elideTextEnabled && ( mImpl->mEventData->mState == EventData::INACTIVE ) )
2763 ResetScrollPosition();
2767 // Update the visual model.
2768 bool isAutoScrollEnabled = mImpl->mIsAutoScrollEnabled;
2770 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
2773 isAutoScrollEnabled );
2774 mImpl->mIsAutoScrollEnabled = isAutoScrollEnabled;
2776 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
2780 layoutSize = newLayoutSize;
2782 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
2784 mImpl->mIsTextDirectionRTL = false;
2787 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && !mImpl->mModel->mVisualModel->mLines.Empty() )
2789 mImpl->mIsTextDirectionRTL = mImpl->mModel->mVisualModel->mLines[0u].direction;
2792 // Sets the layout size.
2793 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
2795 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
2800 if( NO_OPERATION != ( ALIGN & operations ) )
2802 // The laid-out lines.
2803 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
2805 CharacterIndex alignStartIndex = startIndex;
2806 Length alignRequestedNumberOfCharacters = requestedNumberOfCharacters;
2808 // the whole text needs to be full aligned.
2809 // If you do not do a full aligned, only the last line of the multiline input is aligned.
2810 if( mImpl->mEventData && mImpl->mEventData->mUpdateAlignment )
2812 alignStartIndex = 0u;
2813 alignRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2814 mImpl->mEventData->mUpdateAlignment = false;
2817 // Need to align with the control's size as the text may contain lines
2818 // starting either with left to right text or right to left.
2819 mImpl->mLayoutEngine.Align( size,
2821 alignRequestedNumberOfCharacters,
2822 mImpl->mModel->mHorizontalAlignment,
2824 mImpl->mModel->mAlignmentOffset,
2825 mImpl->mLayoutDirection,
2826 mImpl->mModel->mMatchSystemLanguageDirection );
2830 #if defined(DEBUG_ENABLED)
2831 std::string currentText;
2832 GetText( currentText );
2833 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mIsTextDirectionRTL[%s] [%s]\n", this, (mImpl->mIsTextDirectionRTL)?"true":"false", currentText.c_str() );
2835 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
2839 void Controller::CalculateVerticalOffset( const Size& controlSize )
2841 ModelPtr& model = mImpl->mModel;
2842 VisualModelPtr& visualModel = model->mVisualModel;
2843 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
2844 Size oldLayoutSize = layoutSize;
2845 float offsetY = 0.f;
2846 bool needRecalc = false;
2847 float defaultFontLineHeight = mImpl->GetDefaultFontLineHeight();
2849 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
2851 // Get the line height of the default font.
2852 layoutSize.height = defaultFontLineHeight;
2855 // Whether the text control is editable
2856 const bool isEditable = NULL != mImpl->mEventData;
2857 if ( isEditable && layoutSize.height != defaultFontLineHeight )
2859 // This code prevents the wrong positioning of cursor when the layout size is bigger/smaller than defaultFontLineHeight.
2860 // This situation occurs when the size of placeholder text is different from the default text.
2861 layoutSize.height = defaultFontLineHeight;
2865 switch( mImpl->mModel->mVerticalAlignment )
2867 case VerticalAlignment::TOP:
2869 mImpl->mModel->mScrollPosition.y = 0.f;
2873 case VerticalAlignment::CENTER:
2875 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
2876 if ( needRecalc ) offsetY = floorf( 0.5f * ( layoutSize.height - oldLayoutSize.height ) );
2879 case VerticalAlignment::BOTTOM:
2881 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
2882 if ( needRecalc ) offsetY = layoutSize.height - oldLayoutSize.height;
2889 // Update glyphPositions according to recalculation.
2890 const Length positionCount = visualModel->mGlyphPositions.Count();
2891 Vector<Vector2>& glyphPositions = visualModel->mGlyphPositions;
2892 for( Length index = 0u; index < positionCount; index++ )
2894 glyphPositions[index].y += offsetY;
2899 // private : Events.
2901 void Controller::ProcessModifyEvents()
2903 EventHandler::ProcessModifyEvents(*this);
2906 void Controller::TextReplacedEvent()
2908 EventHandler::TextReplacedEvent(*this);
2911 void Controller::TextInsertedEvent()
2913 EventHandler::TextInsertedEvent(*this);
2916 void Controller::TextDeletedEvent()
2918 EventHandler::TextDeletedEvent(*this);
2921 bool Controller::DeleteEvent( int keyCode )
2923 return EventHandler::DeleteEvent(*this, keyCode);
2926 // private : Helpers.
2928 void Controller::ResetText()
2931 mImpl->mModel->mLogicalModel->mText.Clear();
2933 // Reset the embedded images buffer.
2934 mImpl->mModel->mLogicalModel->ClearEmbeddedImages();
2936 // We have cleared everything including the placeholder-text
2937 mImpl->PlaceholderCleared();
2939 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2940 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2941 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
2943 // Clear any previous text.
2944 mImpl->mTextUpdateInfo.mClearAll = true;
2946 // The natural size needs to be re-calculated.
2947 mImpl->mRecalculateNaturalSize = true;
2949 // The text direction needs to be updated.
2950 mImpl->mUpdateTextDirection = true;
2952 // Apply modifications to the model
2953 mImpl->mOperationsPending = ALL_OPERATIONS;
2956 void Controller::ShowPlaceholderText()
2958 if( mImpl->IsPlaceholderAvailable() )
2960 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
2962 if( NULL == mImpl->mEventData )
2967 mImpl->mEventData->mIsShowingPlaceholderText = true;
2969 // Disable handles when showing place-holder text
2970 mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
2971 mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
2972 mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
2974 const char* text( NULL );
2977 // TODO - Switch Placeholder text when changing state
2978 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
2979 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
2981 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
2982 size = mImpl->mEventData->mPlaceholderTextActive.size();
2986 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
2987 size = mImpl->mEventData->mPlaceholderTextInactive.size();
2990 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2991 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2993 // Reset model for showing placeholder.
2994 mImpl->mModel->mLogicalModel->mText.Clear();
2995 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
2997 // Convert text into UTF-32
2998 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
2999 utf32Characters.Resize( size );
3001 // This is a bit horrible but std::string returns a (signed) char*
3002 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
3004 // Transform a text array encoded in utf8 into an array encoded in utf32.
3005 // It returns the actual number of characters.
3006 const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
3007 utf32Characters.Resize( characterCount );
3009 // The characters to be added.
3010 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
3012 // Reset the cursor position
3013 mImpl->mEventData->mPrimaryCursorPosition = 0;
3015 // The natural size needs to be re-calculated.
3016 mImpl->mRecalculateNaturalSize = true;
3018 // The text direction needs to be updated.
3019 mImpl->mUpdateTextDirection = true;
3021 // Apply modifications to the model
3022 mImpl->mOperationsPending = ALL_OPERATIONS;
3024 // Update the rest of the model during size negotiation
3025 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
3029 void Controller::ClearFontData()
3031 if( mImpl->mFontDefaults )
3033 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
3036 // Set flags to update the model.
3037 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3038 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3039 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
3041 mImpl->mTextUpdateInfo.mClearAll = true;
3042 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
3043 mImpl->mRecalculateNaturalSize = true;
3045 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
3051 UPDATE_LAYOUT_SIZE |
3056 void Controller::ClearStyleData()
3058 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
3059 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
3062 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
3064 // Reset the cursor position
3065 if( NULL != mImpl->mEventData )
3067 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
3069 // Update the cursor if it's in editing mode.
3070 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
3072 mImpl->mEventData->mUpdateCursorPosition = true;
3077 void Controller::ResetScrollPosition()
3079 if( NULL != mImpl->mEventData )
3081 // Reset the scroll position.
3082 mImpl->mModel->mScrollPosition = Vector2::ZERO;
3083 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3087 void Controller::SetControlInterface( ControlInterface* controlInterface )
3089 mImpl->mControlInterface = controlInterface;
3092 bool Controller::ShouldClearFocusOnEscape() const
3094 return mImpl->mShouldClearFocusOnEscape;
3097 Actor Controller::CreateBackgroundActor()
3099 return mImpl->CreateBackgroundActor();
3102 // private : Private contructors & copy operator.
3104 Controller::Controller()
3105 : Controller(nullptr, nullptr, nullptr)
3109 Controller::Controller( ControlInterface* controlInterface )
3110 :Controller( controlInterface, nullptr, nullptr)
3114 Controller::Controller( ControlInterface* controlInterface,
3115 EditableControlInterface* editableControlInterface,
3116 SelectableControlInterface* selectableControlInterface )
3117 : mImpl(new Controller::Impl(controlInterface, editableControlInterface, selectableControlInterface))
3121 // The copy constructor and operator are left unimplemented.
3123 // protected : Destructor.
3125 Controller::~Controller()
3132 } // namespace Toolkit