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 void Controller::RetrieveSelection( std::string& selectedText ) const
738 mImpl->RetrieveSelection( selectedText, false );
741 void Controller::SetSelection( int start, int end )
743 mImpl->SetSelection( start, end );
746 std::pair< int, int > Controller::GetSelectionIndexes() const
748 return mImpl->GetSelectionIndexes();
751 void Controller::CopyStringToClipboard( const std::string& source )
753 mImpl->CopyStringToClipboard( source );
756 void Controller::SendSelectionToClipboard( bool deleteAfterSending )
758 mImpl->SendSelectionToClipboard( deleteAfterSending );
761 // public : Default style & Input style
763 void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
765 if( NULL == mImpl->mFontDefaults )
767 mImpl->mFontDefaults = new FontDefaults();
770 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
771 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
772 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
774 if( mImpl->mEventData )
776 // Update the cursor position if it's in editing mode
777 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
779 mImpl->mEventData->mDecoratorUpdated = true;
780 mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font family is updated.
784 // Clear the font-specific data
787 mImpl->RequestRelayout();
790 const std::string& Controller::GetDefaultFontFamily() const
792 if( NULL != mImpl->mFontDefaults )
794 return mImpl->mFontDefaults->mFontDescription.family;
800 void Controller::SetPlaceholderFontFamily( const std::string& placeholderTextFontFamily )
802 PlaceholderHandler::SetPlaceholderFontFamily(*this, placeholderTextFontFamily);
805 const std::string& Controller::GetPlaceholderFontFamily() const
807 return PlaceholderHandler::GetPlaceholderFontFamily(*this);
810 void Controller::SetDefaultFontWeight( FontWeight weight )
812 if( NULL == mImpl->mFontDefaults )
814 mImpl->mFontDefaults = new FontDefaults();
817 mImpl->mFontDefaults->mFontDescription.weight = weight;
818 mImpl->mFontDefaults->weightDefined = true;
820 if( mImpl->mEventData )
822 // Update the cursor position if it's in editing mode
823 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
825 mImpl->mEventData->mDecoratorUpdated = true;
826 mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font weight is updated.
830 // Clear the font-specific data
833 mImpl->RequestRelayout();
836 bool Controller::IsDefaultFontWeightDefined() const
838 if( NULL != mImpl->mFontDefaults )
840 return mImpl->mFontDefaults->weightDefined;
846 FontWeight Controller::GetDefaultFontWeight() const
848 if( NULL != mImpl->mFontDefaults )
850 return mImpl->mFontDefaults->mFontDescription.weight;
853 return TextAbstraction::FontWeight::NORMAL;
856 void Controller::SetPlaceholderTextFontWeight( FontWeight weight )
858 PlaceholderHandler::SetPlaceholderTextFontWeight(*this, weight);
861 bool Controller::IsPlaceholderTextFontWeightDefined() const
863 return PlaceholderHandler::IsPlaceholderTextFontWeightDefined(*this);;
866 FontWeight Controller::GetPlaceholderTextFontWeight() const
868 return PlaceholderHandler::GetPlaceholderTextFontWeight(*this);
871 void Controller::SetDefaultFontWidth( FontWidth width )
873 if( NULL == mImpl->mFontDefaults )
875 mImpl->mFontDefaults = new FontDefaults();
878 mImpl->mFontDefaults->mFontDescription.width = width;
879 mImpl->mFontDefaults->widthDefined = true;
881 if( mImpl->mEventData )
883 // Update the cursor position if it's in editing mode
884 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
886 mImpl->mEventData->mDecoratorUpdated = true;
887 mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font width is updated.
891 // Clear the font-specific data
894 mImpl->RequestRelayout();
897 bool Controller::IsDefaultFontWidthDefined() const
899 if( NULL != mImpl->mFontDefaults )
901 return mImpl->mFontDefaults->widthDefined;
907 FontWidth Controller::GetDefaultFontWidth() const
909 if( NULL != mImpl->mFontDefaults )
911 return mImpl->mFontDefaults->mFontDescription.width;
914 return TextAbstraction::FontWidth::NORMAL;
917 void Controller::SetPlaceholderTextFontWidth( FontWidth width )
919 PlaceholderHandler::SetPlaceholderTextFontWidth(*this, width);
922 bool Controller::IsPlaceholderTextFontWidthDefined() const
924 return PlaceholderHandler::IsPlaceholderTextFontWidthDefined(*this);
927 FontWidth Controller::GetPlaceholderTextFontWidth() const
929 return PlaceholderHandler::GetPlaceholderTextFontWidth(*this);
932 void Controller::SetDefaultFontSlant( FontSlant slant )
934 if( NULL == mImpl->mFontDefaults )
936 mImpl->mFontDefaults = new FontDefaults();
939 mImpl->mFontDefaults->mFontDescription.slant = slant;
940 mImpl->mFontDefaults->slantDefined = true;
942 if( mImpl->mEventData )
944 // Update the cursor position if it's in editing mode
945 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
947 mImpl->mEventData->mDecoratorUpdated = true;
948 mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font slant is updated.
952 // Clear the font-specific data
955 mImpl->RequestRelayout();
958 bool Controller::IsDefaultFontSlantDefined() const
960 if( NULL != mImpl->mFontDefaults )
962 return mImpl->mFontDefaults->slantDefined;
967 FontSlant Controller::GetDefaultFontSlant() const
969 if( NULL != mImpl->mFontDefaults )
971 return mImpl->mFontDefaults->mFontDescription.slant;
974 return TextAbstraction::FontSlant::NORMAL;
977 void Controller::SetPlaceholderTextFontSlant( FontSlant slant )
979 PlaceholderHandler::SetPlaceholderTextFontSlant(*this, slant);
982 bool Controller::IsPlaceholderTextFontSlantDefined() const
984 return PlaceholderHandler::IsPlaceholderTextFontSlantDefined(*this);
987 FontSlant Controller::GetPlaceholderTextFontSlant() const
989 return PlaceholderHandler::GetPlaceholderTextFontSlant(*this);
992 void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
994 if( NULL == mImpl->mFontDefaults )
996 mImpl->mFontDefaults = new FontDefaults();
1003 mImpl->mFontDefaults->mDefaultPointSize = fontSize;
1004 mImpl->mFontDefaults->sizeDefined = true;
1009 // Point size = Pixel size * 72.f / DPI
1010 unsigned int horizontalDpi = 0u;
1011 unsigned int verticalDpi = 0u;
1012 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1013 fontClient.GetDpi( horizontalDpi, verticalDpi );
1015 mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
1016 mImpl->mFontDefaults->sizeDefined = true;
1021 if( mImpl->mEventData )
1023 // Update the cursor position if it's in editing mode
1024 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
1026 mImpl->mEventData->mDecoratorUpdated = true;
1027 mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font size is updated.
1031 // Clear the font-specific data
1034 mImpl->RequestRelayout();
1037 float Controller::GetDefaultFontSize( FontSizeType type ) const
1040 if( NULL != mImpl->mFontDefaults )
1046 value = mImpl->mFontDefaults->mDefaultPointSize;
1051 // Pixel size = Point size * DPI / 72.f
1052 unsigned int horizontalDpi = 0u;
1053 unsigned int verticalDpi = 0u;
1054 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1055 fontClient.GetDpi( horizontalDpi, verticalDpi );
1057 value = mImpl->mFontDefaults->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1067 void Controller::SetPlaceholderTextFontSize( float fontSize, FontSizeType type )
1069 PlaceholderHandler::SetPlaceholderTextFontSize(*this, fontSize, type);
1072 float Controller::GetPlaceholderTextFontSize( FontSizeType type ) const
1074 return PlaceholderHandler::GetPlaceholderTextFontSize(*this, type);
1077 void Controller::SetDefaultColor( const Vector4& color )
1079 mImpl->mTextColor = color;
1081 if( !mImpl->IsShowingPlaceholderText() )
1083 mImpl->mModel->mVisualModel->SetTextColor( color );
1085 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
1087 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1089 mImpl->RequestRelayout();
1093 const Vector4& Controller::GetDefaultColor() const
1095 return mImpl->mTextColor;
1098 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
1100 PlaceholderHandler::SetPlaceholderTextColor(*this, textColor);
1103 const Vector4& Controller::GetPlaceholderTextColor() const
1105 return PlaceholderHandler::GetPlaceholderTextColor(*this);
1108 void Controller::SetShadowOffset( const Vector2& shadowOffset )
1110 mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
1112 mImpl->RequestRelayout();
1115 const Vector2& Controller::GetShadowOffset() const
1117 return mImpl->mModel->mVisualModel->GetShadowOffset();
1120 void Controller::SetShadowColor( const Vector4& shadowColor )
1122 mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
1124 mImpl->RequestRelayout();
1127 const Vector4& Controller::GetShadowColor() const
1129 return mImpl->mModel->mVisualModel->GetShadowColor();
1132 void Controller::SetShadowBlurRadius( const float& shadowBlurRadius )
1134 if ( fabsf( GetShadowBlurRadius() - shadowBlurRadius ) > Math::MACHINE_EPSILON_1 )
1136 mImpl->mModel->mVisualModel->SetShadowBlurRadius( shadowBlurRadius );
1138 mImpl->RequestRelayout();
1142 const float& Controller::GetShadowBlurRadius() const
1144 return mImpl->mModel->mVisualModel->GetShadowBlurRadius();
1147 void Controller::SetUnderlineColor( const Vector4& color )
1149 mImpl->mModel->mVisualModel->SetUnderlineColor( color );
1151 mImpl->RequestRelayout();
1154 const Vector4& Controller::GetUnderlineColor() const
1156 return mImpl->mModel->mVisualModel->GetUnderlineColor();
1159 void Controller::SetUnderlineEnabled( bool enabled )
1161 mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
1163 mImpl->RequestRelayout();
1166 bool Controller::IsUnderlineEnabled() const
1168 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
1171 void Controller::SetUnderlineHeight( float height )
1173 mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
1175 mImpl->RequestRelayout();
1178 float Controller::GetUnderlineHeight() const
1180 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
1183 void Controller::SetOutlineColor( const Vector4& color )
1185 mImpl->mModel->mVisualModel->SetOutlineColor( color );
1187 mImpl->RequestRelayout();
1190 const Vector4& Controller::GetOutlineColor() const
1192 return mImpl->mModel->mVisualModel->GetOutlineColor();
1195 void Controller::SetOutlineWidth( uint16_t width )
1197 mImpl->mModel->mVisualModel->SetOutlineWidth( width );
1199 mImpl->RequestRelayout();
1202 uint16_t Controller::GetOutlineWidth() const
1204 return mImpl->mModel->mVisualModel->GetOutlineWidth();
1207 void Controller::SetBackgroundColor( const Vector4& color )
1209 mImpl->mModel->mVisualModel->SetBackgroundColor( color );
1211 mImpl->RequestRelayout();
1214 const Vector4& Controller::GetBackgroundColor() const
1216 return mImpl->mModel->mVisualModel->GetBackgroundColor();
1219 void Controller::SetBackgroundEnabled( bool enabled )
1221 mImpl->mModel->mVisualModel->SetBackgroundEnabled( enabled );
1223 mImpl->RequestRelayout();
1226 bool Controller::IsBackgroundEnabled() const
1228 return mImpl->mModel->mVisualModel->IsBackgroundEnabled();
1231 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
1233 if( NULL == mImpl->mEmbossDefaults )
1235 mImpl->mEmbossDefaults = new EmbossDefaults();
1238 mImpl->mEmbossDefaults->properties = embossProperties;
1241 const std::string& Controller::GetDefaultEmbossProperties() const
1243 if( NULL != mImpl->mEmbossDefaults )
1245 return mImpl->mEmbossDefaults->properties;
1248 return EMPTY_STRING;
1251 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
1253 if( NULL == mImpl->mOutlineDefaults )
1255 mImpl->mOutlineDefaults = new OutlineDefaults();
1258 mImpl->mOutlineDefaults->properties = outlineProperties;
1261 const std::string& Controller::GetDefaultOutlineProperties() const
1263 if( NULL != mImpl->mOutlineDefaults )
1265 return mImpl->mOutlineDefaults->properties;
1268 return EMPTY_STRING;
1271 bool Controller::SetDefaultLineSpacing( float lineSpacing )
1273 if( std::fabs( lineSpacing - mImpl->mLayoutEngine.GetDefaultLineSpacing() ) > Math::MACHINE_EPSILON_1000 )
1275 mImpl->mLayoutEngine.SetDefaultLineSpacing(lineSpacing);
1276 mImpl->mRecalculateNaturalSize = true;
1282 float Controller::GetDefaultLineSpacing() const
1284 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
1287 bool Controller::SetDefaultLineSize( float lineSize )
1289 if( std::fabs( lineSize - mImpl->mLayoutEngine.GetDefaultLineSize() ) > Math::MACHINE_EPSILON_1000 )
1291 mImpl->mLayoutEngine.SetDefaultLineSize(lineSize);
1292 mImpl->mRecalculateNaturalSize = true;
1298 float Controller::GetDefaultLineSize() const
1300 return mImpl->mLayoutEngine.GetDefaultLineSize();
1303 void Controller::SetInputColor( const Vector4& color )
1305 if( NULL != mImpl->mEventData )
1307 mImpl->mEventData->mInputStyle.textColor = color;
1308 mImpl->mEventData->mInputStyle.isDefaultColor = false;
1310 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1312 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
1314 // Get start and end position of selection
1315 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
1316 const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
1318 // Add the color run.
1319 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1320 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
1322 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
1323 colorRun.color = color;
1324 colorRun.characterRun.characterIndex = startOfSelectedText;
1325 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1327 // Request to relayout.
1328 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1329 mImpl->RequestRelayout();
1331 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1332 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1333 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1338 const Vector4& Controller::GetInputColor() const
1340 if( NULL != mImpl->mEventData )
1342 return mImpl->mEventData->mInputStyle.textColor;
1345 // Return the default text's color if there is no EventData.
1346 return mImpl->mTextColor;
1350 void Controller::SetInputFontFamily( const std::string& fontFamily )
1352 InputFontHandler::SetInputFontFamily(*this, fontFamily);
1355 const std::string& Controller::GetInputFontFamily() const
1357 return InputFontHandler::GetInputFontFamily(*this);
1360 void Controller::SetInputFontWeight( FontWeight weight )
1362 InputFontHandler::SetInputFontWeight(*this, weight);
1365 bool Controller::IsInputFontWeightDefined() const
1367 return InputFontHandler::IsInputFontWeightDefined(*this);
1370 FontWeight Controller::GetInputFontWeight() const
1372 return InputFontHandler::GetInputFontWeight(*this);
1375 void Controller::SetInputFontWidth( FontWidth width )
1377 InputFontHandler::SetInputFontWidth(*this, width);
1380 bool Controller::IsInputFontWidthDefined() const
1382 return InputFontHandler::IsInputFontWidthDefined(*this);
1385 FontWidth Controller::GetInputFontWidth() const
1387 return InputFontHandler::GetInputFontWidth(*this);
1390 void Controller::SetInputFontSlant( FontSlant slant )
1392 InputFontHandler::SetInputFontSlant(*this, slant);
1395 bool Controller::IsInputFontSlantDefined() const
1397 return InputFontHandler::IsInputFontSlantDefined(*this);
1400 FontSlant Controller::GetInputFontSlant() const
1402 return InputFontHandler::GetInputFontSlant(*this);
1405 void Controller::SetInputFontPointSize( float size )
1407 InputFontHandler::SetInputFontPointSize(*this, size);
1410 float Controller::GetInputFontPointSize() const
1412 return InputFontHandler::GetInputFontPointSize(*this);
1415 void Controller::SetInputLineSpacing( float lineSpacing )
1417 if( NULL != mImpl->mEventData )
1419 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1420 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1424 float Controller::GetInputLineSpacing() const
1426 if( NULL != mImpl->mEventData )
1428 return mImpl->mEventData->mInputStyle.lineSpacing;
1434 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1436 if( NULL != mImpl->mEventData )
1438 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1442 const std::string& Controller::GetInputShadowProperties() const
1444 if( NULL != mImpl->mEventData )
1446 return mImpl->mEventData->mInputStyle.shadowProperties;
1449 return EMPTY_STRING;
1452 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1454 if( NULL != mImpl->mEventData )
1456 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1460 const std::string& Controller::GetInputUnderlineProperties() const
1462 if( NULL != mImpl->mEventData )
1464 return mImpl->mEventData->mInputStyle.underlineProperties;
1467 return EMPTY_STRING;
1470 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
1472 if( NULL != mImpl->mEventData )
1474 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1478 const std::string& Controller::GetInputEmbossProperties() const
1480 if( NULL != mImpl->mEventData )
1482 return mImpl->mEventData->mInputStyle.embossProperties;
1485 return GetDefaultEmbossProperties();
1488 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
1490 if( NULL != mImpl->mEventData )
1492 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1496 const std::string& Controller::GetInputOutlineProperties() const
1498 if( NULL != mImpl->mEventData )
1500 return mImpl->mEventData->mInputStyle.outlineProperties;
1503 return GetDefaultOutlineProperties();
1506 void Controller::SetInputModePassword( bool passwordInput )
1508 if( NULL != mImpl->mEventData )
1510 mImpl->mEventData->mPasswordInput = passwordInput;
1514 bool Controller::IsInputModePassword()
1516 if( NULL != mImpl->mEventData )
1518 return mImpl->mEventData->mPasswordInput;
1523 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
1525 if( NULL != mImpl->mEventData )
1527 mImpl->mEventData->mDoubleTapAction = action;
1531 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1533 NoTextTap::Action action = NoTextTap::NO_ACTION;
1535 if( NULL != mImpl->mEventData )
1537 action = mImpl->mEventData->mDoubleTapAction;
1543 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
1545 if( NULL != mImpl->mEventData )
1547 mImpl->mEventData->mLongPressAction = action;
1551 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1553 NoTextTap::Action action = NoTextTap::NO_ACTION;
1555 if( NULL != mImpl->mEventData )
1557 action = mImpl->mEventData->mLongPressAction;
1563 bool Controller::IsUnderlineSetByString()
1565 return mImpl->mUnderlineSetByString;
1568 void Controller::UnderlineSetByString( bool setByString )
1570 mImpl->mUnderlineSetByString = setByString;
1573 bool Controller::IsShadowSetByString()
1575 return mImpl->mShadowSetByString;
1578 void Controller::ShadowSetByString( bool setByString )
1580 mImpl->mShadowSetByString = setByString;
1583 bool Controller::IsOutlineSetByString()
1585 return mImpl->mOutlineSetByString;
1588 void Controller::OutlineSetByString( bool setByString )
1590 mImpl->mOutlineSetByString = setByString;
1593 bool Controller::IsFontStyleSetByString()
1595 return mImpl->mFontStyleSetByString;
1598 void Controller::FontStyleSetByString( bool setByString )
1600 mImpl->mFontStyleSetByString = setByString;
1603 // public : Queries & retrieves.
1605 Layout::Engine& Controller::GetLayoutEngine()
1607 return mImpl->mLayoutEngine;
1610 View& Controller::GetView()
1612 return mImpl->mView;
1615 Vector3 Controller::GetNaturalSize()
1617 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
1618 Vector3 naturalSize;
1620 // Make sure the model is up-to-date before layouting
1621 ProcessModifyEvents();
1623 if( mImpl->mRecalculateNaturalSize )
1625 // Operations that can be done only once until the text changes.
1626 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1632 GET_GLYPH_METRICS );
1634 // Set the update info to relayout the whole text.
1635 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1636 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1638 // Make sure the model is up-to-date before layouting
1639 mImpl->UpdateModel( onlyOnceOperations );
1641 // Layout the text for the new width.
1642 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT | REORDER );
1644 // Store the actual control's size to restore later.
1645 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
1647 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
1648 static_cast<OperationsMask>( onlyOnceOperations |
1650 naturalSize.GetVectorXY() );
1652 // Do not do again the only once operations.
1653 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1655 // Do the size related operations again.
1656 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1659 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1661 // Stores the natural size to avoid recalculate it again
1662 // unless the text/style changes.
1663 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
1665 mImpl->mRecalculateNaturalSize = false;
1667 // Clear the update info. This info will be set the next time the text is updated.
1668 mImpl->mTextUpdateInfo.Clear();
1669 mImpl->mTextUpdateInfo.mClearAll = true;
1671 // Restore the actual control's size.
1672 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
1674 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1678 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
1680 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1683 naturalSize.x = ConvertToEven( naturalSize.x );
1684 naturalSize.y = ConvertToEven( naturalSize.y );
1689 bool Controller::CheckForTextFit( float pointSize, Size& layoutSize )
1692 mImpl->mFontDefaults->mFitPointSize = pointSize;
1693 mImpl->mFontDefaults->sizeDefined = true;
1696 // Operations that can be done only once until the text changes.
1697 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1703 GET_GLYPH_METRICS );
1705 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1706 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1708 // Make sure the model is up-to-date before layouting
1709 mImpl->UpdateModel( onlyOnceOperations );
1711 DoRelayout( Size( layoutSize.width, MAX_FLOAT ),
1712 static_cast<OperationsMask>( onlyOnceOperations | LAYOUT),
1715 // Clear the update info. This info will be set the next time the text is updated.
1716 mImpl->mTextUpdateInfo.Clear();
1717 mImpl->mTextUpdateInfo.mClearAll = true;
1719 if( textSize.width > layoutSize.width || textSize.height > layoutSize.height )
1726 void Controller::FitPointSizeforLayout( Size layoutSize )
1728 const OperationsMask operations = mImpl->mOperationsPending;
1729 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) || mImpl->mTextFitContentSize != layoutSize )
1731 bool actualellipsis = mImpl->mModel->mElideEnabled;
1732 float minPointSize = mImpl->mTextFitMinSize;
1733 float maxPointSize = mImpl->mTextFitMaxSize;
1734 float pointInterval = mImpl->mTextFitStepSize;
1736 mImpl->mModel->mElideEnabled = false;
1737 Vector<float> pointSizeArray;
1740 if( pointInterval < 1.f )
1742 mImpl->mTextFitStepSize = pointInterval = 1.0f;
1745 pointSizeArray.Reserve( static_cast< unsigned int >( ceil( ( maxPointSize - minPointSize ) / pointInterval ) ) );
1747 for( float i = minPointSize; i < maxPointSize; i += pointInterval )
1749 pointSizeArray.PushBack( i );
1752 pointSizeArray.PushBack( maxPointSize );
1754 int bestSizeIndex = 0;
1755 int min = bestSizeIndex + 1;
1756 int max = pointSizeArray.Size() - 1;
1759 int destI = ( min + max ) / 2;
1761 if( CheckForTextFit( pointSizeArray[destI], layoutSize ) )
1763 bestSizeIndex = min;
1769 bestSizeIndex = max;
1773 mImpl->mModel->mElideEnabled = actualellipsis;
1774 mImpl->mFontDefaults->mFitPointSize = pointSizeArray[bestSizeIndex];
1775 mImpl->mFontDefaults->sizeDefined = true;
1780 float Controller::GetHeightForWidth( float width )
1782 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
1783 // Make sure the model is up-to-date before layouting
1784 ProcessModifyEvents();
1787 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ||
1788 mImpl->mTextUpdateInfo.mFullRelayoutNeeded ||
1789 mImpl->mTextUpdateInfo.mClearAll )
1791 // Operations that can be done only once until the text changes.
1792 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1798 GET_GLYPH_METRICS );
1800 // Set the update info to relayout the whole text.
1801 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1802 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1804 // Make sure the model is up-to-date before layouting
1805 mImpl->UpdateModel( onlyOnceOperations );
1808 // Layout the text for the new width.
1809 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
1811 // Store the actual control's width.
1812 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
1814 DoRelayout( Size( width, MAX_FLOAT ),
1815 static_cast<OperationsMask>( onlyOnceOperations |
1819 // Do not do again the only once operations.
1820 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1822 // Do the size related operations again.
1823 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1827 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1829 // Clear the update info. This info will be set the next time the text is updated.
1830 mImpl->mTextUpdateInfo.Clear();
1831 mImpl->mTextUpdateInfo.mClearAll = true;
1833 // Restore the actual control's width.
1834 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
1836 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
1840 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
1841 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
1844 return layoutSize.height;
1847 int Controller::GetLineCount( float width )
1849 GetHeightForWidth( width );
1850 int numberofLines = mImpl->mModel->GetNumberOfLines();
1851 return numberofLines;
1854 const ModelInterface* const Controller::GetTextModel() const
1856 return mImpl->mModel.Get();
1859 float Controller::GetScrollAmountByUserInput()
1861 float scrollAmount = 0.0f;
1863 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
1865 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
1866 mImpl->mEventData->mCheckScrollAmount = false;
1868 return scrollAmount;
1871 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
1873 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
1876 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
1877 layoutHeight = layout.height;
1878 scrollPosition = mImpl->mModel->mScrollPosition.y;
1879 isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
1883 void Controller::SetHiddenInputOption(const Property::Map& options )
1885 if( NULL == mImpl->mHiddenInput )
1887 mImpl->mHiddenInput = new HiddenText( this );
1889 mImpl->mHiddenInput->SetProperties(options);
1892 void Controller::GetHiddenInputOption(Property::Map& options )
1894 if( NULL != mImpl->mHiddenInput )
1896 mImpl->mHiddenInput->GetProperties(options);
1900 void Controller::SetPlaceholderProperty( const Property::Map& map )
1902 PlaceholderHandler::SetPlaceholderProperty(*this, map);
1905 void Controller::GetPlaceholderProperty( Property::Map& map )
1907 PlaceholderHandler::GetPlaceholderProperty(*this, map);
1910 Toolkit::DevelText::TextDirection::Type Controller::GetTextDirection()
1912 // Make sure the model is up-to-date before layouting
1913 ProcessModifyEvents();
1915 if ( mImpl->mUpdateTextDirection )
1917 // Operations that can be done only once until the text changes.
1918 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1924 GET_GLYPH_METRICS );
1926 // Set the update info to relayout the whole text.
1927 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1928 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1930 // Make sure the model is up-to-date before layouting
1931 mImpl->UpdateModel( onlyOnceOperations );
1933 Vector3 naturalSize;
1934 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
1935 static_cast<OperationsMask>( onlyOnceOperations |
1936 LAYOUT | REORDER | UPDATE_DIRECTION ),
1937 naturalSize.GetVectorXY() );
1939 // Do not do again the only once operations.
1940 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1942 // Clear the update info. This info will be set the next time the text is updated.
1943 mImpl->mTextUpdateInfo.Clear();
1945 // FullRelayoutNeeded should be true because DoRelayout is MAX_FLOAT, MAX_FLOAT.
1946 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
1948 mImpl->mUpdateTextDirection = false;
1951 return mImpl->mIsTextDirectionRTL ? Toolkit::DevelText::TextDirection::RIGHT_TO_LEFT : Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT;
1954 Toolkit::DevelText::VerticalLineAlignment::Type Controller::GetVerticalLineAlignment() const
1956 return mImpl->mModel->GetVerticalLineAlignment();
1959 void Controller::SetVerticalLineAlignment( Toolkit::DevelText::VerticalLineAlignment::Type alignment )
1961 mImpl->mModel->mVerticalLineAlignment = alignment;
1964 // public : Relayout.
1966 Controller::UpdateTextType Controller::Relayout( const Size& size, Dali::LayoutDirection::Type layoutDirection )
1968 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
1970 UpdateTextType updateTextType = NONE_UPDATED;
1972 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
1974 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
1976 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
1977 updateTextType = MODEL_UPDATED;
1980 // Clear the update info. This info will be set the next time the text is updated.
1981 mImpl->mTextUpdateInfo.Clear();
1983 // Not worth to relayout if width or height is equal to zero.
1984 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
1986 return updateTextType;
1989 // Whether a new size has been set.
1990 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
1994 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
1996 if( ( 0 == mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd ) &&
1997 ( 0 == mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) &&
1998 ( ( mImpl->mModel->mVisualModel->mControlSize.width < Math::MACHINE_EPSILON_1000 ) || ( mImpl->mModel->mVisualModel->mControlSize.height < Math::MACHINE_EPSILON_1000 ) ) )
2000 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
2003 // Layout operations that need to be done if the size changes.
2004 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2007 UPDATE_LAYOUT_SIZE |
2009 // Set the update info to relayout the whole text.
2010 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2011 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2013 // Store the size used to layout the text.
2014 mImpl->mModel->mVisualModel->mControlSize = size;
2017 // Whether there are modify events.
2018 if( 0u != mImpl->mModifyEvents.Count() )
2020 // Style operations that need to be done if the text is modified.
2021 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2025 // Set the update info to elide the text.
2026 if( mImpl->mModel->mElideEnabled ||
2027 ( ( NULL != mImpl->mEventData ) && mImpl->mEventData->mIsPlaceholderElideEnabled ) )
2029 // Update Text layout for applying elided
2030 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2033 UPDATE_LAYOUT_SIZE |
2035 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2036 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2039 if( mImpl->mModel->mMatchSystemLanguageDirection && mImpl->mLayoutDirection != layoutDirection )
2041 // Clear the update info. This info will be set the next time the text is updated.
2042 mImpl->mTextUpdateInfo.mClearAll = true;
2043 // Apply modifications to the model
2044 // Shape the text again is needed because characters like '()[]{}' have to be mirrored and the glyphs generated again.
2045 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2052 mImpl->mLayoutDirection = layoutDirection;
2055 // Make sure the model is up-to-date before layouting.
2056 ProcessModifyEvents();
2057 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
2061 updated = DoRelayout( size,
2062 mImpl->mOperationsPending,
2063 layoutSize ) || updated;
2068 updateTextType = MODEL_UPDATED;
2071 // Do not re-do any operation until something changes.
2072 mImpl->mOperationsPending = NO_OPERATION;
2073 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
2075 // Whether the text control is editable
2076 const bool isEditable = NULL != mImpl->mEventData;
2078 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
2080 if( newSize && isEditable )
2082 offset = mImpl->mModel->mScrollPosition;
2085 if( !isEditable || !IsMultiLineEnabled() )
2087 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
2088 CalculateVerticalOffset( size );
2095 // If there is a new size, the scroll position needs to be clamped.
2096 mImpl->ClampHorizontalScroll( layoutSize );
2098 // Update the decorator's positions is needed if there is a new size.
2099 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
2102 // Move the cursor, grab handle etc.
2103 if( mImpl->ProcessInputEvents() )
2105 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
2109 // Clear the update info. This info will be set the next time the text is updated.
2110 mImpl->mTextUpdateInfo.Clear();
2111 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
2113 return updateTextType;
2116 void Controller::RequestRelayout()
2118 mImpl->RequestRelayout();
2121 // public : Input style change signals.
2123 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
2125 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
2128 void Controller::ProcessInputStyleChangedSignals()
2130 if( NULL == mImpl->mEventData )
2136 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
2137 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
2141 const InputStyle::Mask mask = *it;
2143 if( NULL != mImpl->mEditableControlInterface )
2145 // Emit the input style changed signal.
2146 mImpl->mEditableControlInterface->InputStyleChanged( mask );
2150 mImpl->mEventData->mInputStyleChangedQueue.Clear();
2153 // public : Text-input Event Queuing.
2155 void Controller::KeyboardFocusGainEvent()
2157 EventHandler::KeyboardFocusGainEvent(*this);
2160 void Controller::KeyboardFocusLostEvent()
2162 EventHandler::KeyboardFocusLostEvent(*this);
2165 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
2167 return EventHandler::KeyEvent(*this, keyEvent);
2170 void Controller::TapEvent( unsigned int tapCount, float x, float y )
2172 EventHandler::TapEvent(*this, tapCount, x, y);
2175 void Controller::PanEvent( GestureState state, const Vector2& displacement )
2177 EventHandler::PanEvent(*this, state, displacement);
2180 void Controller::LongPressEvent( GestureState state, float x, float y )
2182 EventHandler::LongPressEvent(*this, state, x, y);
2185 void Controller::SelectEvent( float x, float y, SelectionType selectType )
2187 EventHandler::SelectEvent(*this, x, y, selectType);
2190 void Controller::SetTextSelectionRange(const uint32_t *start, const uint32_t *end)
2192 if( mImpl->mEventData )
2194 mImpl->mEventData->mCheckScrollAmount = true;
2195 mImpl->mEventData->mIsLeftHandleSelected = true;
2196 mImpl->mEventData->mIsRightHandleSelected = true;
2197 mImpl->SetTextSelectionRange(start, end);
2198 mImpl->RequestRelayout();
2199 KeyboardFocusGainEvent();
2203 Uint32Pair Controller::GetTextSelectionRange() const
2205 return mImpl->GetTextSelectionRange();
2208 void Controller::SelectWholeText()
2210 SelectEvent( 0.f, 0.f, SelectionType::ALL );
2213 void Controller::SelectNone()
2215 SelectEvent( 0.f, 0.f, SelectionType::NONE );
2218 string Controller::GetSelectedText() const
2221 if( EventData::SELECTING == mImpl->mEventData->mState )
2223 mImpl->RetrieveSelection( text, false );
2228 InputMethodContext::CallbackData Controller::OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
2230 return EventHandler::OnInputMethodContextEvent(*this, inputMethodContext, inputMethodContextEvent);
2233 void Controller::PasteClipboardItemEvent()
2235 EventHandler::PasteClipboardItemEvent(*this);
2238 // protected : Inherit from Text::Decorator::ControllerInterface.
2240 void Controller::GetTargetSize( Vector2& targetSize )
2242 targetSize = mImpl->mModel->mVisualModel->mControlSize;
2245 void Controller::AddDecoration( Actor& actor, bool needsClipping )
2247 if( NULL != mImpl->mEditableControlInterface )
2249 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
2253 bool Controller::IsEditable() const
2255 return mImpl->IsEditable();
2258 void Controller::SetEditable( bool editable )
2260 mImpl->SetEditable( editable );
2261 if(mImpl->mEventData && mImpl->mEventData->mDecorator)
2263 mImpl->mEventData->mDecorator->SetEditable( editable );
2267 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
2269 EventHandler::DecorationEvent(*this, handleType, state, x, y);
2272 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
2274 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
2276 EventHandler::TextPopupButtonTouched(*this, button);
2279 void Controller::DisplayTimeExpired()
2281 mImpl->mEventData->mUpdateCursorPosition = true;
2282 // Apply modifications to the model
2283 mImpl->mOperationsPending = ALL_OPERATIONS;
2285 mImpl->RequestRelayout();
2288 // private : Update.
2290 void Controller::InsertText( const std::string& text, Controller::InsertType type )
2292 bool removedPrevious = false;
2293 bool removedSelected = false;
2294 bool maxLengthReached = false;
2296 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
2298 if( NULL == mImpl->mEventData )
2303 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
2304 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
2305 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
2307 // TODO: At the moment the underline runs are only for pre-edit.
2308 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
2310 // Remove the previous InputMethodContext pre-edit.
2311 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
2313 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
2314 mImpl->mEventData->mPreEditLength,
2315 DONT_UPDATE_INPUT_STYLE );
2317 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
2318 mImpl->mEventData->mPreEditLength = 0u;
2322 // Remove the previous Selection.
2323 removedSelected = RemoveSelectedText();
2327 Vector<Character> utf32Characters;
2328 Length characterCount = 0u;
2332 // Convert text into UTF-32
2333 utf32Characters.Resize( text.size() );
2335 // This is a bit horrible but std::string returns a (signed) char*
2336 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
2338 // Transform a text array encoded in utf8 into an array encoded in utf32.
2339 // It returns the actual number of characters.
2340 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
2341 utf32Characters.Resize( characterCount );
2343 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
2344 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
2347 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
2349 // The placeholder text is no longer needed
2350 if( mImpl->IsShowingPlaceholderText() )
2355 mImpl->ChangeState( EventData::EDITING );
2357 // Handle the InputMethodContext (predicitive text) state changes
2358 if( COMMIT == type )
2360 // InputMethodContext is no longer handling key-events
2361 mImpl->ClearPreEditFlag();
2365 if( !mImpl->mEventData->mPreEditFlag )
2367 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
2369 // Record the start of the pre-edit text
2370 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
2373 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
2374 mImpl->mEventData->mPreEditFlag = true;
2376 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
2379 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
2381 // Restrict new text to fit within Maximum characters setting.
2382 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
2383 maxLengthReached = ( characterCount > maxSizeOfNewText );
2385 // The cursor position.
2386 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
2388 // Update the text's style.
2390 // Updates the text style runs by adding characters.
2391 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
2393 // Get the character index from the cursor index.
2394 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
2396 // Retrieve the text's style for the given index.
2398 mImpl->RetrieveDefaultInputStyle( style );
2399 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
2401 // Whether to add a new text color run.
2402 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor ) && !mImpl->mEventData->mInputStyle.isDefaultColor;
2404 // Whether to add a new font run.
2405 const bool addFontNameRun = ( style.familyName != mImpl->mEventData->mInputStyle.familyName ) && mImpl->mEventData->mInputStyle.isFamilyDefined;
2406 const bool addFontWeightRun = ( style.weight != mImpl->mEventData->mInputStyle.weight ) && mImpl->mEventData->mInputStyle.isWeightDefined;
2407 const bool addFontWidthRun = ( style.width != mImpl->mEventData->mInputStyle.width ) && mImpl->mEventData->mInputStyle.isWidthDefined;
2408 const bool addFontSlantRun = ( style.slant != mImpl->mEventData->mInputStyle.slant ) && mImpl->mEventData->mInputStyle.isSlantDefined;
2409 const bool addFontSizeRun = ( style.size != mImpl->mEventData->mInputStyle.size ) && mImpl->mEventData->mInputStyle.isSizeDefined ;
2414 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
2415 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
2417 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
2418 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
2419 colorRun.characterRun.characterIndex = cursorIndex;
2420 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
2423 if( addFontNameRun ||
2429 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
2430 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
2432 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
2434 if( addFontNameRun )
2436 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
2437 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
2438 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
2439 fontDescriptionRun.familyDefined = true;
2441 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
2444 if( addFontWeightRun )
2446 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
2447 fontDescriptionRun.weightDefined = true;
2450 if( addFontWidthRun )
2452 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
2453 fontDescriptionRun.widthDefined = true;
2456 if( addFontSlantRun )
2458 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
2459 fontDescriptionRun.slantDefined = true;
2462 if( addFontSizeRun )
2464 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
2465 fontDescriptionRun.sizeDefined = true;
2468 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
2469 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
2472 // Insert at current cursor position.
2473 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
2475 auto pos = modifyText.End();
2476 if( cursorIndex < numberOfCharactersInModel )
2478 pos = modifyText.Begin() + cursorIndex;
2480 unsigned int realPos = pos - modifyText.Begin();
2481 modifyText.Insert( pos, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
2483 if( NULL != mImpl->mEditableControlInterface )
2485 mImpl->mEditableControlInterface->TextInserted( realPos, maxSizeOfNewText, text );
2488 // Mark the first paragraph to be updated.
2489 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
2491 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
2492 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2493 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
2494 mImpl->mTextUpdateInfo.mClearAll = true;
2498 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
2499 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
2502 // Update the cursor index.
2503 cursorIndex += maxSizeOfNewText;
2505 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 );
2508 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
2509 mImpl->IsPlaceholderAvailable() )
2511 // Show place-holder if empty after removing the pre-edit text
2512 ShowPlaceholderText();
2513 mImpl->mEventData->mUpdateCursorPosition = true;
2514 mImpl->ClearPreEditFlag();
2516 else if( removedPrevious ||
2518 ( 0 != utf32Characters.Count() ) )
2520 // Queue an inserted event
2521 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
2523 mImpl->mEventData->mUpdateCursorPosition = true;
2524 if( removedSelected )
2526 mImpl->mEventData->mScrollAfterDelete = true;
2530 mImpl->mEventData->mScrollAfterUpdatePosition = true;
2534 if( maxLengthReached )
2536 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
2538 mImpl->ResetInputMethodContext();
2540 if( NULL != mImpl->mEditableControlInterface )
2542 // Do this last since it provides callbacks into application code
2543 mImpl->mEditableControlInterface->MaxLengthReached();
2548 void Controller::PasteText( const std::string& stringToPaste )
2550 InsertText( stringToPaste, Text::Controller::COMMIT );
2551 mImpl->ChangeState( EventData::EDITING );
2552 mImpl->RequestRelayout();
2554 if( NULL != mImpl->mEditableControlInterface )
2556 // Do this last since it provides callbacks into application code
2557 mImpl->mEditableControlInterface->TextChanged();
2561 bool Controller::RemoveText( int cursorOffset,
2562 int numberOfCharacters,
2563 UpdateInputStyleType type )
2565 bool removed = false;
2567 if( NULL == mImpl->mEventData )
2572 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
2573 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
2575 if( !mImpl->IsShowingPlaceholderText() )
2577 // Delete at current cursor position
2578 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
2579 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
2581 CharacterIndex cursorIndex = 0;
2583 // Validate the cursor position & number of characters
2584 if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
2586 cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
2589 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
2591 numberOfCharacters = currentText.Count() - cursorIndex;
2594 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.
2595 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
2597 // Mark the paragraphs to be updated.
2598 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
2600 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
2601 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2602 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
2603 mImpl->mTextUpdateInfo.mClearAll = true;
2607 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
2608 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
2611 // Update the input style and remove the text's style before removing the text.
2613 if( UPDATE_INPUT_STYLE == type )
2615 // Keep a copy of the current input style.
2616 InputStyle currentInputStyle;
2617 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
2619 // Set first the default input style.
2620 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
2622 // Update the input style.
2623 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
2625 // Compare if the input style has changed.
2626 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
2628 if( hasInputStyleChanged )
2630 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
2631 // Queue the input style changed signal.
2632 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
2636 // If the number of current text and the number of characters to be deleted are same,
2637 // it means all texts should be removed and all Preedit variables should be initialized.
2638 if( ( currentText.Count() - numberOfCharacters == 0 ) && ( cursorIndex == 0 ) )
2640 mImpl->ClearPreEditFlag();
2641 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0;
2644 // Updates the text style runs by removing characters. Runs with no characters are removed.
2645 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
2647 // Remove the characters.
2648 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
2649 Vector<Character>::Iterator last = first + numberOfCharacters;
2651 if( NULL != mImpl->mEditableControlInterface )
2654 Utf32ToUtf8( first, numberOfCharacters, utf8 );
2655 mImpl->mEditableControlInterface->TextDeleted( cursorIndex, numberOfCharacters, utf8 );
2658 currentText.Erase( first, last );
2660 // Cursor position retreat
2661 oldCursorIndex = cursorIndex;
2663 mImpl->mEventData->mScrollAfterDelete = true;
2665 if( EventData::INACTIVE == mImpl->mEventData->mState )
2667 mImpl->ChangeState( EventData::EDITING );
2670 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
2678 bool Controller::RemoveSelectedText()
2680 bool textRemoved( false );
2682 if( EventData::SELECTING == mImpl->mEventData->mState )
2684 std::string removedString;
2685 mImpl->RetrieveSelection( removedString, true );
2687 if( !removedString.empty() )
2690 mImpl->ChangeState( EventData::EDITING );
2697 // private : Relayout.
2699 bool Controller::DoRelayout( const Size& size,
2700 OperationsMask operationsRequired,
2703 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
2704 bool viewUpdated( false );
2706 // Calculate the operations to be done.
2707 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
2709 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
2710 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
2712 // Get the current layout size.
2713 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
2715 if( NO_OPERATION != ( LAYOUT & operations ) )
2717 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
2719 // Some vectors with data needed to layout and reorder may be void
2720 // after the first time the text has been laid out.
2721 // Fill the vectors again.
2723 // Calculate the number of glyphs to layout.
2724 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
2725 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
2726 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
2727 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
2729 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
2730 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
2732 // Make sure the index is not out of bound
2733 if ( charactersToGlyph.Count() != glyphsPerCharacter.Count() ||
2734 requestedNumberOfCharacters > charactersToGlyph.Count() ||
2735 ( lastIndex > charactersToGlyph.Count() && charactersToGlyph.Count() > 0u ) )
2737 std::string currentText;
2738 GetText( currentText );
2740 DALI_LOG_ERROR( "Controller::DoRelayout: Attempting to access invalid buffer\n" );
2741 DALI_LOG_ERROR( "Current text is: %s\n", currentText.c_str() );
2742 DALI_LOG_ERROR( "startIndex: %u, lastIndex: %u, requestedNumberOfCharacters: %u, charactersToGlyph.Count = %lu, glyphsPerCharacter.Count = %lu\n", startIndex, lastIndex, requestedNumberOfCharacters, charactersToGlyph.Count(), glyphsPerCharacter.Count());
2747 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
2748 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
2750 if( 0u == totalNumberOfGlyphs )
2752 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
2754 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
2757 // Nothing else to do if there is no glyphs.
2758 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
2762 // Set the layout parameters.
2763 Layout::Parameters layoutParameters( size,
2766 // Resize the vector of positions to have the same size than the vector of glyphs.
2767 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
2768 glyphPositions.Resize( totalNumberOfGlyphs );
2770 // Whether the last character is a new paragraph character.
2771 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
2772 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
2773 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
2775 // The initial glyph and the number of glyphs to layout.
2776 layoutParameters.startGlyphIndex = startGlyphIndex;
2777 layoutParameters.numberOfGlyphs = numberOfGlyphs;
2778 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
2779 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
2781 // Update the ellipsis
2782 bool elideTextEnabled = mImpl->mModel->mElideEnabled;
2784 if( NULL != mImpl->mEventData )
2786 if( mImpl->mEventData->mPlaceholderEllipsisFlag && mImpl->IsShowingPlaceholderText() )
2788 elideTextEnabled = mImpl->mEventData->mIsPlaceholderElideEnabled;
2790 else if( EventData::INACTIVE != mImpl->mEventData->mState )
2792 // Disable ellipsis when editing
2793 elideTextEnabled = false;
2796 // Reset the scroll position in inactive state
2797 if( elideTextEnabled && ( mImpl->mEventData->mState == EventData::INACTIVE ) )
2799 ResetScrollPosition();
2803 // Update the visual model.
2804 bool isAutoScrollEnabled = mImpl->mIsAutoScrollEnabled;
2806 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
2809 isAutoScrollEnabled );
2810 mImpl->mIsAutoScrollEnabled = isAutoScrollEnabled;
2812 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
2816 layoutSize = newLayoutSize;
2818 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
2820 mImpl->mIsTextDirectionRTL = false;
2823 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && !mImpl->mModel->mVisualModel->mLines.Empty() )
2825 mImpl->mIsTextDirectionRTL = mImpl->mModel->mVisualModel->mLines[0u].direction;
2828 // Sets the layout size.
2829 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
2831 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
2836 if( NO_OPERATION != ( ALIGN & operations ) )
2838 // The laid-out lines.
2839 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
2841 CharacterIndex alignStartIndex = startIndex;
2842 Length alignRequestedNumberOfCharacters = requestedNumberOfCharacters;
2844 // the whole text needs to be full aligned.
2845 // If you do not do a full aligned, only the last line of the multiline input is aligned.
2846 if( mImpl->mEventData && mImpl->mEventData->mUpdateAlignment )
2848 alignStartIndex = 0u;
2849 alignRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2850 mImpl->mEventData->mUpdateAlignment = false;
2853 // Need to align with the control's size as the text may contain lines
2854 // starting either with left to right text or right to left.
2855 mImpl->mLayoutEngine.Align( size,
2857 alignRequestedNumberOfCharacters,
2858 mImpl->mModel->mHorizontalAlignment,
2860 mImpl->mModel->mAlignmentOffset,
2861 mImpl->mLayoutDirection,
2862 mImpl->mModel->mMatchSystemLanguageDirection );
2866 #if defined(DEBUG_ENABLED)
2867 std::string currentText;
2868 GetText( currentText );
2869 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mIsTextDirectionRTL[%s] [%s]\n", this, (mImpl->mIsTextDirectionRTL)?"true":"false", currentText.c_str() );
2871 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
2875 void Controller::CalculateVerticalOffset( const Size& controlSize )
2877 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
2879 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
2881 // Get the line height of the default font.
2882 layoutSize.height = mImpl->GetDefaultFontLineHeight();
2885 switch( mImpl->mModel->mVerticalAlignment )
2887 case VerticalAlignment::TOP:
2889 mImpl->mModel->mScrollPosition.y = 0.f;
2892 case VerticalAlignment::CENTER:
2894 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
2897 case VerticalAlignment::BOTTOM:
2899 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
2905 // private : Events.
2907 void Controller::ProcessModifyEvents()
2909 EventHandler::ProcessModifyEvents(*this);
2912 void Controller::TextReplacedEvent()
2914 EventHandler::TextReplacedEvent(*this);
2917 void Controller::TextInsertedEvent()
2919 EventHandler::TextInsertedEvent(*this);
2922 void Controller::TextDeletedEvent()
2924 EventHandler::TextDeletedEvent(*this);
2927 bool Controller::DeleteEvent( int keyCode )
2929 return EventHandler::DeleteEvent(*this, keyCode);
2932 // private : Helpers.
2934 void Controller::ResetText()
2937 mImpl->mModel->mLogicalModel->mText.Clear();
2939 // Reset the embedded images buffer.
2940 mImpl->mModel->mLogicalModel->ClearEmbeddedImages();
2942 // We have cleared everything including the placeholder-text
2943 mImpl->PlaceholderCleared();
2945 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2946 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2947 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
2949 // Clear any previous text.
2950 mImpl->mTextUpdateInfo.mClearAll = true;
2952 // The natural size needs to be re-calculated.
2953 mImpl->mRecalculateNaturalSize = true;
2955 // The text direction needs to be updated.
2956 mImpl->mUpdateTextDirection = true;
2958 // Apply modifications to the model
2959 mImpl->mOperationsPending = ALL_OPERATIONS;
2962 void Controller::ShowPlaceholderText()
2964 if( mImpl->IsPlaceholderAvailable() )
2966 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
2968 if( NULL == mImpl->mEventData )
2973 mImpl->mEventData->mIsShowingPlaceholderText = true;
2975 // Disable handles when showing place-holder text
2976 mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
2977 mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
2978 mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
2980 const char* text( NULL );
2983 // TODO - Switch Placeholder text when changing state
2984 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
2985 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
2987 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
2988 size = mImpl->mEventData->mPlaceholderTextActive.size();
2992 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
2993 size = mImpl->mEventData->mPlaceholderTextInactive.size();
2996 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2997 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2999 // Reset model for showing placeholder.
3000 mImpl->mModel->mLogicalModel->mText.Clear();
3001 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
3003 // Convert text into UTF-32
3004 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
3005 utf32Characters.Resize( size );
3007 // This is a bit horrible but std::string returns a (signed) char*
3008 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
3010 // Transform a text array encoded in utf8 into an array encoded in utf32.
3011 // It returns the actual number of characters.
3012 const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
3013 utf32Characters.Resize( characterCount );
3015 // The characters to be added.
3016 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
3018 // Reset the cursor position
3019 mImpl->mEventData->mPrimaryCursorPosition = 0;
3021 // The natural size needs to be re-calculated.
3022 mImpl->mRecalculateNaturalSize = true;
3024 // The text direction needs to be updated.
3025 mImpl->mUpdateTextDirection = true;
3027 // Apply modifications to the model
3028 mImpl->mOperationsPending = ALL_OPERATIONS;
3030 // Update the rest of the model during size negotiation
3031 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
3035 void Controller::ClearFontData()
3037 if( mImpl->mFontDefaults )
3039 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
3042 // Set flags to update the model.
3043 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3044 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3045 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
3047 mImpl->mTextUpdateInfo.mClearAll = true;
3048 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
3049 mImpl->mRecalculateNaturalSize = true;
3051 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
3057 UPDATE_LAYOUT_SIZE |
3062 void Controller::ClearStyleData()
3064 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
3065 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
3068 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
3070 // Reset the cursor position
3071 if( NULL != mImpl->mEventData )
3073 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
3075 // Update the cursor if it's in editing mode.
3076 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
3078 mImpl->mEventData->mUpdateCursorPosition = true;
3083 CharacterIndex Controller::GetCursorPosition()
3085 if( !mImpl->mEventData )
3088 return mImpl->mEventData->mPrimaryCursorPosition;
3091 void Controller::ResetScrollPosition()
3093 if( NULL != mImpl->mEventData )
3095 // Reset the scroll position.
3096 mImpl->mModel->mScrollPosition = Vector2::ZERO;
3097 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3101 void Controller::SetControlInterface( ControlInterface* controlInterface )
3103 mImpl->mControlInterface = controlInterface;
3106 bool Controller::ShouldClearFocusOnEscape() const
3108 return mImpl->mShouldClearFocusOnEscape;
3111 Actor Controller::CreateBackgroundActor()
3113 return mImpl->CreateBackgroundActor();
3116 // private : Private contructors & copy operator.
3118 Controller::Controller()
3119 : Controller(nullptr, nullptr, nullptr)
3123 Controller::Controller( ControlInterface* controlInterface )
3124 :Controller( controlInterface, nullptr, nullptr)
3128 Controller::Controller( ControlInterface* controlInterface,
3129 EditableControlInterface* editableControlInterface,
3130 SelectableControlInterface* selectableControlInterface )
3131 : mImpl(new Controller::Impl(controlInterface, editableControlInterface, selectableControlInterface))
3135 // The copy constructor and operator are left unimplemented.
3137 // protected : Destructor.
3139 Controller::~Controller()
3146 } // namespace Toolkit