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::SetFontSizeScale( float scale )
994 mImpl->mFontSizeScale = scale;
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::GetFontSizeScale() const
1014 if( nullptr != mImpl->mFontDefaults )
1016 return mImpl->mFontSizeScale;
1022 void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
1024 if( NULL == mImpl->mFontDefaults )
1026 mImpl->mFontDefaults = new FontDefaults();
1033 mImpl->mFontDefaults->mDefaultPointSize = fontSize;
1034 mImpl->mFontDefaults->sizeDefined = true;
1039 // Point size = Pixel size * 72.f / DPI
1040 unsigned int horizontalDpi = 0u;
1041 unsigned int verticalDpi = 0u;
1042 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1043 fontClient.GetDpi( horizontalDpi, verticalDpi );
1045 mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
1046 mImpl->mFontDefaults->sizeDefined = true;
1051 if( mImpl->mEventData )
1053 // Update the cursor position if it's in editing mode
1054 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
1056 mImpl->mEventData->mDecoratorUpdated = true;
1057 mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font size is updated.
1061 // Clear the font-specific data
1064 mImpl->RequestRelayout();
1067 float Controller::GetDefaultFontSize( FontSizeType type ) const
1070 if( NULL != mImpl->mFontDefaults )
1076 value = mImpl->mFontDefaults->mDefaultPointSize;
1081 // Pixel size = Point size * DPI / 72.f
1082 unsigned int horizontalDpi = 0u;
1083 unsigned int verticalDpi = 0u;
1084 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1085 fontClient.GetDpi( horizontalDpi, verticalDpi );
1087 value = mImpl->mFontDefaults->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1097 void Controller::SetPlaceholderTextFontSize( float fontSize, FontSizeType type )
1099 PlaceholderHandler::SetPlaceholderTextFontSize(*this, fontSize, type);
1102 float Controller::GetPlaceholderTextFontSize( FontSizeType type ) const
1104 return PlaceholderHandler::GetPlaceholderTextFontSize(*this, type);
1107 void Controller::SetDefaultColor( const Vector4& color )
1109 mImpl->mTextColor = color;
1111 if( !mImpl->IsShowingPlaceholderText() )
1113 mImpl->mModel->mVisualModel->SetTextColor( color );
1115 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
1117 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1119 mImpl->RequestRelayout();
1123 const Vector4& Controller::GetDefaultColor() const
1125 return mImpl->mTextColor;
1128 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
1130 PlaceholderHandler::SetPlaceholderTextColor(*this, textColor);
1133 const Vector4& Controller::GetPlaceholderTextColor() const
1135 return PlaceholderHandler::GetPlaceholderTextColor(*this);
1138 void Controller::SetShadowOffset( const Vector2& shadowOffset )
1140 mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
1142 mImpl->RequestRelayout();
1145 const Vector2& Controller::GetShadowOffset() const
1147 return mImpl->mModel->mVisualModel->GetShadowOffset();
1150 void Controller::SetShadowColor( const Vector4& shadowColor )
1152 mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
1154 mImpl->RequestRelayout();
1157 const Vector4& Controller::GetShadowColor() const
1159 return mImpl->mModel->mVisualModel->GetShadowColor();
1162 void Controller::SetShadowBlurRadius( const float& shadowBlurRadius )
1164 if ( fabsf( GetShadowBlurRadius() - shadowBlurRadius ) > Math::MACHINE_EPSILON_1 )
1166 mImpl->mModel->mVisualModel->SetShadowBlurRadius( shadowBlurRadius );
1168 mImpl->RequestRelayout();
1172 const float& Controller::GetShadowBlurRadius() const
1174 return mImpl->mModel->mVisualModel->GetShadowBlurRadius();
1177 void Controller::SetUnderlineColor( const Vector4& color )
1179 mImpl->mModel->mVisualModel->SetUnderlineColor( color );
1181 mImpl->RequestRelayout();
1184 const Vector4& Controller::GetUnderlineColor() const
1186 return mImpl->mModel->mVisualModel->GetUnderlineColor();
1189 void Controller::SetUnderlineEnabled( bool enabled )
1191 mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
1193 mImpl->RequestRelayout();
1196 bool Controller::IsUnderlineEnabled() const
1198 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
1201 void Controller::SetUnderlineHeight( float height )
1203 mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
1205 mImpl->RequestRelayout();
1208 float Controller::GetUnderlineHeight() const
1210 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
1213 void Controller::SetOutlineColor( const Vector4& color )
1215 mImpl->mModel->mVisualModel->SetOutlineColor( color );
1217 mImpl->RequestRelayout();
1220 const Vector4& Controller::GetOutlineColor() const
1222 return mImpl->mModel->mVisualModel->GetOutlineColor();
1225 void Controller::SetOutlineWidth( uint16_t width )
1227 mImpl->mModel->mVisualModel->SetOutlineWidth( width );
1229 mImpl->RequestRelayout();
1232 uint16_t Controller::GetOutlineWidth() const
1234 return mImpl->mModel->mVisualModel->GetOutlineWidth();
1237 void Controller::SetBackgroundColor( const Vector4& color )
1239 mImpl->mModel->mVisualModel->SetBackgroundColor( color );
1241 mImpl->RequestRelayout();
1244 const Vector4& Controller::GetBackgroundColor() const
1246 return mImpl->mModel->mVisualModel->GetBackgroundColor();
1249 void Controller::SetBackgroundEnabled( bool enabled )
1251 mImpl->mModel->mVisualModel->SetBackgroundEnabled( enabled );
1253 mImpl->RequestRelayout();
1256 bool Controller::IsBackgroundEnabled() const
1258 return mImpl->mModel->mVisualModel->IsBackgroundEnabled();
1261 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
1263 if( NULL == mImpl->mEmbossDefaults )
1265 mImpl->mEmbossDefaults = new EmbossDefaults();
1268 mImpl->mEmbossDefaults->properties = embossProperties;
1271 const std::string& Controller::GetDefaultEmbossProperties() const
1273 if( NULL != mImpl->mEmbossDefaults )
1275 return mImpl->mEmbossDefaults->properties;
1278 return EMPTY_STRING;
1281 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
1283 if( NULL == mImpl->mOutlineDefaults )
1285 mImpl->mOutlineDefaults = new OutlineDefaults();
1288 mImpl->mOutlineDefaults->properties = outlineProperties;
1291 const std::string& Controller::GetDefaultOutlineProperties() const
1293 if( NULL != mImpl->mOutlineDefaults )
1295 return mImpl->mOutlineDefaults->properties;
1298 return EMPTY_STRING;
1301 bool Controller::SetDefaultLineSpacing( float lineSpacing )
1303 if( std::fabs( lineSpacing - mImpl->mLayoutEngine.GetDefaultLineSpacing() ) > Math::MACHINE_EPSILON_1000 )
1305 mImpl->mLayoutEngine.SetDefaultLineSpacing(lineSpacing);
1306 mImpl->mRecalculateNaturalSize = true;
1312 float Controller::GetDefaultLineSpacing() const
1314 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
1317 bool Controller::SetDefaultLineSize( float lineSize )
1319 if( std::fabs( lineSize - mImpl->mLayoutEngine.GetDefaultLineSize() ) > Math::MACHINE_EPSILON_1000 )
1321 mImpl->mLayoutEngine.SetDefaultLineSize(lineSize);
1322 mImpl->mRecalculateNaturalSize = true;
1328 float Controller::GetDefaultLineSize() const
1330 return mImpl->mLayoutEngine.GetDefaultLineSize();
1333 void Controller::SetInputColor( const Vector4& color )
1335 if( NULL != mImpl->mEventData )
1337 mImpl->mEventData->mInputStyle.textColor = color;
1338 mImpl->mEventData->mInputStyle.isDefaultColor = false;
1340 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1342 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
1344 // Get start and end position of selection
1345 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
1346 const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
1348 // Add the color run.
1349 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1350 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
1352 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
1353 colorRun.color = color;
1354 colorRun.characterRun.characterIndex = startOfSelectedText;
1355 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1357 // Request to relayout.
1358 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1359 mImpl->RequestRelayout();
1361 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1362 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1363 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1368 const Vector4& Controller::GetInputColor() const
1370 if( NULL != mImpl->mEventData )
1372 return mImpl->mEventData->mInputStyle.textColor;
1375 // Return the default text's color if there is no EventData.
1376 return mImpl->mTextColor;
1380 void Controller::SetInputFontFamily( const std::string& fontFamily )
1382 InputFontHandler::SetInputFontFamily(*this, fontFamily);
1385 const std::string& Controller::GetInputFontFamily() const
1387 return InputFontHandler::GetInputFontFamily(*this);
1390 void Controller::SetInputFontWeight( FontWeight weight )
1392 InputFontHandler::SetInputFontWeight(*this, weight);
1395 bool Controller::IsInputFontWeightDefined() const
1397 return InputFontHandler::IsInputFontWeightDefined(*this);
1400 FontWeight Controller::GetInputFontWeight() const
1402 return InputFontHandler::GetInputFontWeight(*this);
1405 void Controller::SetInputFontWidth( FontWidth width )
1407 InputFontHandler::SetInputFontWidth(*this, width);
1410 bool Controller::IsInputFontWidthDefined() const
1412 return InputFontHandler::IsInputFontWidthDefined(*this);
1415 FontWidth Controller::GetInputFontWidth() const
1417 return InputFontHandler::GetInputFontWidth(*this);
1420 void Controller::SetInputFontSlant( FontSlant slant )
1422 InputFontHandler::SetInputFontSlant(*this, slant);
1425 bool Controller::IsInputFontSlantDefined() const
1427 return InputFontHandler::IsInputFontSlantDefined(*this);
1430 FontSlant Controller::GetInputFontSlant() const
1432 return InputFontHandler::GetInputFontSlant(*this);
1435 void Controller::SetInputFontPointSize( float size )
1437 InputFontHandler::SetInputFontPointSize(*this, size);
1440 float Controller::GetInputFontPointSize() const
1442 return InputFontHandler::GetInputFontPointSize(*this);
1445 void Controller::SetInputLineSpacing( float lineSpacing )
1447 if( NULL != mImpl->mEventData )
1449 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1450 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1454 float Controller::GetInputLineSpacing() const
1456 if( NULL != mImpl->mEventData )
1458 return mImpl->mEventData->mInputStyle.lineSpacing;
1464 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1466 if( NULL != mImpl->mEventData )
1468 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1472 const std::string& Controller::GetInputShadowProperties() const
1474 if( NULL != mImpl->mEventData )
1476 return mImpl->mEventData->mInputStyle.shadowProperties;
1479 return EMPTY_STRING;
1482 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1484 if( NULL != mImpl->mEventData )
1486 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1490 const std::string& Controller::GetInputUnderlineProperties() const
1492 if( NULL != mImpl->mEventData )
1494 return mImpl->mEventData->mInputStyle.underlineProperties;
1497 return EMPTY_STRING;
1500 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
1502 if( NULL != mImpl->mEventData )
1504 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1508 const std::string& Controller::GetInputEmbossProperties() const
1510 if( NULL != mImpl->mEventData )
1512 return mImpl->mEventData->mInputStyle.embossProperties;
1515 return GetDefaultEmbossProperties();
1518 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
1520 if( NULL != mImpl->mEventData )
1522 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1526 const std::string& Controller::GetInputOutlineProperties() const
1528 if( NULL != mImpl->mEventData )
1530 return mImpl->mEventData->mInputStyle.outlineProperties;
1533 return GetDefaultOutlineProperties();
1536 void Controller::SetInputModePassword( bool passwordInput )
1538 if( NULL != mImpl->mEventData )
1540 mImpl->mEventData->mPasswordInput = passwordInput;
1544 bool Controller::IsInputModePassword()
1546 if( NULL != mImpl->mEventData )
1548 return mImpl->mEventData->mPasswordInput;
1553 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
1555 if( NULL != mImpl->mEventData )
1557 mImpl->mEventData->mDoubleTapAction = action;
1561 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1563 NoTextTap::Action action = NoTextTap::NO_ACTION;
1565 if( NULL != mImpl->mEventData )
1567 action = mImpl->mEventData->mDoubleTapAction;
1573 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
1575 if( NULL != mImpl->mEventData )
1577 mImpl->mEventData->mLongPressAction = action;
1581 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1583 NoTextTap::Action action = NoTextTap::NO_ACTION;
1585 if( NULL != mImpl->mEventData )
1587 action = mImpl->mEventData->mLongPressAction;
1593 bool Controller::IsUnderlineSetByString()
1595 return mImpl->mUnderlineSetByString;
1598 void Controller::UnderlineSetByString( bool setByString )
1600 mImpl->mUnderlineSetByString = setByString;
1603 bool Controller::IsShadowSetByString()
1605 return mImpl->mShadowSetByString;
1608 void Controller::ShadowSetByString( bool setByString )
1610 mImpl->mShadowSetByString = setByString;
1613 bool Controller::IsOutlineSetByString()
1615 return mImpl->mOutlineSetByString;
1618 void Controller::OutlineSetByString( bool setByString )
1620 mImpl->mOutlineSetByString = setByString;
1623 bool Controller::IsFontStyleSetByString()
1625 return mImpl->mFontStyleSetByString;
1628 void Controller::FontStyleSetByString( bool setByString )
1630 mImpl->mFontStyleSetByString = setByString;
1633 // public : Queries & retrieves.
1635 Layout::Engine& Controller::GetLayoutEngine()
1637 return mImpl->mLayoutEngine;
1640 View& Controller::GetView()
1642 return mImpl->mView;
1645 Vector3 Controller::GetNaturalSize()
1647 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
1648 Vector3 naturalSize;
1650 // Make sure the model is up-to-date before layouting
1651 ProcessModifyEvents();
1653 if( mImpl->mRecalculateNaturalSize )
1655 // Operations that can be done only once until the text changes.
1656 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1662 GET_GLYPH_METRICS );
1664 // Set the update info to relayout the whole text.
1665 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1666 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1668 // Make sure the model is up-to-date before layouting
1669 mImpl->UpdateModel( onlyOnceOperations );
1671 // Layout the text for the new width.
1672 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT | REORDER );
1674 // Store the actual control's size to restore later.
1675 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
1677 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
1678 static_cast<OperationsMask>( onlyOnceOperations |
1680 naturalSize.GetVectorXY() );
1682 // Do not do again the only once operations.
1683 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1685 // Do the size related operations again.
1686 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1689 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1691 // Stores the natural size to avoid recalculate it again
1692 // unless the text/style changes.
1693 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
1695 mImpl->mRecalculateNaturalSize = false;
1697 // Clear the update info. This info will be set the next time the text is updated.
1698 mImpl->mTextUpdateInfo.Clear();
1699 mImpl->mTextUpdateInfo.mClearAll = true;
1701 // Restore the actual control's size.
1702 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
1704 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1708 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
1710 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1713 naturalSize.x = ConvertToEven( naturalSize.x );
1714 naturalSize.y = ConvertToEven( naturalSize.y );
1719 bool Controller::CheckForTextFit( float pointSize, Size& layoutSize )
1722 mImpl->mFontDefaults->mFitPointSize = pointSize;
1723 mImpl->mFontDefaults->sizeDefined = true;
1726 // Operations that can be done only once until the text changes.
1727 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1733 GET_GLYPH_METRICS );
1735 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1736 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1738 // Make sure the model is up-to-date before layouting
1739 mImpl->UpdateModel( onlyOnceOperations );
1741 DoRelayout( Size( layoutSize.width, MAX_FLOAT ),
1742 static_cast<OperationsMask>( onlyOnceOperations | LAYOUT),
1745 // Clear the update info. This info will be set the next time the text is updated.
1746 mImpl->mTextUpdateInfo.Clear();
1747 mImpl->mTextUpdateInfo.mClearAll = true;
1749 if( textSize.width > layoutSize.width || textSize.height > layoutSize.height )
1756 void Controller::FitPointSizeforLayout( Size layoutSize )
1758 const OperationsMask operations = mImpl->mOperationsPending;
1759 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) || mImpl->mTextFitContentSize != layoutSize )
1761 bool actualellipsis = mImpl->mModel->mElideEnabled;
1762 float minPointSize = mImpl->mTextFitMinSize;
1763 float maxPointSize = mImpl->mTextFitMaxSize;
1764 float pointInterval = mImpl->mTextFitStepSize;
1766 mImpl->mModel->mElideEnabled = false;
1767 Vector<float> pointSizeArray;
1770 if( pointInterval < 1.f )
1772 mImpl->mTextFitStepSize = pointInterval = 1.0f;
1775 pointSizeArray.Reserve( static_cast< unsigned int >( ceil( ( maxPointSize - minPointSize ) / pointInterval ) ) );
1777 for( float i = minPointSize; i < maxPointSize; i += pointInterval )
1779 pointSizeArray.PushBack( i );
1782 pointSizeArray.PushBack( maxPointSize );
1784 int bestSizeIndex = 0;
1785 int min = bestSizeIndex + 1;
1786 int max = pointSizeArray.Size() - 1;
1789 int destI = ( min + max ) / 2;
1791 if( CheckForTextFit( pointSizeArray[destI], layoutSize ) )
1793 bestSizeIndex = min;
1799 bestSizeIndex = max;
1803 mImpl->mModel->mElideEnabled = actualellipsis;
1804 mImpl->mFontDefaults->mFitPointSize = pointSizeArray[bestSizeIndex];
1805 mImpl->mFontDefaults->sizeDefined = true;
1810 float Controller::GetHeightForWidth( float width )
1812 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
1813 // Make sure the model is up-to-date before layouting
1814 ProcessModifyEvents();
1817 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ||
1818 mImpl->mTextUpdateInfo.mFullRelayoutNeeded ||
1819 mImpl->mTextUpdateInfo.mClearAll )
1821 // Operations that can be done only once until the text changes.
1822 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1828 GET_GLYPH_METRICS );
1830 // Set the update info to relayout the whole text.
1831 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1832 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1834 // Make sure the model is up-to-date before layouting
1835 mImpl->UpdateModel( onlyOnceOperations );
1838 // Layout the text for the new width.
1839 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
1841 // Store the actual control's width.
1842 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
1844 DoRelayout( Size( width, MAX_FLOAT ),
1845 static_cast<OperationsMask>( onlyOnceOperations |
1849 // Do not do again the only once operations.
1850 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1852 // Do the size related operations again.
1853 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1857 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1859 // Clear the update info. This info will be set the next time the text is updated.
1860 mImpl->mTextUpdateInfo.Clear();
1861 mImpl->mTextUpdateInfo.mClearAll = true;
1863 // Restore the actual control's width.
1864 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
1866 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
1870 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
1871 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
1874 return layoutSize.height;
1877 int Controller::GetLineCount( float width )
1879 GetHeightForWidth( width );
1880 int numberofLines = mImpl->mModel->GetNumberOfLines();
1881 return numberofLines;
1884 const ModelInterface* const Controller::GetTextModel() const
1886 return mImpl->mModel.Get();
1889 float Controller::GetScrollAmountByUserInput()
1891 float scrollAmount = 0.0f;
1893 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
1895 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
1896 mImpl->mEventData->mCheckScrollAmount = false;
1898 return scrollAmount;
1901 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
1903 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
1906 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
1907 layoutHeight = layout.height;
1908 scrollPosition = mImpl->mModel->mScrollPosition.y;
1909 isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
1913 void Controller::SetHiddenInputOption(const Property::Map& options )
1915 if( NULL == mImpl->mHiddenInput )
1917 mImpl->mHiddenInput = new HiddenText( this );
1919 mImpl->mHiddenInput->SetProperties(options);
1922 void Controller::GetHiddenInputOption(Property::Map& options )
1924 if( NULL != mImpl->mHiddenInput )
1926 mImpl->mHiddenInput->GetProperties(options);
1930 void Controller::SetPlaceholderProperty( const Property::Map& map )
1932 PlaceholderHandler::SetPlaceholderProperty(*this, map);
1935 void Controller::GetPlaceholderProperty( Property::Map& map )
1937 PlaceholderHandler::GetPlaceholderProperty(*this, map);
1940 Toolkit::DevelText::TextDirection::Type Controller::GetTextDirection()
1942 // Make sure the model is up-to-date before layouting
1943 ProcessModifyEvents();
1945 if ( mImpl->mUpdateTextDirection )
1947 // Operations that can be done only once until the text changes.
1948 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1954 GET_GLYPH_METRICS );
1956 // Set the update info to relayout the whole text.
1957 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1958 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1960 // Make sure the model is up-to-date before layouting
1961 mImpl->UpdateModel( onlyOnceOperations );
1963 Vector3 naturalSize;
1964 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
1965 static_cast<OperationsMask>( onlyOnceOperations |
1966 LAYOUT | REORDER | UPDATE_DIRECTION ),
1967 naturalSize.GetVectorXY() );
1969 // Do not do again the only once operations.
1970 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1972 // Clear the update info. This info will be set the next time the text is updated.
1973 mImpl->mTextUpdateInfo.Clear();
1975 // FullRelayoutNeeded should be true because DoRelayout is MAX_FLOAT, MAX_FLOAT.
1976 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
1978 mImpl->mUpdateTextDirection = false;
1981 return mImpl->mIsTextDirectionRTL ? Toolkit::DevelText::TextDirection::RIGHT_TO_LEFT : Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT;
1984 Toolkit::DevelText::VerticalLineAlignment::Type Controller::GetVerticalLineAlignment() const
1986 return mImpl->mModel->GetVerticalLineAlignment();
1989 void Controller::SetVerticalLineAlignment( Toolkit::DevelText::VerticalLineAlignment::Type alignment )
1991 mImpl->mModel->mVerticalLineAlignment = alignment;
1994 // public : Relayout.
1996 Controller::UpdateTextType Controller::Relayout( const Size& size, Dali::LayoutDirection::Type layoutDirection )
1998 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
2000 UpdateTextType updateTextType = NONE_UPDATED;
2002 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
2004 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
2006 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
2007 updateTextType = MODEL_UPDATED;
2010 // Clear the update info. This info will be set the next time the text is updated.
2011 mImpl->mTextUpdateInfo.Clear();
2013 // Not worth to relayout if width or height is equal to zero.
2014 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
2016 return updateTextType;
2019 // Whether a new size has been set.
2020 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
2024 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
2026 if( ( 0 == mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd ) &&
2027 ( 0 == mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) &&
2028 ( ( mImpl->mModel->mVisualModel->mControlSize.width < Math::MACHINE_EPSILON_1000 ) || ( mImpl->mModel->mVisualModel->mControlSize.height < Math::MACHINE_EPSILON_1000 ) ) )
2030 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
2033 // Layout operations that need to be done if the size changes.
2034 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2037 UPDATE_LAYOUT_SIZE |
2039 // Set the update info to relayout the whole text.
2040 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2041 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2043 // Store the size used to layout the text.
2044 mImpl->mModel->mVisualModel->mControlSize = size;
2047 // Whether there are modify events.
2048 if( 0u != mImpl->mModifyEvents.Count() )
2050 // Style operations that need to be done if the text is modified.
2051 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2055 // Set the update info to elide the text.
2056 if( mImpl->mModel->mElideEnabled ||
2057 ( ( NULL != mImpl->mEventData ) && mImpl->mEventData->mIsPlaceholderElideEnabled ) )
2059 // Update Text layout for applying elided
2060 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2063 UPDATE_LAYOUT_SIZE |
2065 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2066 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2069 if( mImpl->mModel->mMatchSystemLanguageDirection && mImpl->mLayoutDirection != layoutDirection )
2071 // Clear the update info. This info will be set the next time the text is updated.
2072 mImpl->mTextUpdateInfo.mClearAll = true;
2073 // Apply modifications to the model
2074 // Shape the text again is needed because characters like '()[]{}' have to be mirrored and the glyphs generated again.
2075 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2082 mImpl->mLayoutDirection = layoutDirection;
2085 // Make sure the model is up-to-date before layouting.
2086 ProcessModifyEvents();
2087 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
2091 updated = DoRelayout( size,
2092 mImpl->mOperationsPending,
2093 layoutSize ) || updated;
2098 updateTextType = MODEL_UPDATED;
2101 // Do not re-do any operation until something changes.
2102 mImpl->mOperationsPending = NO_OPERATION;
2103 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
2105 // Whether the text control is editable
2106 const bool isEditable = NULL != mImpl->mEventData;
2108 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
2110 if( newSize && isEditable )
2112 offset = mImpl->mModel->mScrollPosition;
2115 if( !isEditable || !IsMultiLineEnabled() )
2117 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
2118 CalculateVerticalOffset( size );
2125 // If there is a new size, the scroll position needs to be clamped.
2126 mImpl->ClampHorizontalScroll( layoutSize );
2128 // Update the decorator's positions is needed if there is a new size.
2129 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
2132 // Move the cursor, grab handle etc.
2133 if( mImpl->ProcessInputEvents() )
2135 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
2139 // Clear the update info. This info will be set the next time the text is updated.
2140 mImpl->mTextUpdateInfo.Clear();
2141 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
2143 return updateTextType;
2146 void Controller::RequestRelayout()
2148 mImpl->RequestRelayout();
2151 // public : Input style change signals.
2153 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
2155 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
2158 void Controller::ProcessInputStyleChangedSignals()
2160 if( NULL == mImpl->mEventData )
2166 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
2167 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
2171 const InputStyle::Mask mask = *it;
2173 if( NULL != mImpl->mEditableControlInterface )
2175 // Emit the input style changed signal.
2176 mImpl->mEditableControlInterface->InputStyleChanged( mask );
2180 mImpl->mEventData->mInputStyleChangedQueue.Clear();
2183 // public : Text-input Event Queuing.
2185 void Controller::KeyboardFocusGainEvent()
2187 EventHandler::KeyboardFocusGainEvent(*this);
2190 void Controller::KeyboardFocusLostEvent()
2192 EventHandler::KeyboardFocusLostEvent(*this);
2195 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
2197 return EventHandler::KeyEvent(*this, keyEvent);
2200 void Controller::TapEvent( unsigned int tapCount, float x, float y )
2202 EventHandler::TapEvent(*this, tapCount, x, y);
2205 void Controller::PanEvent( GestureState state, const Vector2& displacement )
2207 EventHandler::PanEvent(*this, state, displacement);
2210 void Controller::LongPressEvent( GestureState state, float x, float y )
2212 EventHandler::LongPressEvent(*this, state, x, y);
2215 void Controller::SelectEvent( float x, float y, SelectionType selectType )
2217 EventHandler::SelectEvent(*this, x, y, selectType);
2220 void Controller::SetTextSelectionRange(const uint32_t *start, const uint32_t *end)
2222 if( mImpl->mEventData )
2224 mImpl->mEventData->mCheckScrollAmount = true;
2225 mImpl->mEventData->mIsLeftHandleSelected = true;
2226 mImpl->mEventData->mIsRightHandleSelected = true;
2227 mImpl->SetTextSelectionRange(start, end);
2228 mImpl->RequestRelayout();
2229 KeyboardFocusGainEvent();
2233 Uint32Pair Controller::GetTextSelectionRange() const
2235 return mImpl->GetTextSelectionRange();
2238 void Controller::SelectWholeText()
2240 SelectEvent( 0.f, 0.f, SelectionType::ALL );
2243 void Controller::SelectNone()
2245 SelectEvent( 0.f, 0.f, SelectionType::NONE );
2248 string Controller::GetSelectedText() const
2251 if( EventData::SELECTING == mImpl->mEventData->mState )
2253 mImpl->RetrieveSelection( text, false );
2258 InputMethodContext::CallbackData Controller::OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
2260 return EventHandler::OnInputMethodContextEvent(*this, inputMethodContext, inputMethodContextEvent);
2263 void Controller::PasteClipboardItemEvent()
2265 EventHandler::PasteClipboardItemEvent(*this);
2268 // protected : Inherit from Text::Decorator::ControllerInterface.
2270 void Controller::GetTargetSize( Vector2& targetSize )
2272 targetSize = mImpl->mModel->mVisualModel->mControlSize;
2275 void Controller::AddDecoration( Actor& actor, bool needsClipping )
2277 if( NULL != mImpl->mEditableControlInterface )
2279 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
2283 bool Controller::IsEditable() const
2285 return mImpl->IsEditable();
2288 void Controller::SetEditable( bool editable )
2290 mImpl->SetEditable( editable );
2291 if(mImpl->mEventData && mImpl->mEventData->mDecorator)
2293 mImpl->mEventData->mDecorator->SetEditable( editable );
2297 void Controller::ScrollBy( Vector2 scroll )
2299 if( mImpl->mEventData && (fabs(scroll.x) > Math::MACHINE_EPSILON_0 || fabs(scroll.y) > Math::MACHINE_EPSILON_0))
2301 const Vector2& layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
2302 const Vector2 currentScroll = mImpl->mModel->mScrollPosition;
2304 scroll.x = -scroll.x;
2305 scroll.y = -scroll.y;
2307 if( fabs(scroll.x) > Math::MACHINE_EPSILON_0 )
2309 mImpl->mModel->mScrollPosition.x += scroll.x;
2310 mImpl->ClampHorizontalScroll( layoutSize );
2313 if( fabs(scroll.y) > Math::MACHINE_EPSILON_0 )
2315 mImpl->mModel->mScrollPosition.y += scroll.y;
2316 mImpl->ClampVerticalScroll( layoutSize );
2319 if (mImpl->mModel->mScrollPosition != currentScroll)
2321 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - currentScroll );
2322 mImpl->RequestRelayout();
2327 float Controller::GetHorizontalScrollPosition()
2329 if( mImpl->mEventData )
2331 //scroll values are negative internally so we convert them to positive numbers
2332 return -mImpl->mModel->mScrollPosition.x;
2337 float Controller::GetVerticalScrollPosition()
2339 if( mImpl->mEventData )
2341 //scroll values are negative internally so we convert them to positive numbers
2342 return -mImpl->mModel->mScrollPosition.y;
2347 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
2349 EventHandler::DecorationEvent(*this, handleType, state, x, y);
2352 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
2354 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
2356 EventHandler::TextPopupButtonTouched(*this, button);
2359 void Controller::DisplayTimeExpired()
2361 mImpl->mEventData->mUpdateCursorPosition = true;
2362 // Apply modifications to the model
2363 mImpl->mOperationsPending = ALL_OPERATIONS;
2365 mImpl->RequestRelayout();
2368 // private : Update.
2370 void Controller::InsertText( const std::string& text, Controller::InsertType type )
2372 bool removedPrevious = false;
2373 bool removedSelected = false;
2374 bool maxLengthReached = false;
2376 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
2378 if( NULL == mImpl->mEventData )
2383 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
2384 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
2385 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
2387 // TODO: At the moment the underline runs are only for pre-edit.
2388 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
2390 // Remove the previous InputMethodContext pre-edit.
2391 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
2393 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
2394 mImpl->mEventData->mPreEditLength,
2395 DONT_UPDATE_INPUT_STYLE );
2397 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
2398 mImpl->mEventData->mPreEditLength = 0u;
2402 // Remove the previous Selection.
2403 removedSelected = RemoveSelectedText();
2407 Vector<Character> utf32Characters;
2408 Length characterCount = 0u;
2412 // Convert text into UTF-32
2413 utf32Characters.Resize( text.size() );
2415 // This is a bit horrible but std::string returns a (signed) char*
2416 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
2418 // Transform a text array encoded in utf8 into an array encoded in utf32.
2419 // It returns the actual number of characters.
2420 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
2421 utf32Characters.Resize( characterCount );
2423 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
2424 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
2427 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
2429 // The placeholder text is no longer needed
2430 if( mImpl->IsShowingPlaceholderText() )
2435 mImpl->ChangeState( EventData::EDITING );
2437 // Handle the InputMethodContext (predicitive text) state changes
2438 if( COMMIT == type )
2440 // InputMethodContext is no longer handling key-events
2441 mImpl->ClearPreEditFlag();
2445 if( !mImpl->mEventData->mPreEditFlag )
2447 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
2449 // Record the start of the pre-edit text
2450 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
2453 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
2454 mImpl->mEventData->mPreEditFlag = true;
2456 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
2459 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
2461 // Restrict new text to fit within Maximum characters setting.
2462 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
2463 maxLengthReached = ( characterCount > maxSizeOfNewText );
2465 // The cursor position.
2466 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
2468 // Update the text's style.
2470 // Updates the text style runs by adding characters.
2471 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
2473 // Get the character index from the cursor index.
2474 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
2476 // Retrieve the text's style for the given index.
2478 mImpl->RetrieveDefaultInputStyle( style );
2479 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
2481 // Whether to add a new text color run.
2482 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor ) && !mImpl->mEventData->mInputStyle.isDefaultColor;
2484 // Whether to add a new font run.
2485 const bool addFontNameRun = ( style.familyName != mImpl->mEventData->mInputStyle.familyName ) && mImpl->mEventData->mInputStyle.isFamilyDefined;
2486 const bool addFontWeightRun = ( style.weight != mImpl->mEventData->mInputStyle.weight ) && mImpl->mEventData->mInputStyle.isWeightDefined;
2487 const bool addFontWidthRun = ( style.width != mImpl->mEventData->mInputStyle.width ) && mImpl->mEventData->mInputStyle.isWidthDefined;
2488 const bool addFontSlantRun = ( style.slant != mImpl->mEventData->mInputStyle.slant ) && mImpl->mEventData->mInputStyle.isSlantDefined;
2489 const bool addFontSizeRun = ( style.size != mImpl->mEventData->mInputStyle.size ) && mImpl->mEventData->mInputStyle.isSizeDefined ;
2494 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
2495 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
2497 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
2498 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
2499 colorRun.characterRun.characterIndex = cursorIndex;
2500 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
2503 if( addFontNameRun ||
2509 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
2510 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
2512 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
2514 if( addFontNameRun )
2516 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
2517 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
2518 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
2519 fontDescriptionRun.familyDefined = true;
2521 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
2524 if( addFontWeightRun )
2526 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
2527 fontDescriptionRun.weightDefined = true;
2530 if( addFontWidthRun )
2532 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
2533 fontDescriptionRun.widthDefined = true;
2536 if( addFontSlantRun )
2538 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
2539 fontDescriptionRun.slantDefined = true;
2542 if( addFontSizeRun )
2544 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * mImpl->mFontSizeScale * 64.f );
2545 fontDescriptionRun.sizeDefined = true;
2548 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
2549 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
2552 // Insert at current cursor position.
2553 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
2555 auto pos = modifyText.End();
2556 if( cursorIndex < numberOfCharactersInModel )
2558 pos = modifyText.Begin() + cursorIndex;
2560 unsigned int realPos = pos - modifyText.Begin();
2561 modifyText.Insert( pos, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
2563 if( NULL != mImpl->mEditableControlInterface )
2565 mImpl->mEditableControlInterface->TextInserted( realPos, maxSizeOfNewText, text );
2568 // Mark the first paragraph 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 = numberOfCharactersInModel + maxSizeOfNewText;
2574 mImpl->mTextUpdateInfo.mClearAll = true;
2578 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
2579 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
2582 // Update the cursor index.
2583 cursorIndex += maxSizeOfNewText;
2585 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 );
2588 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
2589 mImpl->IsPlaceholderAvailable() )
2591 // Show place-holder if empty after removing the pre-edit text
2592 ShowPlaceholderText();
2593 mImpl->mEventData->mUpdateCursorPosition = true;
2594 mImpl->ClearPreEditFlag();
2596 else if( removedPrevious ||
2598 ( 0 != utf32Characters.Count() ) )
2600 // Queue an inserted event
2601 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
2603 mImpl->mEventData->mUpdateCursorPosition = true;
2604 if( removedSelected )
2606 mImpl->mEventData->mScrollAfterDelete = true;
2610 mImpl->mEventData->mScrollAfterUpdatePosition = true;
2614 if( maxLengthReached )
2616 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
2618 mImpl->ResetInputMethodContext();
2620 if( NULL != mImpl->mEditableControlInterface )
2622 // Do this last since it provides callbacks into application code
2623 mImpl->mEditableControlInterface->MaxLengthReached();
2628 void Controller::PasteText( const std::string& stringToPaste )
2630 InsertText( stringToPaste, Text::Controller::COMMIT );
2631 mImpl->ChangeState( EventData::EDITING );
2632 mImpl->RequestRelayout();
2634 if( NULL != mImpl->mEditableControlInterface )
2636 // Do this last since it provides callbacks into application code
2637 mImpl->mEditableControlInterface->TextChanged();
2641 bool Controller::RemoveText( int cursorOffset,
2642 int numberOfCharacters,
2643 UpdateInputStyleType type )
2645 bool removed = false;
2647 if( NULL == mImpl->mEventData )
2652 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
2653 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
2655 if( !mImpl->IsShowingPlaceholderText() )
2657 // Delete at current cursor position
2658 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
2659 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
2661 CharacterIndex cursorIndex = 0;
2663 // Validate the cursor position & number of characters
2664 if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
2666 cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
2669 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
2671 numberOfCharacters = currentText.Count() - cursorIndex;
2674 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.
2675 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
2677 // Mark the paragraphs to be updated.
2678 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
2680 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
2681 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2682 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
2683 mImpl->mTextUpdateInfo.mClearAll = true;
2687 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
2688 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
2691 // Update the input style and remove the text's style before removing the text.
2693 if( UPDATE_INPUT_STYLE == type )
2695 // Keep a copy of the current input style.
2696 InputStyle currentInputStyle;
2697 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
2699 // Set first the default input style.
2700 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
2702 // Update the input style.
2703 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
2705 // Compare if the input style has changed.
2706 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
2708 if( hasInputStyleChanged )
2710 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
2711 // Queue the input style changed signal.
2712 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
2716 // If the number of current text and the number of characters to be deleted are same,
2717 // it means all texts should be removed and all Preedit variables should be initialized.
2718 if( ( currentText.Count() - numberOfCharacters == 0 ) && ( cursorIndex == 0 ) )
2720 mImpl->ClearPreEditFlag();
2721 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0;
2724 // Updates the text style runs by removing characters. Runs with no characters are removed.
2725 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
2727 // Remove the characters.
2728 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
2729 Vector<Character>::Iterator last = first + numberOfCharacters;
2731 if( NULL != mImpl->mEditableControlInterface )
2734 Utf32ToUtf8( first, numberOfCharacters, utf8 );
2735 mImpl->mEditableControlInterface->TextDeleted( cursorIndex, numberOfCharacters, utf8 );
2738 currentText.Erase( first, last );
2740 // Cursor position retreat
2741 oldCursorIndex = cursorIndex;
2743 mImpl->mEventData->mScrollAfterDelete = true;
2745 if( EventData::INACTIVE == mImpl->mEventData->mState )
2747 mImpl->ChangeState( EventData::EDITING );
2750 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
2758 bool Controller::RemoveSelectedText()
2760 bool textRemoved( false );
2762 if( EventData::SELECTING == mImpl->mEventData->mState )
2764 std::string removedString;
2765 mImpl->RetrieveSelection( removedString, true );
2767 if( !removedString.empty() )
2770 mImpl->ChangeState( EventData::EDITING );
2777 // private : Relayout.
2779 bool Controller::DoRelayout( const Size& size,
2780 OperationsMask operationsRequired,
2783 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
2784 bool viewUpdated( false );
2786 // Calculate the operations to be done.
2787 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
2789 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
2790 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
2792 // Get the current layout size.
2793 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
2795 if( NO_OPERATION != ( LAYOUT & operations ) )
2797 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
2799 // Some vectors with data needed to layout and reorder may be void
2800 // after the first time the text has been laid out.
2801 // Fill the vectors again.
2803 // Calculate the number of glyphs to layout.
2804 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
2805 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
2806 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
2807 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
2809 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
2810 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
2812 // Make sure the index is not out of bound
2813 if ( charactersToGlyph.Count() != glyphsPerCharacter.Count() ||
2814 requestedNumberOfCharacters > charactersToGlyph.Count() ||
2815 ( lastIndex > charactersToGlyph.Count() && charactersToGlyph.Count() > 0u ) )
2817 std::string currentText;
2818 GetText( currentText );
2820 DALI_LOG_ERROR( "Controller::DoRelayout: Attempting to access invalid buffer\n" );
2821 DALI_LOG_ERROR( "Current text is: %s\n", currentText.c_str() );
2822 DALI_LOG_ERROR( "startIndex: %u, lastIndex: %u, requestedNumberOfCharacters: %u, charactersToGlyph.Count = %lu, glyphsPerCharacter.Count = %lu\n", startIndex, lastIndex, requestedNumberOfCharacters, charactersToGlyph.Count(), glyphsPerCharacter.Count());
2827 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
2828 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
2830 if( 0u == totalNumberOfGlyphs )
2832 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
2834 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
2837 // Nothing else to do if there is no glyphs.
2838 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
2842 // Set the layout parameters.
2843 Layout::Parameters layoutParameters( size,
2846 // Resize the vector of positions to have the same size than the vector of glyphs.
2847 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
2848 glyphPositions.Resize( totalNumberOfGlyphs );
2850 // Whether the last character is a new paragraph character.
2851 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
2852 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
2853 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
2855 // The initial glyph and the number of glyphs to layout.
2856 layoutParameters.startGlyphIndex = startGlyphIndex;
2857 layoutParameters.numberOfGlyphs = numberOfGlyphs;
2858 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
2859 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
2861 // Update the ellipsis
2862 bool elideTextEnabled = mImpl->mModel->mElideEnabled;
2864 if( NULL != mImpl->mEventData )
2866 if( mImpl->mEventData->mPlaceholderEllipsisFlag && mImpl->IsShowingPlaceholderText() )
2868 elideTextEnabled = mImpl->mEventData->mIsPlaceholderElideEnabled;
2870 else if( EventData::INACTIVE != mImpl->mEventData->mState )
2872 // Disable ellipsis when editing
2873 elideTextEnabled = false;
2876 // Reset the scroll position in inactive state
2877 if( elideTextEnabled && ( mImpl->mEventData->mState == EventData::INACTIVE ) )
2879 ResetScrollPosition();
2883 // Update the visual model.
2884 bool isAutoScrollEnabled = mImpl->mIsAutoScrollEnabled;
2886 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
2889 isAutoScrollEnabled );
2890 mImpl->mIsAutoScrollEnabled = isAutoScrollEnabled;
2892 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
2896 layoutSize = newLayoutSize;
2898 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
2900 mImpl->mIsTextDirectionRTL = false;
2903 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && !mImpl->mModel->mVisualModel->mLines.Empty() )
2905 mImpl->mIsTextDirectionRTL = mImpl->mModel->mVisualModel->mLines[0u].direction;
2908 // Sets the layout size.
2909 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
2911 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
2916 if( NO_OPERATION != ( ALIGN & operations ) )
2918 // The laid-out lines.
2919 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
2921 CharacterIndex alignStartIndex = startIndex;
2922 Length alignRequestedNumberOfCharacters = requestedNumberOfCharacters;
2924 // the whole text needs to be full aligned.
2925 // If you do not do a full aligned, only the last line of the multiline input is aligned.
2926 if( mImpl->mEventData && mImpl->mEventData->mUpdateAlignment )
2928 alignStartIndex = 0u;
2929 alignRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2930 mImpl->mEventData->mUpdateAlignment = false;
2933 // Need to align with the control's size as the text may contain lines
2934 // starting either with left to right text or right to left.
2935 mImpl->mLayoutEngine.Align( size,
2937 alignRequestedNumberOfCharacters,
2938 mImpl->mModel->mHorizontalAlignment,
2940 mImpl->mModel->mAlignmentOffset,
2941 mImpl->mLayoutDirection,
2942 mImpl->mModel->mMatchSystemLanguageDirection );
2946 #if defined(DEBUG_ENABLED)
2947 std::string currentText;
2948 GetText( currentText );
2949 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mIsTextDirectionRTL[%s] [%s]\n", this, (mImpl->mIsTextDirectionRTL)?"true":"false", currentText.c_str() );
2951 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
2955 void Controller::CalculateVerticalOffset( const Size& controlSize )
2957 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
2959 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
2961 // Get the line height of the default font.
2962 layoutSize.height = mImpl->GetDefaultFontLineHeight();
2965 switch( mImpl->mModel->mVerticalAlignment )
2967 case VerticalAlignment::TOP:
2969 mImpl->mModel->mScrollPosition.y = 0.f;
2972 case VerticalAlignment::CENTER:
2974 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
2977 case VerticalAlignment::BOTTOM:
2979 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
2985 // private : Events.
2987 void Controller::ProcessModifyEvents()
2989 EventHandler::ProcessModifyEvents(*this);
2992 void Controller::TextReplacedEvent()
2994 EventHandler::TextReplacedEvent(*this);
2997 void Controller::TextInsertedEvent()
2999 EventHandler::TextInsertedEvent(*this);
3002 void Controller::TextDeletedEvent()
3004 EventHandler::TextDeletedEvent(*this);
3007 bool Controller::DeleteEvent( int keyCode )
3009 return EventHandler::DeleteEvent(*this, keyCode);
3012 // private : Helpers.
3014 void Controller::ResetText()
3017 mImpl->mModel->mLogicalModel->mText.Clear();
3019 // Reset the embedded images buffer.
3020 mImpl->mModel->mLogicalModel->ClearEmbeddedImages();
3022 // We have cleared everything including the placeholder-text
3023 mImpl->PlaceholderCleared();
3025 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3026 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3027 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
3029 // Clear any previous text.
3030 mImpl->mTextUpdateInfo.mClearAll = true;
3032 // The natural size needs to be re-calculated.
3033 mImpl->mRecalculateNaturalSize = true;
3035 // The text direction needs to be updated.
3036 mImpl->mUpdateTextDirection = true;
3038 // Apply modifications to the model
3039 mImpl->mOperationsPending = ALL_OPERATIONS;
3042 void Controller::ShowPlaceholderText()
3044 if( mImpl->IsPlaceholderAvailable() )
3046 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
3048 if( NULL == mImpl->mEventData )
3053 mImpl->mEventData->mIsShowingPlaceholderText = true;
3055 // Disable handles when showing place-holder text
3056 mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
3057 mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
3058 mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
3060 const char* text( NULL );
3063 // TODO - Switch Placeholder text when changing state
3064 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
3065 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
3067 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
3068 size = mImpl->mEventData->mPlaceholderTextActive.size();
3072 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
3073 size = mImpl->mEventData->mPlaceholderTextInactive.size();
3076 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3077 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3079 // Reset model for showing placeholder.
3080 mImpl->mModel->mLogicalModel->mText.Clear();
3081 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
3083 // Convert text into UTF-32
3084 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
3085 utf32Characters.Resize( size );
3087 // This is a bit horrible but std::string returns a (signed) char*
3088 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
3090 // Transform a text array encoded in utf8 into an array encoded in utf32.
3091 // It returns the actual number of characters.
3092 const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
3093 utf32Characters.Resize( characterCount );
3095 // The characters to be added.
3096 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
3098 // Reset the cursor position
3099 mImpl->mEventData->mPrimaryCursorPosition = 0;
3101 // The natural size needs to be re-calculated.
3102 mImpl->mRecalculateNaturalSize = true;
3104 // The text direction needs to be updated.
3105 mImpl->mUpdateTextDirection = true;
3107 // Apply modifications to the model
3108 mImpl->mOperationsPending = ALL_OPERATIONS;
3110 // Update the rest of the model during size negotiation
3111 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
3115 void Controller::ClearFontData()
3117 if( mImpl->mFontDefaults )
3119 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
3122 // Set flags to update the model.
3123 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3124 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3125 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
3127 mImpl->mTextUpdateInfo.mClearAll = true;
3128 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
3129 mImpl->mRecalculateNaturalSize = true;
3131 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
3137 UPDATE_LAYOUT_SIZE |
3142 void Controller::ClearStyleData()
3144 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
3145 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
3148 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
3150 // Reset the cursor position
3151 if( NULL != mImpl->mEventData )
3153 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
3155 // Update the cursor if it's in editing mode.
3156 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
3158 mImpl->mEventData->mUpdateCursorPosition = true;
3163 CharacterIndex Controller::GetCursorPosition()
3165 if( !mImpl->mEventData )
3168 return mImpl->mEventData->mPrimaryCursorPosition;
3171 void Controller::ResetScrollPosition()
3173 if( NULL != mImpl->mEventData )
3175 // Reset the scroll position.
3176 mImpl->mModel->mScrollPosition = Vector2::ZERO;
3177 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3181 void Controller::SetControlInterface( ControlInterface* controlInterface )
3183 mImpl->mControlInterface = controlInterface;
3186 bool Controller::ShouldClearFocusOnEscape() const
3188 return mImpl->mShouldClearFocusOnEscape;
3191 Actor Controller::CreateBackgroundActor()
3193 return mImpl->CreateBackgroundActor();
3196 // private : Private contructors & copy operator.
3198 Controller::Controller()
3199 : Controller(nullptr, nullptr, nullptr)
3203 Controller::Controller( ControlInterface* controlInterface )
3204 :Controller( controlInterface, nullptr, nullptr)
3208 Controller::Controller( ControlInterface* controlInterface,
3209 EditableControlInterface* editableControlInterface,
3210 SelectableControlInterface* selectableControlInterface )
3211 : mImpl(new Controller::Impl(controlInterface, editableControlInterface, selectableControlInterface))
3215 // The copy constructor and operator are left unimplemented.
3217 // protected : Destructor.
3219 Controller::~Controller()
3226 } // namespace Toolkit