2 * Copyright (c) 2019 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/public-api/adaptor-framework/key.h>
26 #include <dali/integration-api/debug.h>
27 #include <dali/devel-api/adaptor-framework/clipboard-event-notifier.h>
28 #include <dali/devel-api/text-abstraction/font-client.h>
29 #include <dali/devel-api/adaptor-framework/key-devel.h>
32 #include <dali-toolkit/public-api/controls/text-controls/placeholder-properties.h>
33 #include <dali-toolkit/internal/text/bidirectional-support.h>
34 #include <dali-toolkit/internal/text/character-set-conversion.h>
35 #include <dali-toolkit/internal/text/layouts/layout-parameters.h>
36 #include <dali-toolkit/internal/text/markup-processor.h>
37 #include <dali-toolkit/internal/text/multi-language-support.h>
38 #include <dali-toolkit/internal/text/text-controller-impl.h>
39 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
40 #include <dali-toolkit/internal/text/text-font-style.h>
45 #if defined(DEBUG_ENABLED)
46 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
49 const float MAX_FLOAT = std::numeric_limits<float>::max();
51 const std::string EMPTY_STRING("");
53 const std::string KEY_C_NAME = "c";
54 const std::string KEY_V_NAME = "v";
55 const std::string KEY_X_NAME = "x";
57 const char * const PLACEHOLDER_TEXT = "text";
58 const char * const PLACEHOLDER_TEXT_FOCUSED = "textFocused";
59 const char * const PLACEHOLDER_COLOR = "color";
60 const char * const PLACEHOLDER_FONT_FAMILY = "fontFamily";
61 const char * const PLACEHOLDER_FONT_STYLE = "fontStyle";
62 const char * const PLACEHOLDER_POINT_SIZE = "pointSize";
63 const char * const PLACEHOLDER_PIXEL_SIZE = "pixelSize";
64 const char * const PLACEHOLDER_ELLIPSIS = "ellipsis";
65 const unsigned int MAX_TEXT_LENGTH = 1024u * 32u;
67 float ConvertToEven( float value )
69 int intValue(static_cast<int>( value ));
70 return static_cast<float>( intValue + ( intValue & 1 ) );
73 int ConvertPixelToPint( float pixel )
75 unsigned int horizontalDpi = 0u;
76 unsigned int verticalDpi = 0u;
77 Dali::TextAbstraction::FontClient fontClient = Dali::TextAbstraction::FontClient::Get();
78 fontClient.GetDpi( horizontalDpi, verticalDpi );
80 return ( pixel * 72.f ) / static_cast< float >( horizontalDpi );
96 * @brief Adds a new font description run for the selected text.
98 * The new font parameters are added after the call to this method.
100 * @param[in] eventData The event data pointer.
101 * @param[in] logicalModel The logical model where to add the new font description run.
102 * @param[out] startOfSelectedText Index to the first selected character.
103 * @param[out] lengthOfSelectedText Number of selected characters.
105 FontDescriptionRun& UpdateSelectionFontStyleRun( EventData* eventData,
106 LogicalModelPtr logicalModel,
107 CharacterIndex& startOfSelectedText,
108 Length& lengthOfSelectedText )
110 const bool handlesCrossed = eventData->mLeftSelectionPosition > eventData->mRightSelectionPosition;
112 // Get start and end position of selection
113 startOfSelectedText = handlesCrossed ? eventData->mRightSelectionPosition : eventData->mLeftSelectionPosition;
114 lengthOfSelectedText = ( handlesCrossed ? eventData->mLeftSelectionPosition : eventData->mRightSelectionPosition ) - startOfSelectedText;
117 const VectorBase::SizeType numberOfRuns = logicalModel->mFontDescriptionRuns.Count();
118 logicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
120 FontDescriptionRun& fontDescriptionRun = *( logicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
122 fontDescriptionRun.characterRun.characterIndex = startOfSelectedText;
123 fontDescriptionRun.characterRun.numberOfCharacters = lengthOfSelectedText;
125 // Recalculate the selection highlight as the metrics may have changed.
126 eventData->mUpdateLeftSelectionPosition = true;
127 eventData->mUpdateRightSelectionPosition = true;
128 eventData->mUpdateHighlightBox = true;
130 return fontDescriptionRun;
133 // public : Constructor.
135 ControllerPtr Controller::New()
137 return ControllerPtr( new Controller() );
140 ControllerPtr Controller::New( ControlInterface* controlInterface )
142 return ControllerPtr( new Controller( controlInterface ) );
145 ControllerPtr Controller::New( ControlInterface* controlInterface,
146 EditableControlInterface* editableControlInterface )
148 return ControllerPtr( new Controller( controlInterface,
149 editableControlInterface ) );
152 // public : Configure the text controller.
154 void Controller::EnableTextInput( DecoratorPtr decorator, InputMethodContext& inputMethodContext )
158 delete mImpl->mEventData;
159 mImpl->mEventData = NULL;
161 // Nothing else to do.
165 if( NULL == mImpl->mEventData )
167 mImpl->mEventData = new EventData( decorator, inputMethodContext );
171 void Controller::SetGlyphType( TextAbstraction::GlyphType glyphType )
173 // Metrics for bitmap & vector based glyphs are different
174 mImpl->mMetrics->SetGlyphType( glyphType );
176 // Clear the font-specific data
179 mImpl->RequestRelayout();
182 void Controller::SetMarkupProcessorEnabled( bool enable )
184 if( enable != mImpl->mMarkupProcessorEnabled )
186 //If Text was already set, call the SetText again for enabling or disabling markup
187 mImpl->mMarkupProcessorEnabled = enable;
194 bool Controller::IsMarkupProcessorEnabled() const
196 return mImpl->mMarkupProcessorEnabled;
199 void Controller::SetAutoScrollEnabled( bool enable )
201 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 );
203 if( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX )
207 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled for SINGLE_LINE_BOX\n" );
208 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
218 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled Disabling autoscroll\n");
219 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
226 mImpl->mIsAutoScrollEnabled = enable;
227 mImpl->RequestRelayout();
231 DALI_LOG_WARNING( "Attempted AutoScrolling on a non SINGLE_LINE_BOX, request ignored\n" );
232 mImpl->mIsAutoScrollEnabled = false;
236 bool Controller::IsAutoScrollEnabled() const
238 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::IsAutoScrollEnabled[%s]\n", mImpl->mIsAutoScrollEnabled?"true":"false" );
240 return mImpl->mIsAutoScrollEnabled;
243 CharacterDirection Controller::GetAutoScrollDirection() const
245 return mImpl->mIsTextDirectionRTL;
248 float Controller::GetAutoScrollLineAlignment() const
252 if( mImpl->mModel->mVisualModel &&
253 ( 0u != mImpl->mModel->mVisualModel->mLines.Count() ) )
255 offset = ( *mImpl->mModel->mVisualModel->mLines.Begin() ).alignmentOffset;
261 void Controller::SetHorizontalScrollEnabled( bool enable )
263 if( ( NULL != mImpl->mEventData ) &&
264 mImpl->mEventData->mDecorator )
266 mImpl->mEventData->mDecorator->SetHorizontalScrollEnabled( enable );
269 bool Controller::IsHorizontalScrollEnabled() const
271 if( ( NULL != mImpl->mEventData ) &&
272 mImpl->mEventData->mDecorator )
274 return mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
280 void Controller::SetVerticalScrollEnabled( bool enable )
282 if( ( NULL != mImpl->mEventData ) &&
283 mImpl->mEventData->mDecorator )
285 if( mImpl->mEventData->mDecorator )
287 mImpl->mEventData->mDecorator->SetVerticalScrollEnabled( enable );
292 bool Controller::IsVerticalScrollEnabled() const
294 if( ( NULL != mImpl->mEventData ) &&
295 mImpl->mEventData->mDecorator )
297 return mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
303 void Controller::SetSmoothHandlePanEnabled( bool enable )
305 if( ( NULL != mImpl->mEventData ) &&
306 mImpl->mEventData->mDecorator )
308 mImpl->mEventData->mDecorator->SetSmoothHandlePanEnabled( enable );
312 bool Controller::IsSmoothHandlePanEnabled() const
314 if( ( NULL != mImpl->mEventData ) &&
315 mImpl->mEventData->mDecorator )
317 return mImpl->mEventData->mDecorator->IsSmoothHandlePanEnabled();
323 void Controller::SetMaximumNumberOfCharacters( Length maxCharacters )
325 mImpl->mMaximumNumberOfCharacters = std::min( maxCharacters, MAX_TEXT_LENGTH );
328 int Controller::GetMaximumNumberOfCharacters()
330 return mImpl->mMaximumNumberOfCharacters;
333 void Controller::SetEnableCursorBlink( bool enable )
335 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "TextInput disabled" );
337 if( NULL != mImpl->mEventData )
339 mImpl->mEventData->mCursorBlinkEnabled = enable;
342 mImpl->mEventData->mDecorator )
344 mImpl->mEventData->mDecorator->StopCursorBlink();
349 bool Controller::GetEnableCursorBlink() const
351 if( NULL != mImpl->mEventData )
353 return mImpl->mEventData->mCursorBlinkEnabled;
359 void Controller::SetMultiLineEnabled( bool enable )
361 const Layout::Engine::Type layout = enable ? Layout::Engine::MULTI_LINE_BOX : Layout::Engine::SINGLE_LINE_BOX;
363 if( layout != mImpl->mLayoutEngine.GetLayout() )
365 // Set the layout type.
366 mImpl->mLayoutEngine.SetLayout( layout );
368 // Set the flags to redo the layout operations
369 const OperationsMask layoutOperations = static_cast<OperationsMask>( LAYOUT |
374 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
375 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | layoutOperations );
377 // Need to recalculate natural size
378 mImpl->mRecalculateNaturalSize = true;
380 mImpl->RequestRelayout();
384 bool Controller::IsMultiLineEnabled() const
386 return Layout::Engine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
389 void Controller::SetHorizontalAlignment( Text::HorizontalAlignment::Type alignment )
391 if( alignment != mImpl->mModel->mHorizontalAlignment )
393 // Set the alignment.
394 mImpl->mModel->mHorizontalAlignment = alignment;
396 // Set the flag to redo the alignment operation.
397 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
399 if( mImpl->mEventData )
401 mImpl->mEventData->mUpdateAlignment = true;
404 mImpl->RequestRelayout();
408 Text::HorizontalAlignment::Type Controller::GetHorizontalAlignment() const
410 return mImpl->mModel->mHorizontalAlignment;
413 void Controller::SetVerticalAlignment( VerticalAlignment::Type alignment )
415 if( alignment != mImpl->mModel->mVerticalAlignment )
417 // Set the alignment.
418 mImpl->mModel->mVerticalAlignment = alignment;
420 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
422 mImpl->RequestRelayout();
426 VerticalAlignment::Type Controller::GetVerticalAlignment() const
428 return mImpl->mModel->mVerticalAlignment;
431 bool Controller::IsIgnoreSpacesAfterText() const
433 return mImpl->mModel->mIgnoreSpacesAfterText;
436 void Controller::SetIgnoreSpacesAfterText( bool ignore )
438 mImpl->mModel->mIgnoreSpacesAfterText = ignore;
441 bool Controller::IsMatchSystemLanguageDirection() const
443 return mImpl->mModel->mMatchSystemLanguageDirection;
446 void Controller::SetMatchSystemLanguageDirection( bool match )
448 mImpl->mModel->mMatchSystemLanguageDirection = match;
451 void Controller::SetLayoutDirection( Dali::LayoutDirection::Type layoutDirection )
453 mImpl->mLayoutDirection = layoutDirection;
456 bool Controller::IsShowingRealText() const
458 return mImpl->IsShowingRealText();
462 void Controller::SetLineWrapMode( Text::LineWrap::Mode lineWrapMode )
464 if( lineWrapMode != mImpl->mModel->mLineWrapMode )
466 // Set the text wrap mode.
467 mImpl->mModel->mLineWrapMode = lineWrapMode;
470 // Update Text layout for applying wrap mode
471 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
476 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
477 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
478 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
481 mImpl->RequestRelayout();
485 Text::LineWrap::Mode Controller::GetLineWrapMode() const
487 return mImpl->mModel->mLineWrapMode;
490 void Controller::SetTextElideEnabled( bool enabled )
492 mImpl->mModel->mElideEnabled = enabled;
495 bool Controller::IsTextElideEnabled() const
497 return mImpl->mModel->mElideEnabled;
500 void Controller::SetTextFitEnabled(bool enabled)
502 mImpl->mTextFitEnabled = enabled;
505 bool Controller::IsTextFitEnabled() const
507 return mImpl->mTextFitEnabled;
510 void Controller::SetTextFitMinSize( float minSize, FontSizeType type )
516 mImpl->mTextFitMinSize = minSize;
521 mImpl->mTextFitMinSize = ConvertPixelToPint( minSize );
527 float Controller::GetTextFitMinSize() const
529 return mImpl->mTextFitMinSize;
532 void Controller::SetTextFitMaxSize( float maxSize, FontSizeType type )
538 mImpl->mTextFitMaxSize = maxSize;
543 mImpl->mTextFitMaxSize = ConvertPixelToPint( maxSize );
549 float Controller::GetTextFitMaxSize() const
551 return mImpl->mTextFitMaxSize;
554 void Controller::SetTextFitStepSize( float step, FontSizeType type )
560 mImpl->mTextFitStepSize = step;
565 mImpl->mTextFitStepSize = ConvertPixelToPint( step );
571 float Controller::GetTextFitStepSize() const
573 return mImpl->mTextFitStepSize;
576 void Controller::SetTextFitContentSize(Vector2 size)
578 mImpl->mTextFitContentSize = size;
581 Vector2 Controller::GetTextFitContentSize() const
583 return mImpl->mTextFitContentSize;
586 void Controller::SetPlaceholderTextElideEnabled( bool enabled )
588 mImpl->mEventData->mIsPlaceholderElideEnabled = enabled;
589 mImpl->mEventData->mPlaceholderEllipsisFlag = true;
591 // Update placeholder if there is no text
592 if( mImpl->IsShowingPlaceholderText() ||
593 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
595 ShowPlaceholderText();
599 bool Controller::IsPlaceholderTextElideEnabled() const
601 return mImpl->mEventData->mIsPlaceholderElideEnabled;
604 void Controller::SetSelectionEnabled( bool enabled )
606 mImpl->mEventData->mSelectionEnabled = enabled;
609 bool Controller::IsSelectionEnabled() const
611 return mImpl->mEventData->mSelectionEnabled;
614 void Controller::SetShiftSelectionEnabled( bool enabled )
616 mImpl->mEventData->mShiftSelectionFlag = enabled;
619 bool Controller::IsShiftSelectionEnabled() const
621 return mImpl->mEventData->mShiftSelectionFlag;
624 void Controller::SetGrabHandleEnabled( bool enabled )
626 mImpl->mEventData->mGrabHandleEnabled = enabled;
629 bool Controller::IsGrabHandleEnabled() const
631 return mImpl->mEventData->mGrabHandleEnabled;
634 void Controller::SetGrabHandlePopupEnabled(bool enabled)
636 mImpl->mEventData->mGrabHandlePopupEnabled = enabled;
639 bool Controller::IsGrabHandlePopupEnabled() const
641 return mImpl->mEventData->mGrabHandlePopupEnabled;
646 void Controller::SetText( const std::string& text )
648 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" );
650 // Reset keyboard as text changed
651 mImpl->ResetInputMethodContext();
653 // Remove the previously set text and style.
659 CharacterIndex lastCursorIndex = 0u;
661 if( NULL != mImpl->mEventData )
663 // If popup shown then hide it by switching to Editing state
664 if( ( EventData::SELECTING == mImpl->mEventData->mState ) ||
665 ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
666 ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) ||
667 ( EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState ) )
669 mImpl->ChangeState( EventData::EDITING );
675 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mTextColor );
677 MarkupProcessData markupProcessData( mImpl->mModel->mLogicalModel->mColorRuns,
678 mImpl->mModel->mLogicalModel->mFontDescriptionRuns,
679 mImpl->mModel->mLogicalModel->mEmbeddedItems );
681 Length textSize = 0u;
682 const uint8_t* utf8 = NULL;
683 if( mImpl->mMarkupProcessorEnabled )
685 ProcessMarkupString( text, markupProcessData );
686 textSize = markupProcessData.markupProcessedText.size();
688 // This is a bit horrible but std::string returns a (signed) char*
689 utf8 = reinterpret_cast<const uint8_t*>( markupProcessData.markupProcessedText.c_str() );
693 textSize = text.size();
695 // This is a bit horrible but std::string returns a (signed) char*
696 utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
699 // Limit the text size. If the text size is too large, crash or deadlock will occur.
700 if( textSize > MAX_TEXT_LENGTH )
702 DALI_LOG_WARNING( "The text size is too large(%d), limit the length to 32,768u\n", textSize );
703 textSize = MAX_TEXT_LENGTH;
706 // Convert text into UTF-32
707 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
708 utf32Characters.Resize( textSize );
710 // Transform a text array encoded in utf8 into an array encoded in utf32.
711 // It returns the actual number of characters.
712 Length characterCount = Utf8ToUtf32( utf8, textSize, utf32Characters.Begin() );
713 utf32Characters.Resize( characterCount );
715 DALI_ASSERT_DEBUG( textSize >= characterCount && "Invalid UTF32 conversion length" );
716 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", this, textSize, mImpl->mModel->mLogicalModel->mText.Count() );
718 // The characters to be added.
719 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
721 // To reset the cursor position
722 lastCursorIndex = characterCount;
724 // Update the rest of the model during size negotiation
725 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
727 // The natural size needs to be re-calculated.
728 mImpl->mRecalculateNaturalSize = true;
730 // The text direction needs to be updated.
731 mImpl->mUpdateTextDirection = true;
733 // Apply modifications to the model
734 mImpl->mOperationsPending = ALL_OPERATIONS;
738 ShowPlaceholderText();
741 // Resets the cursor position.
742 ResetCursorPosition( lastCursorIndex );
744 // Scrolls the text to make the cursor visible.
745 ResetScrollPosition();
747 mImpl->RequestRelayout();
749 if( NULL != mImpl->mEventData )
751 // Cancel previously queued events
752 mImpl->mEventData->mEventQueue.clear();
755 // Do this last since it provides callbacks into application code.
756 if( NULL != mImpl->mEditableControlInterface )
758 mImpl->mEditableControlInterface->TextChanged();
762 void Controller::GetText( std::string& text ) const
764 if( !mImpl->IsShowingPlaceholderText() )
766 // Retrieves the text string.
767 mImpl->GetText( 0u, text );
771 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this );
775 void Controller::SetPlaceholderText( PlaceholderType type, const std::string& text )
777 if( NULL != mImpl->mEventData )
779 if( PLACEHOLDER_TYPE_INACTIVE == type )
781 mImpl->mEventData->mPlaceholderTextInactive = text;
785 mImpl->mEventData->mPlaceholderTextActive = text;
788 // Update placeholder if there is no text
789 if( mImpl->IsShowingPlaceholderText() ||
790 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
792 ShowPlaceholderText();
797 void Controller::GetPlaceholderText( PlaceholderType type, std::string& text ) const
799 if( NULL != mImpl->mEventData )
801 if( PLACEHOLDER_TYPE_INACTIVE == type )
803 text = mImpl->mEventData->mPlaceholderTextInactive;
807 text = mImpl->mEventData->mPlaceholderTextActive;
812 void Controller::UpdateAfterFontChange( const std::string& newDefaultFont )
814 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
816 if( !mImpl->mFontDefaults->familyDefined ) // If user defined font then should not update when system font changes
818 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
819 mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
823 mImpl->RequestRelayout();
827 // public : Default style & Input style
829 void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
831 if( NULL == mImpl->mFontDefaults )
833 mImpl->mFontDefaults = new FontDefaults();
836 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
837 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
838 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
840 // Clear the font-specific data
843 mImpl->RequestRelayout();
846 const std::string& Controller::GetDefaultFontFamily() const
848 if( NULL != mImpl->mFontDefaults )
850 return mImpl->mFontDefaults->mFontDescription.family;
856 void Controller::SetPlaceholderFontFamily( const std::string& placeholderTextFontFamily )
858 if( NULL != mImpl->mEventData )
860 if( NULL == mImpl->mEventData->mPlaceholderFont )
862 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
865 mImpl->mEventData->mPlaceholderFont->mFontDescription.family = placeholderTextFontFamily;
866 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetPlaceholderFontFamily %s\n", placeholderTextFontFamily.c_str());
867 mImpl->mEventData->mPlaceholderFont->familyDefined = !placeholderTextFontFamily.empty();
869 mImpl->RequestRelayout();
873 const std::string& Controller::GetPlaceholderFontFamily() const
875 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
877 return mImpl->mEventData->mPlaceholderFont->mFontDescription.family;
883 void Controller::SetDefaultFontWeight( FontWeight weight )
885 if( NULL == mImpl->mFontDefaults )
887 mImpl->mFontDefaults = new FontDefaults();
890 mImpl->mFontDefaults->mFontDescription.weight = weight;
891 mImpl->mFontDefaults->weightDefined = true;
893 // Clear the font-specific data
896 mImpl->RequestRelayout();
899 bool Controller::IsDefaultFontWeightDefined() const
901 if( NULL != mImpl->mFontDefaults )
903 return mImpl->mFontDefaults->weightDefined;
909 FontWeight Controller::GetDefaultFontWeight() const
911 if( NULL != mImpl->mFontDefaults )
913 return mImpl->mFontDefaults->mFontDescription.weight;
916 return TextAbstraction::FontWeight::NORMAL;
919 void Controller::SetPlaceholderTextFontWeight( FontWeight weight )
921 if( NULL != mImpl->mEventData )
923 if( NULL == mImpl->mEventData->mPlaceholderFont )
925 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
928 mImpl->mEventData->mPlaceholderFont->mFontDescription.weight = weight;
929 mImpl->mEventData->mPlaceholderFont->weightDefined = true;
931 mImpl->RequestRelayout();
935 bool Controller::IsPlaceholderTextFontWeightDefined() const
937 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
939 return mImpl->mEventData->mPlaceholderFont->weightDefined;
944 FontWeight Controller::GetPlaceholderTextFontWeight() const
946 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
948 return mImpl->mEventData->mPlaceholderFont->mFontDescription.weight;
951 return TextAbstraction::FontWeight::NORMAL;
954 void Controller::SetDefaultFontWidth( FontWidth width )
956 if( NULL == mImpl->mFontDefaults )
958 mImpl->mFontDefaults = new FontDefaults();
961 mImpl->mFontDefaults->mFontDescription.width = width;
962 mImpl->mFontDefaults->widthDefined = true;
964 // Clear the font-specific data
967 mImpl->RequestRelayout();
970 bool Controller::IsDefaultFontWidthDefined() const
972 if( NULL != mImpl->mFontDefaults )
974 return mImpl->mFontDefaults->widthDefined;
980 FontWidth Controller::GetDefaultFontWidth() const
982 if( NULL != mImpl->mFontDefaults )
984 return mImpl->mFontDefaults->mFontDescription.width;
987 return TextAbstraction::FontWidth::NORMAL;
990 void Controller::SetPlaceholderTextFontWidth( FontWidth width )
992 if( NULL != mImpl->mEventData )
994 if( NULL == mImpl->mEventData->mPlaceholderFont )
996 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
999 mImpl->mEventData->mPlaceholderFont->mFontDescription.width = width;
1000 mImpl->mEventData->mPlaceholderFont->widthDefined = true;
1002 mImpl->RequestRelayout();
1006 bool Controller::IsPlaceholderTextFontWidthDefined() const
1008 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1010 return mImpl->mEventData->mPlaceholderFont->widthDefined;
1015 FontWidth Controller::GetPlaceholderTextFontWidth() const
1017 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1019 return mImpl->mEventData->mPlaceholderFont->mFontDescription.width;
1022 return TextAbstraction::FontWidth::NORMAL;
1025 void Controller::SetDefaultFontSlant( FontSlant slant )
1027 if( NULL == mImpl->mFontDefaults )
1029 mImpl->mFontDefaults = new FontDefaults();
1032 mImpl->mFontDefaults->mFontDescription.slant = slant;
1033 mImpl->mFontDefaults->slantDefined = true;
1035 // Clear the font-specific data
1038 mImpl->RequestRelayout();
1041 bool Controller::IsDefaultFontSlantDefined() const
1043 if( NULL != mImpl->mFontDefaults )
1045 return mImpl->mFontDefaults->slantDefined;
1050 FontSlant Controller::GetDefaultFontSlant() const
1052 if( NULL != mImpl->mFontDefaults )
1054 return mImpl->mFontDefaults->mFontDescription.slant;
1057 return TextAbstraction::FontSlant::NORMAL;
1060 void Controller::SetPlaceholderTextFontSlant( FontSlant slant )
1062 if( NULL != mImpl->mEventData )
1064 if( NULL == mImpl->mEventData->mPlaceholderFont )
1066 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
1069 mImpl->mEventData->mPlaceholderFont->mFontDescription.slant = slant;
1070 mImpl->mEventData->mPlaceholderFont->slantDefined = true;
1072 mImpl->RequestRelayout();
1076 bool Controller::IsPlaceholderTextFontSlantDefined() const
1078 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1080 return mImpl->mEventData->mPlaceholderFont->slantDefined;
1085 FontSlant Controller::GetPlaceholderTextFontSlant() const
1087 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1089 return mImpl->mEventData->mPlaceholderFont->mFontDescription.slant;
1092 return TextAbstraction::FontSlant::NORMAL;
1095 void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
1097 if( NULL == mImpl->mFontDefaults )
1099 mImpl->mFontDefaults = new FontDefaults();
1106 mImpl->mFontDefaults->mDefaultPointSize = fontSize;
1107 mImpl->mFontDefaults->sizeDefined = true;
1112 // Point size = Pixel size * 72.f / DPI
1113 unsigned int horizontalDpi = 0u;
1114 unsigned int verticalDpi = 0u;
1115 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1116 fontClient.GetDpi( horizontalDpi, verticalDpi );
1118 mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
1119 mImpl->mFontDefaults->sizeDefined = true;
1124 // Clear the font-specific data
1127 mImpl->RequestRelayout();
1130 float Controller::GetDefaultFontSize( FontSizeType type ) const
1133 if( NULL != mImpl->mFontDefaults )
1139 value = mImpl->mFontDefaults->mDefaultPointSize;
1144 // Pixel size = Point size * DPI / 72.f
1145 unsigned int horizontalDpi = 0u;
1146 unsigned int verticalDpi = 0u;
1147 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1148 fontClient.GetDpi( horizontalDpi, verticalDpi );
1150 value = mImpl->mFontDefaults->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1160 void Controller::SetPlaceholderTextFontSize( float fontSize, FontSizeType type )
1162 if( NULL != mImpl->mEventData )
1164 if( NULL == mImpl->mEventData->mPlaceholderFont )
1166 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
1173 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = fontSize;
1174 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1175 mImpl->mEventData->mIsPlaceholderPixelSize = false; // Font size flag
1180 // Point size = Pixel size * 72.f / DPI
1181 unsigned int horizontalDpi = 0u;
1182 unsigned int verticalDpi = 0u;
1183 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1184 fontClient.GetDpi( horizontalDpi, verticalDpi );
1186 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
1187 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1188 mImpl->mEventData->mIsPlaceholderPixelSize = true; // Font size flag
1193 mImpl->RequestRelayout();
1197 float Controller::GetPlaceholderTextFontSize( FontSizeType type ) const
1200 if( NULL != mImpl->mEventData )
1206 if( NULL != mImpl->mEventData->mPlaceholderFont )
1208 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize;
1212 // If the placeholder text font size is not set, then return the default font size.
1213 value = GetDefaultFontSize( POINT_SIZE );
1219 if( NULL != mImpl->mEventData->mPlaceholderFont )
1221 // Pixel size = Point size * DPI / 72.f
1222 unsigned int horizontalDpi = 0u;
1223 unsigned int verticalDpi = 0u;
1224 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1225 fontClient.GetDpi( horizontalDpi, verticalDpi );
1227 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1231 // If the placeholder text font size is not set, then return the default font size.
1232 value = GetDefaultFontSize( PIXEL_SIZE );
1243 void Controller::SetDefaultColor( const Vector4& color )
1245 mImpl->mTextColor = color;
1247 if( !mImpl->IsShowingPlaceholderText() )
1249 mImpl->mModel->mVisualModel->SetTextColor( color );
1251 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
1253 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1255 mImpl->RequestRelayout();
1259 const Vector4& Controller::GetDefaultColor() const
1261 return mImpl->mTextColor;
1264 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
1266 if( NULL != mImpl->mEventData )
1268 mImpl->mEventData->mPlaceholderTextColor = textColor;
1271 if( mImpl->IsShowingPlaceholderText() )
1273 mImpl->mModel->mVisualModel->SetTextColor( textColor );
1274 mImpl->RequestRelayout();
1278 const Vector4& Controller::GetPlaceholderTextColor() const
1280 if( NULL != mImpl->mEventData )
1282 return mImpl->mEventData->mPlaceholderTextColor;
1285 return Color::BLACK;
1288 void Controller::SetShadowOffset( const Vector2& shadowOffset )
1290 mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
1292 mImpl->RequestRelayout();
1295 const Vector2& Controller::GetShadowOffset() const
1297 return mImpl->mModel->mVisualModel->GetShadowOffset();
1300 void Controller::SetShadowColor( const Vector4& shadowColor )
1302 mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
1304 mImpl->RequestRelayout();
1307 const Vector4& Controller::GetShadowColor() const
1309 return mImpl->mModel->mVisualModel->GetShadowColor();
1312 void Controller::SetShadowBlurRadius( const float& shadowBlurRadius )
1314 if ( fabsf( GetShadowBlurRadius() - shadowBlurRadius ) > Math::MACHINE_EPSILON_1 )
1316 mImpl->mModel->mVisualModel->SetShadowBlurRadius( shadowBlurRadius );
1318 mImpl->RequestRelayout();
1322 const float& Controller::GetShadowBlurRadius() const
1324 return mImpl->mModel->mVisualModel->GetShadowBlurRadius();
1327 void Controller::SetUnderlineColor( const Vector4& color )
1329 mImpl->mModel->mVisualModel->SetUnderlineColor( color );
1331 mImpl->RequestRelayout();
1334 const Vector4& Controller::GetUnderlineColor() const
1336 return mImpl->mModel->mVisualModel->GetUnderlineColor();
1339 void Controller::SetUnderlineEnabled( bool enabled )
1341 mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
1343 mImpl->RequestRelayout();
1346 bool Controller::IsUnderlineEnabled() const
1348 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
1351 void Controller::SetUnderlineHeight( float height )
1353 mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
1355 mImpl->RequestRelayout();
1358 float Controller::GetUnderlineHeight() const
1360 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
1363 void Controller::SetOutlineColor( const Vector4& color )
1365 mImpl->mModel->mVisualModel->SetOutlineColor( color );
1367 mImpl->RequestRelayout();
1370 const Vector4& Controller::GetOutlineColor() const
1372 return mImpl->mModel->mVisualModel->GetOutlineColor();
1375 void Controller::SetOutlineWidth( uint16_t width )
1377 mImpl->mModel->mVisualModel->SetOutlineWidth( width );
1379 mImpl->RequestRelayout();
1382 uint16_t Controller::GetOutlineWidth() const
1384 return mImpl->mModel->mVisualModel->GetOutlineWidth();
1387 void Controller::SetBackgroundColor( const Vector4& color )
1389 mImpl->mModel->mVisualModel->SetBackgroundColor( color );
1391 mImpl->RequestRelayout();
1394 const Vector4& Controller::GetBackgroundColor() const
1396 return mImpl->mModel->mVisualModel->GetBackgroundColor();
1399 void Controller::SetBackgroundEnabled( bool enabled )
1401 mImpl->mModel->mVisualModel->SetBackgroundEnabled( enabled );
1403 mImpl->RequestRelayout();
1406 bool Controller::IsBackgroundEnabled() const
1408 return mImpl->mModel->mVisualModel->IsBackgroundEnabled();
1411 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
1413 if( NULL == mImpl->mEmbossDefaults )
1415 mImpl->mEmbossDefaults = new EmbossDefaults();
1418 mImpl->mEmbossDefaults->properties = embossProperties;
1421 const std::string& Controller::GetDefaultEmbossProperties() const
1423 if( NULL != mImpl->mEmbossDefaults )
1425 return mImpl->mEmbossDefaults->properties;
1428 return EMPTY_STRING;
1431 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
1433 if( NULL == mImpl->mOutlineDefaults )
1435 mImpl->mOutlineDefaults = new OutlineDefaults();
1438 mImpl->mOutlineDefaults->properties = outlineProperties;
1441 const std::string& Controller::GetDefaultOutlineProperties() const
1443 if( NULL != mImpl->mOutlineDefaults )
1445 return mImpl->mOutlineDefaults->properties;
1448 return EMPTY_STRING;
1451 bool Controller::SetDefaultLineSpacing( float lineSpacing )
1453 if( std::fabs( lineSpacing - mImpl->mLayoutEngine.GetDefaultLineSpacing() ) > Math::MACHINE_EPSILON_1000 )
1455 mImpl->mLayoutEngine.SetDefaultLineSpacing(lineSpacing);
1456 mImpl->mRecalculateNaturalSize = true;
1462 float Controller::GetDefaultLineSpacing() const
1464 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
1467 void Controller::SetInputColor( const Vector4& color )
1469 if( NULL != mImpl->mEventData )
1471 mImpl->mEventData->mInputStyle.textColor = color;
1472 mImpl->mEventData->mInputStyle.isDefaultColor = false;
1474 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1476 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
1478 // Get start and end position of selection
1479 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
1480 const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
1482 // Add the color run.
1483 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1484 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
1486 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
1487 colorRun.color = color;
1488 colorRun.characterRun.characterIndex = startOfSelectedText;
1489 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1491 // Request to relayout.
1492 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1493 mImpl->RequestRelayout();
1495 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1496 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1497 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1502 const Vector4& Controller::GetInputColor() const
1504 if( NULL != mImpl->mEventData )
1506 return mImpl->mEventData->mInputStyle.textColor;
1509 // Return the default text's color if there is no EventData.
1510 return mImpl->mTextColor;
1514 void Controller::SetInputFontFamily( const std::string& fontFamily )
1516 if( NULL != mImpl->mEventData )
1518 mImpl->mEventData->mInputStyle.familyName = fontFamily;
1519 mImpl->mEventData->mInputStyle.isFamilyDefined = true;
1521 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1523 CharacterIndex startOfSelectedText = 0u;
1524 Length lengthOfSelectedText = 0u;
1525 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1526 mImpl->mModel->mLogicalModel,
1527 startOfSelectedText,
1528 lengthOfSelectedText );
1530 fontDescriptionRun.familyLength = fontFamily.size();
1531 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
1532 memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength );
1533 fontDescriptionRun.familyDefined = true;
1535 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
1537 // Request to relayout.
1538 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1543 UPDATE_LAYOUT_SIZE |
1546 mImpl->mRecalculateNaturalSize = true;
1547 mImpl->RequestRelayout();
1549 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1550 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1551 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1553 // As the font changes, recalculate the handle positions is needed.
1554 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1555 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1556 mImpl->mEventData->mUpdateHighlightBox = true;
1557 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1562 const std::string& Controller::GetInputFontFamily() const
1564 if( NULL != mImpl->mEventData )
1566 return mImpl->mEventData->mInputStyle.familyName;
1569 // Return the default font's family if there is no EventData.
1570 return GetDefaultFontFamily();
1573 void Controller::SetInputFontWeight( FontWeight weight )
1575 if( NULL != mImpl->mEventData )
1577 mImpl->mEventData->mInputStyle.weight = weight;
1578 mImpl->mEventData->mInputStyle.isWeightDefined = true;
1580 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1582 CharacterIndex startOfSelectedText = 0u;
1583 Length lengthOfSelectedText = 0u;
1584 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1585 mImpl->mModel->mLogicalModel,
1586 startOfSelectedText,
1587 lengthOfSelectedText );
1589 fontDescriptionRun.weight = weight;
1590 fontDescriptionRun.weightDefined = true;
1592 // Request to relayout.
1593 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1598 UPDATE_LAYOUT_SIZE |
1601 mImpl->mRecalculateNaturalSize = true;
1602 mImpl->RequestRelayout();
1604 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1605 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1606 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1608 // As the font might change, recalculate the handle positions is needed.
1609 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1610 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1611 mImpl->mEventData->mUpdateHighlightBox = true;
1612 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1617 bool Controller::IsInputFontWeightDefined() const
1619 bool defined = false;
1621 if( NULL != mImpl->mEventData )
1623 defined = mImpl->mEventData->mInputStyle.isWeightDefined;
1629 FontWeight Controller::GetInputFontWeight() const
1631 if( NULL != mImpl->mEventData )
1633 return mImpl->mEventData->mInputStyle.weight;
1636 return GetDefaultFontWeight();
1639 void Controller::SetInputFontWidth( FontWidth width )
1641 if( NULL != mImpl->mEventData )
1643 mImpl->mEventData->mInputStyle.width = width;
1644 mImpl->mEventData->mInputStyle.isWidthDefined = true;
1646 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1648 CharacterIndex startOfSelectedText = 0u;
1649 Length lengthOfSelectedText = 0u;
1650 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1651 mImpl->mModel->mLogicalModel,
1652 startOfSelectedText,
1653 lengthOfSelectedText );
1655 fontDescriptionRun.width = width;
1656 fontDescriptionRun.widthDefined = true;
1658 // Request to relayout.
1659 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1664 UPDATE_LAYOUT_SIZE |
1667 mImpl->mRecalculateNaturalSize = true;
1668 mImpl->RequestRelayout();
1670 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1671 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1672 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1674 // As the font might change, recalculate the handle positions is needed.
1675 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1676 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1677 mImpl->mEventData->mUpdateHighlightBox = true;
1678 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1683 bool Controller::IsInputFontWidthDefined() const
1685 bool defined = false;
1687 if( NULL != mImpl->mEventData )
1689 defined = mImpl->mEventData->mInputStyle.isWidthDefined;
1695 FontWidth Controller::GetInputFontWidth() const
1697 if( NULL != mImpl->mEventData )
1699 return mImpl->mEventData->mInputStyle.width;
1702 return GetDefaultFontWidth();
1705 void Controller::SetInputFontSlant( FontSlant slant )
1707 if( NULL != mImpl->mEventData )
1709 mImpl->mEventData->mInputStyle.slant = slant;
1710 mImpl->mEventData->mInputStyle.isSlantDefined = true;
1712 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1714 CharacterIndex startOfSelectedText = 0u;
1715 Length lengthOfSelectedText = 0u;
1716 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1717 mImpl->mModel->mLogicalModel,
1718 startOfSelectedText,
1719 lengthOfSelectedText );
1721 fontDescriptionRun.slant = slant;
1722 fontDescriptionRun.slantDefined = true;
1724 // Request to relayout.
1725 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1730 UPDATE_LAYOUT_SIZE |
1733 mImpl->mRecalculateNaturalSize = true;
1734 mImpl->RequestRelayout();
1736 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1737 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1738 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1740 // As the font might change, recalculate the handle positions is needed.
1741 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1742 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1743 mImpl->mEventData->mUpdateHighlightBox = true;
1744 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1749 bool Controller::IsInputFontSlantDefined() const
1751 bool defined = false;
1753 if( NULL != mImpl->mEventData )
1755 defined = mImpl->mEventData->mInputStyle.isSlantDefined;
1761 FontSlant Controller::GetInputFontSlant() const
1763 if( NULL != mImpl->mEventData )
1765 return mImpl->mEventData->mInputStyle.slant;
1768 return GetDefaultFontSlant();
1771 void Controller::SetInputFontPointSize( float size )
1773 if( NULL != mImpl->mEventData )
1775 mImpl->mEventData->mInputStyle.size = size;
1776 mImpl->mEventData->mInputStyle.isSizeDefined = true;
1778 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1780 CharacterIndex startOfSelectedText = 0u;
1781 Length lengthOfSelectedText = 0u;
1782 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1783 mImpl->mModel->mLogicalModel,
1784 startOfSelectedText,
1785 lengthOfSelectedText );
1787 fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
1788 fontDescriptionRun.sizeDefined = true;
1790 // Request to relayout.
1791 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1796 UPDATE_LAYOUT_SIZE |
1799 mImpl->mRecalculateNaturalSize = true;
1800 mImpl->RequestRelayout();
1802 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1803 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1804 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1806 // As the font might change, recalculate the handle positions is needed.
1807 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1808 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1809 mImpl->mEventData->mUpdateHighlightBox = true;
1810 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1815 float Controller::GetInputFontPointSize() const
1817 if( NULL != mImpl->mEventData )
1819 return mImpl->mEventData->mInputStyle.size;
1822 // Return the default font's point size if there is no EventData.
1823 return GetDefaultFontSize( Text::Controller::POINT_SIZE );
1826 void Controller::SetInputLineSpacing( float lineSpacing )
1828 if( NULL != mImpl->mEventData )
1830 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1831 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1835 float Controller::GetInputLineSpacing() const
1837 if( NULL != mImpl->mEventData )
1839 return mImpl->mEventData->mInputStyle.lineSpacing;
1845 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1847 if( NULL != mImpl->mEventData )
1849 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1853 const std::string& Controller::GetInputShadowProperties() const
1855 if( NULL != mImpl->mEventData )
1857 return mImpl->mEventData->mInputStyle.shadowProperties;
1860 return EMPTY_STRING;
1863 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1865 if( NULL != mImpl->mEventData )
1867 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1871 const std::string& Controller::GetInputUnderlineProperties() const
1873 if( NULL != mImpl->mEventData )
1875 return mImpl->mEventData->mInputStyle.underlineProperties;
1878 return EMPTY_STRING;
1881 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
1883 if( NULL != mImpl->mEventData )
1885 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1889 const std::string& Controller::GetInputEmbossProperties() const
1891 if( NULL != mImpl->mEventData )
1893 return mImpl->mEventData->mInputStyle.embossProperties;
1896 return GetDefaultEmbossProperties();
1899 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
1901 if( NULL != mImpl->mEventData )
1903 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1907 const std::string& Controller::GetInputOutlineProperties() const
1909 if( NULL != mImpl->mEventData )
1911 return mImpl->mEventData->mInputStyle.outlineProperties;
1914 return GetDefaultOutlineProperties();
1917 void Controller::SetInputModePassword( bool passwordInput )
1919 if( NULL != mImpl->mEventData )
1921 mImpl->mEventData->mPasswordInput = passwordInput;
1925 bool Controller::IsInputModePassword()
1927 if( NULL != mImpl->mEventData )
1929 return mImpl->mEventData->mPasswordInput;
1934 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
1936 if( NULL != mImpl->mEventData )
1938 mImpl->mEventData->mDoubleTapAction = action;
1942 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1944 NoTextTap::Action action = NoTextTap::NO_ACTION;
1946 if( NULL != mImpl->mEventData )
1948 action = mImpl->mEventData->mDoubleTapAction;
1954 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
1956 if( NULL != mImpl->mEventData )
1958 mImpl->mEventData->mLongPressAction = action;
1962 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1964 NoTextTap::Action action = NoTextTap::NO_ACTION;
1966 if( NULL != mImpl->mEventData )
1968 action = mImpl->mEventData->mLongPressAction;
1974 bool Controller::IsUnderlineSetByString()
1976 return mImpl->mUnderlineSetByString;
1979 void Controller::UnderlineSetByString( bool setByString )
1981 mImpl->mUnderlineSetByString = setByString;
1984 bool Controller::IsShadowSetByString()
1986 return mImpl->mShadowSetByString;
1989 void Controller::ShadowSetByString( bool setByString )
1991 mImpl->mShadowSetByString = setByString;
1994 bool Controller::IsOutlineSetByString()
1996 return mImpl->mOutlineSetByString;
1999 void Controller::OutlineSetByString( bool setByString )
2001 mImpl->mOutlineSetByString = setByString;
2004 bool Controller::IsFontStyleSetByString()
2006 return mImpl->mFontStyleSetByString;
2009 void Controller::FontStyleSetByString( bool setByString )
2011 mImpl->mFontStyleSetByString = setByString;
2014 // public : Queries & retrieves.
2016 Layout::Engine& Controller::GetLayoutEngine()
2018 return mImpl->mLayoutEngine;
2021 View& Controller::GetView()
2023 return mImpl->mView;
2026 Vector3 Controller::GetNaturalSize()
2028 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
2029 Vector3 naturalSize;
2031 // Make sure the model is up-to-date before layouting
2032 ProcessModifyEvents();
2034 if( mImpl->mRecalculateNaturalSize )
2036 // Operations that can be done only once until the text changes.
2037 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2044 GET_GLYPH_METRICS );
2046 // Set the update info to relayout the whole text.
2047 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2048 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2050 // Make sure the model is up-to-date before layouting
2051 mImpl->UpdateModel( onlyOnceOperations );
2053 // Layout the text for the new width.
2054 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT | REORDER );
2056 // Store the actual control's size to restore later.
2057 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
2059 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
2060 static_cast<OperationsMask>( onlyOnceOperations |
2062 naturalSize.GetVectorXY() );
2064 // Do not do again the only once operations.
2065 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2067 // Do the size related operations again.
2068 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
2071 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
2073 // Stores the natural size to avoid recalculate it again
2074 // unless the text/style changes.
2075 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
2077 mImpl->mRecalculateNaturalSize = false;
2079 // Clear the update info. This info will be set the next time the text is updated.
2080 mImpl->mTextUpdateInfo.Clear();
2081 mImpl->mTextUpdateInfo.mClearAll = true;
2083 // Restore the actual control's size.
2084 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
2086 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
2090 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
2092 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
2095 naturalSize.x = ConvertToEven( naturalSize.x );
2096 naturalSize.y = ConvertToEven( naturalSize.y );
2101 bool Controller::CheckForTextFit( float pointSize, Size& layoutSize )
2104 mImpl->mFontDefaults->mFitPointSize = pointSize;
2105 mImpl->mFontDefaults->sizeDefined = true;
2108 // Operations that can be done only once until the text changes.
2109 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2116 GET_GLYPH_METRICS );
2118 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2119 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2121 // Make sure the model is up-to-date before layouting
2122 mImpl->UpdateModel( onlyOnceOperations );
2124 DoRelayout( Size( layoutSize.width, MAX_FLOAT ),
2125 static_cast<OperationsMask>( onlyOnceOperations | LAYOUT),
2128 // Clear the update info. This info will be set the next time the text is updated.
2129 mImpl->mTextUpdateInfo.Clear();
2130 mImpl->mTextUpdateInfo.mClearAll = true;
2132 if( textSize.width > layoutSize.width || textSize.height > layoutSize.height )
2139 void Controller::FitPointSizeforLayout( Size layoutSize )
2141 const OperationsMask operations = mImpl->mOperationsPending;
2142 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
2144 bool actualellipsis = mImpl->mModel->mElideEnabled;
2145 float minPointSize = mImpl->mTextFitMinSize;
2146 float maxPointSize = mImpl->mTextFitMaxSize;
2147 float pointInterval = mImpl->mTextFitStepSize;
2149 mImpl->mModel->mElideEnabled = false;
2150 Vector<float> pointSizeArray;
2153 if( pointInterval < 1.f )
2155 mImpl->mTextFitStepSize = pointInterval = 1.0f;
2158 pointSizeArray.Reserve( static_cast< unsigned int >( ceil( ( maxPointSize - minPointSize ) / pointInterval ) ) );
2160 for( float i = minPointSize; i < maxPointSize; i += pointInterval )
2162 pointSizeArray.PushBack( i );
2165 pointSizeArray.PushBack( maxPointSize );
2167 int bestSizeIndex = 0;
2168 int min = bestSizeIndex + 1;
2169 int max = pointSizeArray.Size() - 1;
2172 int destI = ( min + max ) / 2;
2174 if( CheckForTextFit( pointSizeArray[destI], layoutSize ) )
2176 bestSizeIndex = min;
2182 bestSizeIndex = max;
2186 mImpl->mModel->mElideEnabled = actualellipsis;
2187 mImpl->mFontDefaults->mFitPointSize = pointSizeArray[bestSizeIndex];
2188 mImpl->mFontDefaults->sizeDefined = true;
2193 float Controller::GetHeightForWidth( float width )
2195 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
2196 // Make sure the model is up-to-date before layouting
2197 ProcessModifyEvents();
2200 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ||
2201 mImpl->mTextUpdateInfo.mFullRelayoutNeeded ||
2202 mImpl->mTextUpdateInfo.mClearAll )
2204 // Operations that can be done only once until the text changes.
2205 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2212 GET_GLYPH_METRICS );
2214 // Set the update info to relayout the whole text.
2215 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2216 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2218 // Make sure the model is up-to-date before layouting
2219 mImpl->UpdateModel( onlyOnceOperations );
2222 // Layout the text for the new width.
2223 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
2225 // Store the actual control's width.
2226 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
2228 DoRelayout( Size( width, MAX_FLOAT ),
2229 static_cast<OperationsMask>( onlyOnceOperations |
2233 // Do not do again the only once operations.
2234 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2236 // Do the size related operations again.
2237 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
2241 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
2243 // Clear the update info. This info will be set the next time the text is updated.
2244 mImpl->mTextUpdateInfo.Clear();
2245 mImpl->mTextUpdateInfo.mClearAll = true;
2247 // Restore the actual control's width.
2248 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
2250 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
2254 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
2255 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
2258 return layoutSize.height;
2261 int Controller::GetLineCount( float width )
2263 GetHeightForWidth( width );
2264 int numberofLines = mImpl->mModel->GetNumberOfLines();
2265 return numberofLines;
2268 const ModelInterface* const Controller::GetTextModel() const
2270 return mImpl->mModel.Get();
2273 float Controller::GetScrollAmountByUserInput()
2275 float scrollAmount = 0.0f;
2277 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
2279 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
2280 mImpl->mEventData->mCheckScrollAmount = false;
2282 return scrollAmount;
2285 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
2287 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
2290 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
2291 layoutHeight = layout.height;
2292 scrollPosition = mImpl->mModel->mScrollPosition.y;
2293 isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
2297 void Controller::SetHiddenInputOption(const Property::Map& options )
2299 if( NULL == mImpl->mHiddenInput )
2301 mImpl->mHiddenInput = new HiddenText( this );
2303 mImpl->mHiddenInput->SetProperties(options);
2306 void Controller::GetHiddenInputOption(Property::Map& options )
2308 if( NULL != mImpl->mHiddenInput )
2310 mImpl->mHiddenInput->GetProperties(options);
2314 void Controller::SetPlaceholderProperty( const Property::Map& map )
2316 const Property::Map::SizeType count = map.Count();
2318 for( Property::Map::SizeType position = 0; position < count; ++position )
2320 KeyValuePair keyValue = map.GetKeyValue( position );
2321 Property::Key& key = keyValue.first;
2322 Property::Value& value = keyValue.second;
2324 if( key == Toolkit::Text::PlaceHolder::Property::TEXT || key == PLACEHOLDER_TEXT )
2326 std::string text = "";
2328 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
2330 else if( key == Toolkit::Text::PlaceHolder::Property::TEXT_FOCUSED || key == PLACEHOLDER_TEXT_FOCUSED )
2332 std::string text = "";
2334 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
2336 else if( key == Toolkit::Text::PlaceHolder::Property::COLOR || key == PLACEHOLDER_COLOR )
2339 value.Get( textColor );
2340 if( GetPlaceholderTextColor() != textColor )
2342 SetPlaceholderTextColor( textColor );
2345 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_FAMILY || key == PLACEHOLDER_FONT_FAMILY )
2347 std::string fontFamily = "";
2348 value.Get( fontFamily );
2349 SetPlaceholderFontFamily( fontFamily );
2351 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_STYLE || key == PLACEHOLDER_FONT_STYLE )
2353 SetFontStyleProperty( this, value, Text::FontStyle::PLACEHOLDER );
2355 else if( key == Toolkit::Text::PlaceHolder::Property::POINT_SIZE || key == PLACEHOLDER_POINT_SIZE )
2358 value.Get( pointSize );
2359 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
2361 SetPlaceholderTextFontSize( pointSize, Text::Controller::POINT_SIZE );
2364 else if( key == Toolkit::Text::PlaceHolder::Property::PIXEL_SIZE || key == PLACEHOLDER_PIXEL_SIZE )
2367 value.Get( pixelSize );
2368 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
2370 SetPlaceholderTextFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
2373 else if( key == Toolkit::Text::PlaceHolder::Property::ELLIPSIS || key == PLACEHOLDER_ELLIPSIS )
2376 value.Get( ellipsis );
2377 SetPlaceholderTextElideEnabled( ellipsis );
2382 void Controller::GetPlaceholderProperty( Property::Map& map )
2384 if( NULL != mImpl->mEventData )
2386 if( !mImpl->mEventData->mPlaceholderTextActive.empty() )
2388 map[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = mImpl->mEventData->mPlaceholderTextActive;
2390 if( !mImpl->mEventData->mPlaceholderTextInactive.empty() )
2392 map[ Text::PlaceHolder::Property::TEXT ] = mImpl->mEventData->mPlaceholderTextInactive;
2395 map[ Text::PlaceHolder::Property::COLOR ] = mImpl->mEventData->mPlaceholderTextColor;
2396 map[ Text::PlaceHolder::Property::FONT_FAMILY ] = GetPlaceholderFontFamily();
2398 Property::Value fontStyleMapGet;
2399 GetFontStyleProperty( this, fontStyleMapGet, Text::FontStyle::PLACEHOLDER );
2400 map[ Text::PlaceHolder::Property::FONT_STYLE ] = fontStyleMapGet;
2402 // Choose font size : POINT_SIZE or PIXEL_SIZE
2403 if( !mImpl->mEventData->mIsPlaceholderPixelSize )
2405 map[ Text::PlaceHolder::Property::POINT_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE );
2409 map[ Text::PlaceHolder::Property::PIXEL_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE );
2412 if( mImpl->mEventData->mPlaceholderEllipsisFlag )
2414 map[ Text::PlaceHolder::Property::ELLIPSIS ] = IsPlaceholderTextElideEnabled();
2419 Toolkit::DevelText::TextDirection::Type Controller::GetTextDirection()
2421 // Make sure the model is up-to-date before layouting
2422 ProcessModifyEvents();
2424 if ( mImpl->mUpdateTextDirection )
2426 // Operations that can be done only once until the text changes.
2427 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2434 GET_GLYPH_METRICS );
2436 // Set the update info to relayout the whole text.
2437 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2438 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2440 // Make sure the model is up-to-date before layouting
2441 mImpl->UpdateModel( onlyOnceOperations );
2443 Vector3 naturalSize;
2444 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
2445 static_cast<OperationsMask>( onlyOnceOperations |
2446 LAYOUT | REORDER | UPDATE_DIRECTION ),
2447 naturalSize.GetVectorXY() );
2449 // Do not do again the only once operations.
2450 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2452 // Clear the update info. This info will be set the next time the text is updated.
2453 mImpl->mTextUpdateInfo.Clear();
2455 mImpl->mUpdateTextDirection = false;
2458 return mImpl->mIsTextDirectionRTL ? Toolkit::DevelText::TextDirection::RIGHT_TO_LEFT : Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT;
2461 Toolkit::DevelText::VerticalLineAlignment::Type Controller::GetVerticalLineAlignment() const
2463 return mImpl->mModel->GetVerticalLineAlignment();
2466 void Controller::SetVerticalLineAlignment( Toolkit::DevelText::VerticalLineAlignment::Type alignment )
2468 mImpl->mModel->mVerticalLineAlignment = alignment;
2471 // public : Relayout.
2473 Controller::UpdateTextType Controller::Relayout( const Size& size, Dali::LayoutDirection::Type layoutDirection )
2475 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
2477 UpdateTextType updateTextType = NONE_UPDATED;
2479 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
2481 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
2483 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
2484 updateTextType = MODEL_UPDATED;
2487 // Clear the update info. This info will be set the next time the text is updated.
2488 mImpl->mTextUpdateInfo.Clear();
2490 // Not worth to relayout if width or height is equal to zero.
2491 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
2493 return updateTextType;
2496 // Whether a new size has been set.
2497 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
2501 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
2503 if( ( 0 == mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd ) &&
2504 ( 0 == mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) &&
2505 ( ( mImpl->mModel->mVisualModel->mControlSize.width < Math::MACHINE_EPSILON_1000 ) || ( mImpl->mModel->mVisualModel->mControlSize.height < Math::MACHINE_EPSILON_1000 ) ) )
2507 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
2510 // Layout operations that need to be done if the size changes.
2511 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2514 UPDATE_LAYOUT_SIZE |
2516 // Set the update info to relayout the whole text.
2517 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2518 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2520 // Store the size used to layout the text.
2521 mImpl->mModel->mVisualModel->mControlSize = size;
2524 // Whether there are modify events.
2525 if( 0u != mImpl->mModifyEvents.Count() )
2527 // Style operations that need to be done if the text is modified.
2528 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2532 // Set the update info to elide the text.
2533 if( mImpl->mModel->mElideEnabled ||
2534 ( ( NULL != mImpl->mEventData ) && mImpl->mEventData->mIsPlaceholderElideEnabled ) )
2536 // Update Text layout for applying elided
2537 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2540 UPDATE_LAYOUT_SIZE |
2542 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2543 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2546 if( mImpl->mModel->mMatchSystemLanguageDirection && mImpl->mLayoutDirection != layoutDirection )
2548 // Clear the update info. This info will be set the next time the text is updated.
2549 mImpl->mTextUpdateInfo.mClearAll = true;
2550 // Apply modifications to the model
2551 // Shape the text again is needed because characters like '()[]{}' have to be mirrored and the glyphs generated again.
2552 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2559 mImpl->mLayoutDirection = layoutDirection;
2562 // Make sure the model is up-to-date before layouting.
2563 ProcessModifyEvents();
2564 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
2568 updated = DoRelayout( size,
2569 mImpl->mOperationsPending,
2570 layoutSize ) || updated;
2575 updateTextType = MODEL_UPDATED;
2578 // Do not re-do any operation until something changes.
2579 mImpl->mOperationsPending = NO_OPERATION;
2580 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
2582 // Whether the text control is editable
2583 const bool isEditable = NULL != mImpl->mEventData;
2585 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
2587 if( newSize && isEditable )
2589 offset = mImpl->mModel->mScrollPosition;
2592 if( !isEditable || !IsMultiLineEnabled() )
2594 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
2595 CalculateVerticalOffset( size );
2602 // If there is a new size, the scroll position needs to be clamped.
2603 mImpl->ClampHorizontalScroll( layoutSize );
2605 // Update the decorator's positions is needed if there is a new size.
2606 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
2609 // Move the cursor, grab handle etc.
2610 if( mImpl->ProcessInputEvents() )
2612 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
2616 // Clear the update info. This info will be set the next time the text is updated.
2617 mImpl->mTextUpdateInfo.Clear();
2618 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
2620 return updateTextType;
2623 void Controller::RequestRelayout()
2625 mImpl->RequestRelayout();
2628 // public : Input style change signals.
2630 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
2632 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
2635 void Controller::ProcessInputStyleChangedSignals()
2637 if( NULL == mImpl->mEventData )
2643 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
2644 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
2648 const InputStyle::Mask mask = *it;
2650 if( NULL != mImpl->mEditableControlInterface )
2652 // Emit the input style changed signal.
2653 mImpl->mEditableControlInterface->InputStyleChanged( mask );
2657 mImpl->mEventData->mInputStyleChangedQueue.Clear();
2660 // public : Text-input Event Queuing.
2662 void Controller::KeyboardFocusGainEvent()
2664 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
2666 if( NULL != mImpl->mEventData )
2668 if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
2669 ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
2671 mImpl->ChangeState( EventData::EDITING );
2672 mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
2673 mImpl->mEventData->mUpdateInputStyle = true;
2674 mImpl->mEventData->mScrollAfterUpdatePosition = true;
2676 mImpl->NotifyInputMethodContextMultiLineStatus();
2677 if( mImpl->IsShowingPlaceholderText() )
2679 // Show alternative placeholder-text when editing
2680 ShowPlaceholderText();
2683 mImpl->RequestRelayout();
2687 void Controller::KeyboardFocusLostEvent()
2689 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
2691 if( NULL != mImpl->mEventData )
2693 if( EventData::INTERRUPTED != mImpl->mEventData->mState )
2695 mImpl->ChangeState( EventData::INACTIVE );
2697 if( !mImpl->IsShowingRealText() )
2699 // Revert to regular placeholder-text when not editing
2700 ShowPlaceholderText();
2704 mImpl->RequestRelayout();
2707 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
2709 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
2711 bool textChanged = false;
2712 bool relayoutNeeded = false;
2714 if( ( NULL != mImpl->mEventData ) &&
2715 ( keyEvent.state == KeyEvent::Down ) )
2717 int keyCode = keyEvent.keyCode;
2718 const std::string& keyString = keyEvent.keyPressed;
2719 const std::string keyName = keyEvent.keyPressedName;
2721 const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
2723 // Pre-process to separate modifying events from non-modifying input events.
2726 // In some platforms arrive key events with no key code.
2730 else if( Dali::DALI_KEY_ESCAPE == keyCode || Dali::DALI_KEY_BACK == keyCode || Dali::DALI_KEY_SEARCH == keyCode )
2735 else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) ||
2736 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
2737 ( Dali::DALI_KEY_CURSOR_UP == keyCode ) ||
2738 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) )
2740 // If don't have any text, do nothing.
2741 if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
2746 uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition;
2747 uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2748 uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition );
2749 uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines();
2751 // Logic to determine whether this text control will lose focus or not.
2752 if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2753 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2754 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) ||
2755 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) ||
2756 ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) ||
2757 ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) )
2759 // Release the active highlight.
2760 if( mImpl->mEventData->mState == EventData::SELECTING )
2762 mImpl->ChangeState( EventData::EDITING );
2764 // Update selection position.
2765 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2766 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2767 mImpl->mEventData->mUpdateCursorPosition = true;
2768 mImpl->RequestRelayout();
2773 mImpl->mEventData->mCheckScrollAmount = true;
2774 Event event( Event::CURSOR_KEY_EVENT );
2775 event.p1.mInt = keyCode;
2776 event.p2.mBool = keyEvent.IsShiftModifier();
2777 mImpl->mEventData->mEventQueue.push_back( event );
2779 // Will request for relayout.
2780 relayoutNeeded = true;
2782 else if ( Dali::DevelKey::DALI_KEY_CONTROL_LEFT == keyCode || Dali::DevelKey::DALI_KEY_CONTROL_RIGHT == keyCode )
2784 // Left or Right Control key event is received before Ctrl-C/V/X key event is received
2785 // If not handle it here, any selected text will be deleted
2790 else if ( keyEvent.IsCtrlModifier() )
2792 bool consumed = false;
2793 if (keyName == KEY_C_NAME)
2795 // Ctrl-C to copy the selected text
2796 TextPopupButtonTouched( Toolkit::TextSelectionPopup::COPY );
2799 else if (keyName == KEY_V_NAME)
2801 // Ctrl-V to paste the copied text
2802 TextPopupButtonTouched( Toolkit::TextSelectionPopup::PASTE );
2805 else if (keyName == KEY_X_NAME)
2807 // Ctrl-X to cut the selected text
2808 TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
2813 else if( ( Dali::DALI_KEY_BACKSPACE == keyCode ) ||
2814 ( Dali::DevelKey::DALI_KEY_DELETE == keyCode ) )
2816 textChanged = DeleteEvent( keyCode );
2818 // Will request for relayout.
2819 relayoutNeeded = true;
2821 else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
2822 IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
2823 IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
2825 // Power key/Menu/Home key behaviour does not allow edit mode to resume.
2826 mImpl->ChangeState( EventData::INACTIVE );
2828 // Will request for relayout.
2829 relayoutNeeded = true;
2831 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2833 else if( ( Dali::DALI_KEY_SHIFT_LEFT == keyCode ) || ( Dali::DALI_KEY_SHIFT_RIGHT == keyCode ) )
2835 // DALI_KEY_SHIFT_LEFT or DALI_KEY_SHIFT_RIGHT is the key code for Shift. It's sent (by the InputMethodContext?) when the predictive text is enabled
2836 // and a character is typed after the type of a upper case latin character.
2841 else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
2843 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2849 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
2851 if( !keyString.empty() )
2853 // InputMethodContext is no longer handling key-events
2854 mImpl->ClearPreEditFlag();
2856 InsertText( keyString, COMMIT );
2860 // Will request for relayout.
2861 relayoutNeeded = true;
2866 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
2867 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
2869 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
2870 ( Dali::DALI_KEY_SHIFT_RIGHT != keyCode ) &&
2871 ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
2872 ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
2874 // Should not change the state if the key is the shift send by the InputMethodContext.
2875 // Otherwise, when the state is SELECTING the text controller can't send the right
2876 // surrounding info to the InputMethodContext.
2877 mImpl->ChangeState( EventData::EDITING );
2879 // Will request for relayout.
2880 relayoutNeeded = true;
2883 if( relayoutNeeded )
2885 mImpl->RequestRelayout();
2890 ( NULL != mImpl->mEditableControlInterface ) )
2892 // Do this last since it provides callbacks into application code
2893 mImpl->mEditableControlInterface->TextChanged();
2899 void Controller::TapEvent( unsigned int tapCount, float x, float y )
2901 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
2903 if( NULL != mImpl->mEventData )
2905 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
2906 EventData::State state( mImpl->mEventData->mState );
2907 bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
2909 if( mImpl->IsClipboardVisible() )
2911 if( EventData::INACTIVE == state || EventData::EDITING == state)
2913 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2915 relayoutNeeded = true;
2917 else if( 1u == tapCount )
2919 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
2921 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
2924 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
2926 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2927 relayoutNeeded = true;
2931 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
2933 // Hide placeholder text
2937 if( EventData::INACTIVE == state )
2939 mImpl->ChangeState( EventData::EDITING );
2941 else if( !mImpl->IsClipboardEmpty() )
2943 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
2945 relayoutNeeded = true;
2948 else if( 2u == tapCount )
2950 if( mImpl->mEventData->mSelectionEnabled &&
2951 mImpl->IsShowingRealText() )
2953 relayoutNeeded = true;
2954 mImpl->mEventData->mIsLeftHandleSelected = true;
2955 mImpl->mEventData->mIsRightHandleSelected = true;
2959 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
2960 if( relayoutNeeded )
2962 Event event( Event::TAP_EVENT );
2963 event.p1.mUint = tapCount;
2964 event.p2.mFloat = x;
2965 event.p3.mFloat = y;
2966 mImpl->mEventData->mEventQueue.push_back( event );
2968 mImpl->RequestRelayout();
2972 // Reset keyboard as tap event has occurred.
2973 mImpl->ResetInputMethodContext();
2976 void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
2978 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
2980 if( NULL != mImpl->mEventData )
2982 Event event( Event::PAN_EVENT );
2983 event.p1.mInt = state;
2984 event.p2.mFloat = displacement.x;
2985 event.p3.mFloat = displacement.y;
2986 mImpl->mEventData->mEventQueue.push_back( event );
2988 mImpl->RequestRelayout();
2992 void Controller::LongPressEvent( Gesture::State state, float x, float y )
2994 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
2996 if( ( state == Gesture::Started ) &&
2997 ( NULL != mImpl->mEventData ) )
2999 // The 1st long-press on inactive text-field is treated as tap
3000 if( EventData::INACTIVE == mImpl->mEventData->mState )
3002 mImpl->ChangeState( EventData::EDITING );
3004 Event event( Event::TAP_EVENT );
3006 event.p2.mFloat = x;
3007 event.p3.mFloat = y;
3008 mImpl->mEventData->mEventQueue.push_back( event );
3010 mImpl->RequestRelayout();
3012 else if( !mImpl->IsShowingRealText() )
3014 Event event( Event::LONG_PRESS_EVENT );
3015 event.p1.mInt = state;
3016 event.p2.mFloat = x;
3017 event.p3.mFloat = y;
3018 mImpl->mEventData->mEventQueue.push_back( event );
3019 mImpl->RequestRelayout();
3021 else if( !mImpl->IsClipboardVisible() )
3023 // Reset the InputMethodContext to commit the pre-edit before selecting the text.
3024 mImpl->ResetInputMethodContext();
3026 Event event( Event::LONG_PRESS_EVENT );
3027 event.p1.mInt = state;
3028 event.p2.mFloat = x;
3029 event.p3.mFloat = y;
3030 mImpl->mEventData->mEventQueue.push_back( event );
3031 mImpl->RequestRelayout();
3033 mImpl->mEventData->mIsLeftHandleSelected = true;
3034 mImpl->mEventData->mIsRightHandleSelected = true;
3039 void Controller::SelectEvent( float x, float y, bool selectAll )
3041 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
3043 if( NULL != mImpl->mEventData )
3047 Event event( Event::SELECT_ALL );
3048 mImpl->mEventData->mEventQueue.push_back( event );
3052 Event event( Event::SELECT );
3053 event.p2.mFloat = x;
3054 event.p3.mFloat = y;
3055 mImpl->mEventData->mEventQueue.push_back( event );
3058 mImpl->mEventData->mCheckScrollAmount = true;
3059 mImpl->mEventData->mIsLeftHandleSelected = true;
3060 mImpl->mEventData->mIsRightHandleSelected = true;
3061 mImpl->RequestRelayout();
3065 InputMethodContext::CallbackData Controller::OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
3067 // Whether the text needs to be relaid-out.
3068 bool requestRelayout = false;
3070 // Whether to retrieve the text and cursor position to be sent to the InputMethodContext.
3071 bool retrieveText = false;
3072 bool retrieveCursor = false;
3074 switch( inputMethodContextEvent.eventName )
3076 case InputMethodContext::COMMIT:
3078 InsertText( inputMethodContextEvent.predictiveString, Text::Controller::COMMIT );
3079 requestRelayout = true;
3080 retrieveCursor = true;
3083 case InputMethodContext::PRE_EDIT:
3085 InsertText( inputMethodContextEvent.predictiveString, Text::Controller::PRE_EDIT );
3086 requestRelayout = true;
3087 retrieveCursor = true;
3090 case InputMethodContext::DELETE_SURROUNDING:
3092 const bool textDeleted = RemoveText( inputMethodContextEvent.cursorOffset,
3093 inputMethodContextEvent.numberOfChars,
3094 DONT_UPDATE_INPUT_STYLE );
3098 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3099 !mImpl->IsPlaceholderAvailable() )
3101 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3105 ShowPlaceholderText();
3107 mImpl->mEventData->mUpdateCursorPosition = true;
3108 mImpl->mEventData->mScrollAfterDelete = true;
3110 requestRelayout = true;
3114 case InputMethodContext::GET_SURROUNDING:
3116 retrieveText = true;
3117 retrieveCursor = true;
3120 case InputMethodContext::PRIVATE_COMMAND:
3122 // PRIVATECOMMAND event is just for getting the private command message
3123 retrieveText = true;
3124 retrieveCursor = true;
3127 case InputMethodContext::VOID:
3134 if( requestRelayout )
3136 mImpl->mOperationsPending = ALL_OPERATIONS;
3137 mImpl->RequestRelayout();
3141 CharacterIndex cursorPosition = 0u;
3142 Length numberOfWhiteSpaces = 0u;
3144 if( retrieveCursor )
3146 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
3148 cursorPosition = mImpl->GetLogicalCursorPosition();
3150 if( cursorPosition < numberOfWhiteSpaces )
3152 cursorPosition = 0u;
3156 cursorPosition -= numberOfWhiteSpaces;
3162 if( !mImpl->IsShowingPlaceholderText() )
3164 // Retrieves the normal text string.
3165 mImpl->GetText( numberOfWhiteSpaces, text );
3169 // When the current text is Placeholder Text, the surrounding text should be empty string.
3170 // It means DALi should send empty string ("") to IME.
3175 InputMethodContext::CallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
3177 if( requestRelayout &&
3178 ( NULL != mImpl->mEditableControlInterface ) )
3180 // Do this last since it provides callbacks into application code
3181 mImpl->mEditableControlInterface->TextChanged();
3184 return callbackData;
3187 void Controller::PasteClipboardItemEvent()
3189 // Retrieve the clipboard contents first
3190 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
3191 std::string stringToPaste( notifier.GetContent() );
3193 // Commit the current pre-edit text; the contents of the clipboard should be appended
3194 mImpl->ResetInputMethodContext();
3196 // Temporary disable hiding clipboard
3197 mImpl->SetClipboardHideEnable( false );
3200 PasteText( stringToPaste );
3202 mImpl->SetClipboardHideEnable( true );
3205 // protected : Inherit from Text::Decorator::ControllerInterface.
3207 void Controller::GetTargetSize( Vector2& targetSize )
3209 targetSize = mImpl->mModel->mVisualModel->mControlSize;
3212 void Controller::AddDecoration( Actor& actor, bool needsClipping )
3214 if( NULL != mImpl->mEditableControlInterface )
3216 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
3220 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
3222 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
3224 if( NULL != mImpl->mEventData )
3226 switch( handleType )
3230 Event event( Event::GRAB_HANDLE_EVENT );
3231 event.p1.mUint = state;
3232 event.p2.mFloat = x;
3233 event.p3.mFloat = y;
3235 mImpl->mEventData->mEventQueue.push_back( event );
3238 case LEFT_SELECTION_HANDLE:
3240 Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
3241 event.p1.mUint = state;
3242 event.p2.mFloat = x;
3243 event.p3.mFloat = y;
3245 mImpl->mEventData->mEventQueue.push_back( event );
3248 case RIGHT_SELECTION_HANDLE:
3250 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
3251 event.p1.mUint = state;
3252 event.p2.mFloat = x;
3253 event.p3.mFloat = y;
3255 mImpl->mEventData->mEventQueue.push_back( event );
3258 case LEFT_SELECTION_HANDLE_MARKER:
3259 case RIGHT_SELECTION_HANDLE_MARKER:
3261 // Markers do not move the handles.
3264 case HANDLE_TYPE_COUNT:
3266 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
3270 mImpl->RequestRelayout();
3274 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
3276 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
3278 if( NULL == mImpl->mEventData )
3285 case Toolkit::TextSelectionPopup::CUT:
3287 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
3288 mImpl->mOperationsPending = ALL_OPERATIONS;
3290 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3291 !mImpl->IsPlaceholderAvailable() )
3293 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3297 ShowPlaceholderText();
3300 mImpl->mEventData->mUpdateCursorPosition = true;
3301 mImpl->mEventData->mScrollAfterDelete = true;
3303 mImpl->RequestRelayout();
3305 if( NULL != mImpl->mEditableControlInterface )
3307 mImpl->mEditableControlInterface->TextChanged();
3311 case Toolkit::TextSelectionPopup::COPY:
3313 mImpl->SendSelectionToClipboard( false ); // Text not modified
3315 mImpl->mEventData->mUpdateCursorPosition = true;
3317 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
3320 case Toolkit::TextSelectionPopup::PASTE:
3322 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
3325 case Toolkit::TextSelectionPopup::SELECT:
3327 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
3329 if( mImpl->mEventData->mSelectionEnabled )
3331 // Creates a SELECT event.
3332 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
3336 case Toolkit::TextSelectionPopup::SELECT_ALL:
3338 // Creates a SELECT_ALL event
3339 SelectEvent( 0.f, 0.f, true );
3342 case Toolkit::TextSelectionPopup::CLIPBOARD:
3344 mImpl->ShowClipboard();
3347 case Toolkit::TextSelectionPopup::NONE:
3355 void Controller::DisplayTimeExpired()
3357 mImpl->mEventData->mUpdateCursorPosition = true;
3358 // Apply modifications to the model
3359 mImpl->mOperationsPending = ALL_OPERATIONS;
3361 mImpl->RequestRelayout();
3364 // private : Update.
3366 void Controller::InsertText( const std::string& text, Controller::InsertType type )
3368 bool removedPrevious = false;
3369 bool removedSelected = false;
3370 bool maxLengthReached = false;
3372 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
3374 if( NULL == mImpl->mEventData )
3379 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
3380 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
3381 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3383 // TODO: At the moment the underline runs are only for pre-edit.
3384 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
3386 // Remove the previous InputMethodContext pre-edit.
3387 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
3389 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
3390 mImpl->mEventData->mPreEditLength,
3391 DONT_UPDATE_INPUT_STYLE );
3393 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
3394 mImpl->mEventData->mPreEditLength = 0u;
3398 // Remove the previous Selection.
3399 removedSelected = RemoveSelectedText();
3403 Vector<Character> utf32Characters;
3404 Length characterCount = 0u;
3408 // Convert text into UTF-32
3409 utf32Characters.Resize( text.size() );
3411 // This is a bit horrible but std::string returns a (signed) char*
3412 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
3414 // Transform a text array encoded in utf8 into an array encoded in utf32.
3415 // It returns the actual number of characters.
3416 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
3417 utf32Characters.Resize( characterCount );
3419 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
3420 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
3423 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
3425 // The placeholder text is no longer needed
3426 if( mImpl->IsShowingPlaceholderText() )
3431 mImpl->ChangeState( EventData::EDITING );
3433 // Handle the InputMethodContext (predicitive text) state changes
3434 if( COMMIT == type )
3436 // InputMethodContext is no longer handling key-events
3437 mImpl->ClearPreEditFlag();
3441 if( !mImpl->mEventData->mPreEditFlag )
3443 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
3445 // Record the start of the pre-edit text
3446 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
3449 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
3450 mImpl->mEventData->mPreEditFlag = true;
3452 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3455 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
3457 // Restrict new text to fit within Maximum characters setting.
3458 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
3459 maxLengthReached = ( characterCount > maxSizeOfNewText );
3461 // The cursor position.
3462 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3464 // Update the text's style.
3466 // Updates the text style runs by adding characters.
3467 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
3469 // Get the character index from the cursor index.
3470 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
3472 // Retrieve the text's style for the given index.
3474 mImpl->RetrieveDefaultInputStyle( style );
3475 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
3477 // Whether to add a new text color run.
3478 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor ) && !mImpl->mEventData->mInputStyle.isDefaultColor;
3480 // Whether to add a new font run.
3481 const bool addFontNameRun = ( style.familyName != mImpl->mEventData->mInputStyle.familyName ) && mImpl->mEventData->mInputStyle.isFamilyDefined;
3482 const bool addFontWeightRun = ( style.weight != mImpl->mEventData->mInputStyle.weight ) && mImpl->mEventData->mInputStyle.isWeightDefined;
3483 const bool addFontWidthRun = ( style.width != mImpl->mEventData->mInputStyle.width ) && mImpl->mEventData->mInputStyle.isWidthDefined;
3484 const bool addFontSlantRun = ( style.slant != mImpl->mEventData->mInputStyle.slant ) && mImpl->mEventData->mInputStyle.isSlantDefined;
3485 const bool addFontSizeRun = ( style.size != mImpl->mEventData->mInputStyle.size ) && mImpl->mEventData->mInputStyle.isSizeDefined ;
3490 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
3491 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
3493 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
3494 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
3495 colorRun.characterRun.characterIndex = cursorIndex;
3496 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3499 if( addFontNameRun ||
3505 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
3506 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
3508 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
3510 if( addFontNameRun )
3512 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
3513 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
3514 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
3515 fontDescriptionRun.familyDefined = true;
3517 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
3520 if( addFontWeightRun )
3522 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
3523 fontDescriptionRun.weightDefined = true;
3526 if( addFontWidthRun )
3528 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
3529 fontDescriptionRun.widthDefined = true;
3532 if( addFontSlantRun )
3534 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
3535 fontDescriptionRun.slantDefined = true;
3538 if( addFontSizeRun )
3540 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
3541 fontDescriptionRun.sizeDefined = true;
3544 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
3545 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3548 // Insert at current cursor position.
3549 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
3551 if( cursorIndex < numberOfCharactersInModel )
3553 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3557 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3560 // Mark the first paragraph to be updated.
3561 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3563 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3564 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3565 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
3566 mImpl->mTextUpdateInfo.mClearAll = true;
3570 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3571 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
3574 // Update the cursor index.
3575 cursorIndex += maxSizeOfNewText;
3577 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 );
3580 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
3581 mImpl->IsPlaceholderAvailable() )
3583 // Show place-holder if empty after removing the pre-edit text
3584 ShowPlaceholderText();
3585 mImpl->mEventData->mUpdateCursorPosition = true;
3586 mImpl->ClearPreEditFlag();
3588 else if( removedPrevious ||
3590 ( 0 != utf32Characters.Count() ) )
3592 // Queue an inserted event
3593 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
3595 mImpl->mEventData->mUpdateCursorPosition = true;
3596 if( removedSelected )
3598 mImpl->mEventData->mScrollAfterDelete = true;
3602 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3606 if( maxLengthReached )
3608 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
3610 mImpl->ResetInputMethodContext();
3612 if( NULL != mImpl->mEditableControlInterface )
3614 // Do this last since it provides callbacks into application code
3615 mImpl->mEditableControlInterface->MaxLengthReached();
3620 void Controller::PasteText( const std::string& stringToPaste )
3622 InsertText( stringToPaste, Text::Controller::COMMIT );
3623 mImpl->ChangeState( EventData::EDITING );
3624 mImpl->RequestRelayout();
3626 if( NULL != mImpl->mEditableControlInterface )
3628 // Do this last since it provides callbacks into application code
3629 mImpl->mEditableControlInterface->TextChanged();
3633 bool Controller::RemoveText( int cursorOffset,
3634 int numberOfCharacters,
3635 UpdateInputStyleType type )
3637 bool removed = false;
3639 if( NULL == mImpl->mEventData )
3644 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
3645 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
3647 if( !mImpl->IsShowingPlaceholderText() )
3649 // Delete at current cursor position
3650 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
3651 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3653 CharacterIndex cursorIndex = 0;
3655 // Validate the cursor position & number of characters
3656 if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
3658 cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
3661 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
3663 numberOfCharacters = currentText.Count() - cursorIndex;
3666 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.
3667 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
3669 // Mark the paragraphs to be updated.
3670 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3672 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3673 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3674 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
3675 mImpl->mTextUpdateInfo.mClearAll = true;
3679 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3680 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
3683 // Update the input style and remove the text's style before removing the text.
3685 if( UPDATE_INPUT_STYLE == type )
3687 // Keep a copy of the current input style.
3688 InputStyle currentInputStyle;
3689 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
3691 // Set first the default input style.
3692 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
3694 // Update the input style.
3695 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
3697 // Compare if the input style has changed.
3698 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
3700 if( hasInputStyleChanged )
3702 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
3703 // Queue the input style changed signal.
3704 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
3708 // Updates the text style runs by removing characters. Runs with no characters are removed.
3709 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
3711 // Remove the characters.
3712 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
3713 Vector<Character>::Iterator last = first + numberOfCharacters;
3715 currentText.Erase( first, last );
3717 // Cursor position retreat
3718 oldCursorIndex = cursorIndex;
3720 mImpl->mEventData->mScrollAfterDelete = true;
3722 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
3730 bool Controller::RemoveSelectedText()
3732 bool textRemoved( false );
3734 if( EventData::SELECTING == mImpl->mEventData->mState )
3736 std::string removedString;
3737 mImpl->RetrieveSelection( removedString, true );
3739 if( !removedString.empty() )
3742 mImpl->ChangeState( EventData::EDITING );
3749 // private : Relayout.
3751 bool Controller::DoRelayout( const Size& size,
3752 OperationsMask operationsRequired,
3755 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
3756 bool viewUpdated( false );
3758 // Calculate the operations to be done.
3759 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
3761 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
3762 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
3764 // Get the current layout size.
3765 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3767 if( NO_OPERATION != ( LAYOUT & operations ) )
3769 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
3771 // Some vectors with data needed to layout and reorder may be void
3772 // after the first time the text has been laid out.
3773 // Fill the vectors again.
3775 // Calculate the number of glyphs to layout.
3776 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
3777 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
3778 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
3779 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
3781 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
3782 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
3784 // Make sure the index is not out of bound
3785 if ( charactersToGlyph.Count() != glyphsPerCharacter.Count() ||
3786 requestedNumberOfCharacters > charactersToGlyph.Count() ||
3787 ( lastIndex > charactersToGlyph.Count() && charactersToGlyph.Count() > 0u ) )
3789 std::string currentText;
3790 GetText( currentText );
3792 DALI_LOG_ERROR( "Controller::DoRelayout: Attempting to access invalid buffer\n" );
3793 DALI_LOG_ERROR( "Current text is: %s\n", currentText.c_str() );
3794 DALI_LOG_ERROR( "startIndex: %u, lastIndex: %u, requestedNumberOfCharacters: %u, charactersToGlyph.Count = %lu, glyphsPerCharacter.Count = %lu\n", startIndex, lastIndex, requestedNumberOfCharacters, charactersToGlyph.Count(), glyphsPerCharacter.Count());
3799 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
3800 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
3802 if( 0u == totalNumberOfGlyphs )
3804 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3806 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
3809 // Nothing else to do if there is no glyphs.
3810 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
3814 const Vector<LineBreakInfo>& lineBreakInfo = mImpl->mModel->mLogicalModel->mLineBreakInfo;
3815 const Vector<WordBreakInfo>& wordBreakInfo = mImpl->mModel->mLogicalModel->mWordBreakInfo;
3816 const Vector<CharacterDirection>& characterDirection = mImpl->mModel->mLogicalModel->mCharacterDirections;
3817 const Vector<GlyphInfo>& glyphs = mImpl->mModel->mVisualModel->mGlyphs;
3818 const Vector<CharacterIndex>& glyphsToCharactersMap = mImpl->mModel->mVisualModel->mGlyphsToCharacters;
3819 const Vector<Length>& charactersPerGlyph = mImpl->mModel->mVisualModel->mCharactersPerGlyph;
3820 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
3821 const float outlineWidth = static_cast<float>( mImpl->mModel->GetOutlineWidth() );
3823 // Set the layout parameters.
3824 Layout::Parameters layoutParameters( size,
3826 lineBreakInfo.Begin(),
3827 wordBreakInfo.Begin(),
3828 ( 0u != characterDirection.Count() ) ? characterDirection.Begin() : NULL,
3830 glyphsToCharactersMap.Begin(),
3831 charactersPerGlyph.Begin(),
3832 charactersToGlyphBuffer,
3833 glyphsPerCharacterBuffer,
3834 totalNumberOfGlyphs,
3835 mImpl->mModel->mHorizontalAlignment,
3836 mImpl->mModel->mLineWrapMode,
3838 mImpl->mModel->mIgnoreSpacesAfterText,
3839 mImpl->mModel->mMatchSystemLanguageDirection );
3841 // Resize the vector of positions to have the same size than the vector of glyphs.
3842 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
3843 glyphPositions.Resize( totalNumberOfGlyphs );
3845 // Whether the last character is a new paragraph character.
3846 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
3847 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
3849 // The initial glyph and the number of glyphs to layout.
3850 layoutParameters.startGlyphIndex = startGlyphIndex;
3851 layoutParameters.numberOfGlyphs = numberOfGlyphs;
3852 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
3853 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
3855 // Update the ellipsis
3856 bool elideTextEnabled = mImpl->mModel->mElideEnabled;
3858 if( NULL != mImpl->mEventData )
3860 if( mImpl->mEventData->mPlaceholderEllipsisFlag && mImpl->IsShowingPlaceholderText() )
3862 elideTextEnabled = mImpl->mEventData->mIsPlaceholderElideEnabled;
3864 else if( EventData::INACTIVE != mImpl->mEventData->mState )
3866 // Disable ellipsis when editing
3867 elideTextEnabled = false;
3870 // Reset the scroll position in inactive state
3871 if( elideTextEnabled && ( mImpl->mEventData->mState == EventData::INACTIVE ) )
3873 ResetScrollPosition();
3877 // Update the visual model.
3878 bool isAutoScrollEnabled = mImpl->mIsAutoScrollEnabled;
3880 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
3882 mImpl->mModel->mVisualModel->mLines,
3885 isAutoScrollEnabled );
3886 mImpl->mIsAutoScrollEnabled = isAutoScrollEnabled;
3888 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
3892 layoutSize = newLayoutSize;
3894 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
3896 mImpl->mIsTextDirectionRTL = false;
3899 // Reorder the lines
3900 if( NO_OPERATION != ( REORDER & operations ) )
3902 Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = mImpl->mModel->mLogicalModel->mBidirectionalParagraphInfo;
3903 Vector<BidirectionalLineInfoRun>& bidirectionalLineInfo = mImpl->mModel->mLogicalModel->mBidirectionalLineInfo;
3905 // Check first if there are paragraphs with bidirectional info.
3906 if( 0u != bidirectionalInfo.Count() )
3909 const Length numberOfLines = mImpl->mModel->mVisualModel->mLines.Count();
3911 // Reorder the lines.
3912 bidirectionalLineInfo.Reserve( numberOfLines ); // Reserve because is not known yet how many lines have right to left characters.
3913 ReorderLines( bidirectionalInfo,
3915 requestedNumberOfCharacters,
3916 mImpl->mModel->mVisualModel->mLines,
3917 bidirectionalLineInfo );
3919 // Set the bidirectional info per line into the layout parameters.
3920 layoutParameters.lineBidirectionalInfoRunsBuffer = bidirectionalLineInfo.Begin();
3921 layoutParameters.numberOfBidirectionalInfoRuns = bidirectionalLineInfo.Count();
3923 // Re-layout the text. Reorder those lines with right to left characters.
3924 mImpl->mLayoutEngine.ReLayoutRightToLeftLines( layoutParameters,
3926 requestedNumberOfCharacters,
3929 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && ( numberOfLines > 0 ) )
3931 const LineRun* const firstline = mImpl->mModel->mVisualModel->mLines.Begin();
3934 mImpl->mIsTextDirectionRTL = firstline->direction;
3940 // Sets the layout size.
3941 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3943 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
3948 if( NO_OPERATION != ( ALIGN & operations ) )
3950 // The laid-out lines.
3951 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
3953 CharacterIndex alignStartIndex = startIndex;
3954 Length alignRequestedNumberOfCharacters = requestedNumberOfCharacters;
3956 // the whole text needs to be full aligned.
3957 // If you do not do a full aligned, only the last line of the multiline input is aligned.
3958 if( mImpl->mEventData && mImpl->mEventData->mUpdateAlignment )
3960 alignStartIndex = 0u;
3961 alignRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
3962 mImpl->mEventData->mUpdateAlignment = false;
3965 // Need to align with the control's size as the text may contain lines
3966 // starting either with left to right text or right to left.
3967 mImpl->mLayoutEngine.Align( size,
3969 alignRequestedNumberOfCharacters,
3970 mImpl->mModel->mHorizontalAlignment,
3972 mImpl->mModel->mAlignmentOffset,
3973 mImpl->mLayoutDirection,
3974 mImpl->mModel->mMatchSystemLanguageDirection );
3978 #if defined(DEBUG_ENABLED)
3979 std::string currentText;
3980 GetText( currentText );
3981 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mIsTextDirectionRTL[%s] [%s]\n", this, (mImpl->mIsTextDirectionRTL)?"true":"false", currentText.c_str() );
3983 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
3987 void Controller::CalculateVerticalOffset( const Size& controlSize )
3989 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3991 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
3993 // Get the line height of the default font.
3994 layoutSize.height = mImpl->GetDefaultFontLineHeight();
3997 switch( mImpl->mModel->mVerticalAlignment )
3999 case VerticalAlignment::TOP:
4001 mImpl->mModel->mScrollPosition.y = 0.f;
4004 case VerticalAlignment::CENTER:
4006 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
4009 case VerticalAlignment::BOTTOM:
4011 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
4017 // private : Events.
4019 void Controller::ProcessModifyEvents()
4021 Vector<ModifyEvent>& events = mImpl->mModifyEvents;
4023 if( 0u == events.Count() )
4029 for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
4030 endIt = events.End();
4034 const ModifyEvent& event = *it;
4036 if( ModifyEvent::TEXT_REPLACED == event.type )
4038 // A (single) replace event should come first, otherwise we wasted time processing NOOP events
4039 DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
4041 TextReplacedEvent();
4043 else if( ModifyEvent::TEXT_INSERTED == event.type )
4045 TextInsertedEvent();
4047 else if( ModifyEvent::TEXT_DELETED == event.type )
4049 // Placeholder-text cannot be deleted
4050 if( !mImpl->IsShowingPlaceholderText() )
4057 if( NULL != mImpl->mEventData )
4059 // When the text is being modified, delay cursor blinking
4060 mImpl->mEventData->mDecorator->DelayCursorBlink();
4062 // Update selection position after modifying the text
4063 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
4064 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
4067 // Discard temporary text
4071 void Controller::TextReplacedEvent()
4073 // The natural size needs to be re-calculated.
4074 mImpl->mRecalculateNaturalSize = true;
4076 // The text direction needs to be updated.
4077 mImpl->mUpdateTextDirection = true;
4079 // Apply modifications to the model
4080 mImpl->mOperationsPending = ALL_OPERATIONS;
4083 void Controller::TextInsertedEvent()
4085 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
4087 if( NULL == mImpl->mEventData )
4092 mImpl->mEventData->mCheckScrollAmount = true;
4094 // The natural size needs to be re-calculated.
4095 mImpl->mRecalculateNaturalSize = true;
4097 // The text direction needs to be updated.
4098 mImpl->mUpdateTextDirection = true;
4100 // Apply modifications to the model; TODO - Optimize this
4101 mImpl->mOperationsPending = ALL_OPERATIONS;
4104 void Controller::TextDeletedEvent()
4106 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
4108 if( NULL == mImpl->mEventData )
4113 mImpl->mEventData->mCheckScrollAmount = true;
4115 // The natural size needs to be re-calculated.
4116 mImpl->mRecalculateNaturalSize = true;
4118 // The text direction needs to be updated.
4119 mImpl->mUpdateTextDirection = true;
4121 // Apply modifications to the model; TODO - Optimize this
4122 mImpl->mOperationsPending = ALL_OPERATIONS;
4125 bool Controller::DeleteEvent( int keyCode )
4127 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p KeyCode : %d \n", this, keyCode );
4129 bool removed = false;
4131 if( NULL == mImpl->mEventData )
4136 // InputMethodContext is no longer handling key-events
4137 mImpl->ClearPreEditFlag();
4139 if( EventData::SELECTING == mImpl->mEventData->mState )
4141 removed = RemoveSelectedText();
4143 else if( ( mImpl->mEventData->mPrimaryCursorPosition > 0 ) && ( keyCode == Dali::DALI_KEY_BACKSPACE) )
4145 // Remove the character before the current cursor position
4146 removed = RemoveText( -1,
4148 UPDATE_INPUT_STYLE );
4150 else if( keyCode == Dali::DevelKey::DALI_KEY_DELETE )
4152 // Remove the character after the current cursor position
4153 removed = RemoveText( 0,
4155 UPDATE_INPUT_STYLE );
4160 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
4161 !mImpl->IsPlaceholderAvailable() )
4163 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
4167 ShowPlaceholderText();
4169 mImpl->mEventData->mUpdateCursorPosition = true;
4170 mImpl->mEventData->mScrollAfterDelete = true;
4176 // private : Helpers.
4178 void Controller::ResetText()
4181 mImpl->mModel->mLogicalModel->mText.Clear();
4183 // Reset the embedded images buffer.
4184 mImpl->mModel->mLogicalModel->ClearEmbeddedImages();
4186 // We have cleared everything including the placeholder-text
4187 mImpl->PlaceholderCleared();
4189 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4190 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4191 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
4193 // Clear any previous text.
4194 mImpl->mTextUpdateInfo.mClearAll = true;
4196 // The natural size needs to be re-calculated.
4197 mImpl->mRecalculateNaturalSize = true;
4199 // The text direction needs to be updated.
4200 mImpl->mUpdateTextDirection = true;
4202 // Apply modifications to the model
4203 mImpl->mOperationsPending = ALL_OPERATIONS;
4206 void Controller::ShowPlaceholderText()
4208 if( mImpl->IsPlaceholderAvailable() )
4210 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
4212 if( NULL == mImpl->mEventData )
4217 mImpl->mEventData->mIsShowingPlaceholderText = true;
4219 // Disable handles when showing place-holder text
4220 mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
4221 mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
4222 mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
4224 const char* text( NULL );
4227 // TODO - Switch Placeholder text when changing state
4228 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
4229 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
4231 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
4232 size = mImpl->mEventData->mPlaceholderTextActive.size();
4236 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
4237 size = mImpl->mEventData->mPlaceholderTextInactive.size();
4240 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4241 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4243 // Reset model for showing placeholder.
4244 mImpl->mModel->mLogicalModel->mText.Clear();
4245 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
4247 // Convert text into UTF-32
4248 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
4249 utf32Characters.Resize( size );
4251 // This is a bit horrible but std::string returns a (signed) char*
4252 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
4254 // Transform a text array encoded in utf8 into an array encoded in utf32.
4255 // It returns the actual number of characters.
4256 const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
4257 utf32Characters.Resize( characterCount );
4259 // The characters to be added.
4260 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
4262 // Reset the cursor position
4263 mImpl->mEventData->mPrimaryCursorPosition = 0;
4265 // The natural size needs to be re-calculated.
4266 mImpl->mRecalculateNaturalSize = true;
4268 // The text direction needs to be updated.
4269 mImpl->mUpdateTextDirection = true;
4271 // Apply modifications to the model
4272 mImpl->mOperationsPending = ALL_OPERATIONS;
4274 // Update the rest of the model during size negotiation
4275 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
4279 void Controller::ClearFontData()
4281 if( mImpl->mFontDefaults )
4283 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
4286 // Set flags to update the model.
4287 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4288 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4289 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
4291 mImpl->mTextUpdateInfo.mClearAll = true;
4292 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
4293 mImpl->mRecalculateNaturalSize = true;
4295 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
4301 UPDATE_LAYOUT_SIZE |
4306 void Controller::ClearStyleData()
4308 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
4309 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
4312 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
4314 // Reset the cursor position
4315 if( NULL != mImpl->mEventData )
4317 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
4319 // Update the cursor if it's in editing mode.
4320 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
4322 mImpl->mEventData->mUpdateCursorPosition = true;
4327 void Controller::ResetScrollPosition()
4329 if( NULL != mImpl->mEventData )
4331 // Reset the scroll position.
4332 mImpl->mModel->mScrollPosition = Vector2::ZERO;
4333 mImpl->mEventData->mScrollAfterUpdatePosition = true;
4337 void Controller::SetControlInterface( ControlInterface* controlInterface )
4339 mImpl->mControlInterface = controlInterface;
4342 bool Controller::ShouldClearFocusOnEscape() const
4344 return mImpl->mShouldClearFocusOnEscape;
4347 // private : Private contructors & copy operator.
4349 Controller::Controller()
4352 mImpl = new Controller::Impl( NULL, NULL );
4355 Controller::Controller( ControlInterface* controlInterface )
4357 mImpl = new Controller::Impl( controlInterface, NULL );
4360 Controller::Controller( ControlInterface* controlInterface,
4361 EditableControlInterface* editableControlInterface )
4363 mImpl = new Controller::Impl( controlInterface,
4364 editableControlInterface );
4367 // The copy constructor and operator are left unimplemented.
4369 // protected : Destructor.
4371 Controller::~Controller()
4378 } // namespace Toolkit