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>
24 #include <dali/public-api/adaptor-framework/key.h>
25 #include <dali/integration-api/debug.h>
26 #include <dali/devel-api/adaptor-framework/clipboard-event-notifier.h>
27 #include <dali/devel-api/text-abstraction/font-client.h>
28 #include <dali/devel-api/adaptor-framework/key-devel.h>
31 #include <dali-toolkit/public-api/controls/text-controls/placeholder-properties.h>
32 #include <dali-toolkit/internal/text/bidirectional-support.h>
33 #include <dali-toolkit/internal/text/character-set-conversion.h>
34 #include <dali-toolkit/internal/text/layouts/layout-parameters.h>
35 #include <dali-toolkit/internal/text/markup-processor.h>
36 #include <dali-toolkit/internal/text/multi-language-support.h>
37 #include <dali-toolkit/internal/text/text-controller-impl.h>
38 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
39 #include <dali-toolkit/internal/text/text-font-style.h>
44 #if defined(DEBUG_ENABLED)
45 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
48 const float MAX_FLOAT = std::numeric_limits<float>::max();
50 const std::string EMPTY_STRING("");
52 const std::string KEY_C_NAME = "c";
53 const std::string KEY_V_NAME = "v";
54 const std::string KEY_X_NAME = "x";
56 const char * const PLACEHOLDER_TEXT = "text";
57 const char * const PLACEHOLDER_TEXT_FOCUSED = "textFocused";
58 const char * const PLACEHOLDER_COLOR = "color";
59 const char * const PLACEHOLDER_FONT_FAMILY = "fontFamily";
60 const char * const PLACEHOLDER_FONT_STYLE = "fontStyle";
61 const char * const PLACEHOLDER_POINT_SIZE = "pointSize";
62 const char * const PLACEHOLDER_PIXEL_SIZE = "pixelSize";
63 const char * const PLACEHOLDER_ELLIPSIS = "ellipsis";
64 const unsigned int MAX_TEXT_LENGTH = 1024u * 32u;
66 float ConvertToEven( float value )
68 int intValue(static_cast<int>( value ));
69 return static_cast<float>( intValue + ( intValue & 1 ) );
72 int ConvertPixelToPint( float pixel )
74 unsigned int horizontalDpi = 0u;
75 unsigned int verticalDpi = 0u;
76 Dali::TextAbstraction::FontClient fontClient = Dali::TextAbstraction::FontClient::Get();
77 fontClient.GetDpi( horizontalDpi, verticalDpi );
79 return ( pixel * 72.f ) / static_cast< float >( horizontalDpi );
95 * @brief Adds a new font description run for the selected text.
97 * The new font parameters are added after the call to this method.
99 * @param[in] eventData The event data pointer.
100 * @param[in] logicalModel The logical model where to add the new font description run.
101 * @param[out] startOfSelectedText Index to the first selected character.
102 * @param[out] lengthOfSelectedText Number of selected characters.
104 FontDescriptionRun& UpdateSelectionFontStyleRun( EventData* eventData,
105 LogicalModelPtr logicalModel,
106 CharacterIndex& startOfSelectedText,
107 Length& lengthOfSelectedText )
109 const bool handlesCrossed = eventData->mLeftSelectionPosition > eventData->mRightSelectionPosition;
111 // Get start and end position of selection
112 startOfSelectedText = handlesCrossed ? eventData->mRightSelectionPosition : eventData->mLeftSelectionPosition;
113 lengthOfSelectedText = ( handlesCrossed ? eventData->mLeftSelectionPosition : eventData->mRightSelectionPosition ) - startOfSelectedText;
116 const VectorBase::SizeType numberOfRuns = logicalModel->mFontDescriptionRuns.Count();
117 logicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
119 FontDescriptionRun& fontDescriptionRun = *( logicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
121 fontDescriptionRun.characterRun.characterIndex = startOfSelectedText;
122 fontDescriptionRun.characterRun.numberOfCharacters = lengthOfSelectedText;
124 // Recalculate the selection highlight as the metrics may have changed.
125 eventData->mUpdateLeftSelectionPosition = true;
126 eventData->mUpdateRightSelectionPosition = true;
127 eventData->mUpdateHighlightBox = true;
129 return fontDescriptionRun;
132 // public : Constructor.
134 ControllerPtr Controller::New()
136 return ControllerPtr( new Controller() );
139 ControllerPtr Controller::New( ControlInterface* controlInterface )
141 return ControllerPtr( new Controller( controlInterface ) );
144 ControllerPtr Controller::New( ControlInterface* controlInterface,
145 EditableControlInterface* editableControlInterface )
147 return ControllerPtr( new Controller( controlInterface,
148 editableControlInterface ) );
151 // public : Configure the text controller.
153 void Controller::EnableTextInput( DecoratorPtr decorator, InputMethodContext& inputMethodContext )
157 delete mImpl->mEventData;
158 mImpl->mEventData = NULL;
160 // Nothing else to do.
164 if( NULL == mImpl->mEventData )
166 mImpl->mEventData = new EventData( decorator, inputMethodContext );
170 void Controller::SetGlyphType( TextAbstraction::GlyphType glyphType )
172 // Metrics for bitmap & vector based glyphs are different
173 mImpl->mMetrics->SetGlyphType( glyphType );
175 // Clear the font-specific data
178 mImpl->RequestRelayout();
181 void Controller::SetMarkupProcessorEnabled( bool enable )
183 if( enable != mImpl->mMarkupProcessorEnabled )
185 //If Text was already set, call the SetText again for enabling or disabling markup
186 mImpl->mMarkupProcessorEnabled = enable;
193 bool Controller::IsMarkupProcessorEnabled() const
195 return mImpl->mMarkupProcessorEnabled;
198 void Controller::SetAutoScrollEnabled( bool enable )
200 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 );
202 if( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX )
206 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled for SINGLE_LINE_BOX\n" );
207 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
217 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled Disabling autoscroll\n");
218 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
225 mImpl->mIsAutoScrollEnabled = enable;
226 mImpl->RequestRelayout();
230 DALI_LOG_WARNING( "Attempted AutoScrolling on a non SINGLE_LINE_BOX, request ignored\n" );
231 mImpl->mIsAutoScrollEnabled = false;
235 bool Controller::IsAutoScrollEnabled() const
237 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::IsAutoScrollEnabled[%s]\n", mImpl->mIsAutoScrollEnabled?"true":"false" );
239 return mImpl->mIsAutoScrollEnabled;
242 CharacterDirection Controller::GetAutoScrollDirection() const
244 return mImpl->mIsTextDirectionRTL;
247 float Controller::GetAutoScrollLineAlignment() const
251 if( mImpl->mModel->mVisualModel &&
252 ( 0u != mImpl->mModel->mVisualModel->mLines.Count() ) )
254 offset = ( *mImpl->mModel->mVisualModel->mLines.Begin() ).alignmentOffset;
260 void Controller::SetHorizontalScrollEnabled( bool enable )
262 if( ( NULL != mImpl->mEventData ) &&
263 mImpl->mEventData->mDecorator )
265 mImpl->mEventData->mDecorator->SetHorizontalScrollEnabled( enable );
268 bool Controller::IsHorizontalScrollEnabled() const
270 if( ( NULL != mImpl->mEventData ) &&
271 mImpl->mEventData->mDecorator )
273 return mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
279 void Controller::SetVerticalScrollEnabled( bool enable )
281 if( ( NULL != mImpl->mEventData ) &&
282 mImpl->mEventData->mDecorator )
284 if( mImpl->mEventData->mDecorator )
286 mImpl->mEventData->mDecorator->SetVerticalScrollEnabled( enable );
291 bool Controller::IsVerticalScrollEnabled() const
293 if( ( NULL != mImpl->mEventData ) &&
294 mImpl->mEventData->mDecorator )
296 return mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
302 void Controller::SetSmoothHandlePanEnabled( bool enable )
304 if( ( NULL != mImpl->mEventData ) &&
305 mImpl->mEventData->mDecorator )
307 mImpl->mEventData->mDecorator->SetSmoothHandlePanEnabled( enable );
311 bool Controller::IsSmoothHandlePanEnabled() const
313 if( ( NULL != mImpl->mEventData ) &&
314 mImpl->mEventData->mDecorator )
316 return mImpl->mEventData->mDecorator->IsSmoothHandlePanEnabled();
322 void Controller::SetMaximumNumberOfCharacters( Length maxCharacters )
324 mImpl->mMaximumNumberOfCharacters = std::min( maxCharacters, MAX_TEXT_LENGTH );
327 int Controller::GetMaximumNumberOfCharacters()
329 return mImpl->mMaximumNumberOfCharacters;
332 void Controller::SetEnableCursorBlink( bool enable )
334 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "TextInput disabled" );
336 if( NULL != mImpl->mEventData )
338 mImpl->mEventData->mCursorBlinkEnabled = enable;
341 mImpl->mEventData->mDecorator )
343 mImpl->mEventData->mDecorator->StopCursorBlink();
348 bool Controller::GetEnableCursorBlink() const
350 if( NULL != mImpl->mEventData )
352 return mImpl->mEventData->mCursorBlinkEnabled;
358 void Controller::SetMultiLineEnabled( bool enable )
360 const Layout::Engine::Type layout = enable ? Layout::Engine::MULTI_LINE_BOX : Layout::Engine::SINGLE_LINE_BOX;
362 if( layout != mImpl->mLayoutEngine.GetLayout() )
364 // Set the layout type.
365 mImpl->mLayoutEngine.SetLayout( layout );
367 // Set the flags to redo the layout operations
368 const OperationsMask layoutOperations = static_cast<OperationsMask>( LAYOUT |
373 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
374 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | layoutOperations );
376 // Need to recalculate natural size
377 mImpl->mRecalculateNaturalSize = true;
379 mImpl->RequestRelayout();
383 bool Controller::IsMultiLineEnabled() const
385 return Layout::Engine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
388 void Controller::SetHorizontalAlignment( Text::HorizontalAlignment::Type alignment )
390 if( alignment != mImpl->mModel->mHorizontalAlignment )
392 // Set the alignment.
393 mImpl->mModel->mHorizontalAlignment = alignment;
395 // Set the flag to redo the alignment operation.
396 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
398 mImpl->RequestRelayout();
402 Text::HorizontalAlignment::Type Controller::GetHorizontalAlignment() const
404 return mImpl->mModel->mHorizontalAlignment;
407 void Controller::SetVerticalAlignment( VerticalAlignment::Type alignment )
409 if( alignment != mImpl->mModel->mVerticalAlignment )
411 // Set the alignment.
412 mImpl->mModel->mVerticalAlignment = alignment;
414 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
416 mImpl->RequestRelayout();
420 VerticalAlignment::Type Controller::GetVerticalAlignment() const
422 return mImpl->mModel->mVerticalAlignment;
425 bool Controller::IsIgnoreSpacesAfterText() const
427 return mImpl->mModel->mIgnoreSpacesAfterText;
430 void Controller::SetIgnoreSpacesAfterText( bool ignore )
432 mImpl->mModel->mIgnoreSpacesAfterText = ignore;
435 bool Controller::IsMatchSystemLanguageDirection() const
437 return mImpl->mModel->mMatchSystemLanguageDirection;
440 void Controller::SetMatchSystemLanguageDirection( bool match )
442 mImpl->mModel->mMatchSystemLanguageDirection = match;
445 void Controller::SetLayoutDirection( Dali::LayoutDirection::Type layoutDirection )
447 mImpl->mLayoutDirection = layoutDirection;
450 bool Controller::IsShowingRealText() const
452 return mImpl->IsShowingRealText();
456 void Controller::SetLineWrapMode( Text::LineWrap::Mode lineWrapMode )
458 if( lineWrapMode != mImpl->mModel->mLineWrapMode )
460 // Set the text wrap mode.
461 mImpl->mModel->mLineWrapMode = lineWrapMode;
464 // Update Text layout for applying wrap mode
465 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
470 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
471 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
472 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
475 mImpl->RequestRelayout();
479 Text::LineWrap::Mode Controller::GetLineWrapMode() const
481 return mImpl->mModel->mLineWrapMode;
484 void Controller::SetTextElideEnabled( bool enabled )
486 mImpl->mModel->mElideEnabled = enabled;
489 bool Controller::IsTextElideEnabled() const
491 return mImpl->mModel->mElideEnabled;
494 void Controller::SetTextFitEnabled(bool enabled)
496 mImpl->mTextFitEnabled = enabled;
499 bool Controller::IsTextFitEnabled() const
501 return mImpl->mTextFitEnabled;
504 void Controller::SetTextFitMinSize( float minSize, FontSizeType type )
510 mImpl->mTextFitMinSize = minSize;
515 mImpl->mTextFitMinSize = ConvertPixelToPint( minSize );
521 float Controller::GetTextFitMinSize() const
523 return mImpl->mTextFitMinSize;
526 void Controller::SetTextFitMaxSize( float maxSize, FontSizeType type )
532 mImpl->mTextFitMaxSize = maxSize;
537 mImpl->mTextFitMaxSize = ConvertPixelToPint( maxSize );
543 float Controller::GetTextFitMaxSize() const
545 return mImpl->mTextFitMaxSize;
548 void Controller::SetTextFitStepSize( float step, FontSizeType type )
554 mImpl->mTextFitStepSize = step;
559 mImpl->mTextFitStepSize = ConvertPixelToPint( step );
565 float Controller::GetTextFitStepSize() const
567 return mImpl->mTextFitStepSize;
570 void Controller::SetTextFitContentSize(Vector2 size)
572 mImpl->mTextFitContentSize = size;
575 Vector2 Controller::GetTextFitContentSize() const
577 return mImpl->mTextFitContentSize;
580 void Controller::SetPlaceholderTextElideEnabled( bool enabled )
582 mImpl->mEventData->mIsPlaceholderElideEnabled = enabled;
583 mImpl->mEventData->mPlaceholderEllipsisFlag = true;
585 // Update placeholder if there is no text
586 if( mImpl->IsShowingPlaceholderText() ||
587 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
589 ShowPlaceholderText();
593 bool Controller::IsPlaceholderTextElideEnabled() const
595 return mImpl->mEventData->mIsPlaceholderElideEnabled;
598 void Controller::SetSelectionEnabled( bool enabled )
600 mImpl->mEventData->mSelectionEnabled = enabled;
603 bool Controller::IsSelectionEnabled() const
605 return mImpl->mEventData->mSelectionEnabled;
608 void Controller::SetShiftSelectionEnabled( bool enabled )
610 mImpl->mEventData->mShiftSelectionFlag = enabled;
613 bool Controller::IsShiftSelectionEnabled() const
615 return mImpl->mEventData->mShiftSelectionFlag;
618 void Controller::SetGrabHandleEnabled( bool enabled )
620 mImpl->mEventData->mGrabHandleEnabled = enabled;
623 bool Controller::IsGrabHandleEnabled() const
625 return mImpl->mEventData->mGrabHandleEnabled;
628 void Controller::SetGrabHandlePopupEnabled(bool enabled)
630 mImpl->mEventData->mGrabHandlePopupEnabled = enabled;
633 bool Controller::IsGrabHandlePopupEnabled() const
635 return mImpl->mEventData->mGrabHandlePopupEnabled;
640 void Controller::SetText( const std::string& text )
642 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" );
644 // Reset keyboard as text changed
645 mImpl->ResetInputMethodContext();
647 // Remove the previously set text and style.
653 CharacterIndex lastCursorIndex = 0u;
655 if( NULL != mImpl->mEventData )
657 // If popup shown then hide it by switching to Editing state
658 if( ( EventData::SELECTING == mImpl->mEventData->mState ) ||
659 ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
660 ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) ||
661 ( EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState ) )
663 mImpl->ChangeState( EventData::EDITING );
669 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mTextColor );
671 MarkupProcessData markupProcessData( mImpl->mModel->mLogicalModel->mColorRuns,
672 mImpl->mModel->mLogicalModel->mFontDescriptionRuns,
673 mImpl->mModel->mLogicalModel->mEmbeddedItems );
675 Length textSize = 0u;
676 const uint8_t* utf8 = NULL;
677 if( mImpl->mMarkupProcessorEnabled )
679 ProcessMarkupString( text, markupProcessData );
680 textSize = markupProcessData.markupProcessedText.size();
682 // This is a bit horrible but std::string returns a (signed) char*
683 utf8 = reinterpret_cast<const uint8_t*>( markupProcessData.markupProcessedText.c_str() );
687 textSize = text.size();
689 // This is a bit horrible but std::string returns a (signed) char*
690 utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
693 // Limit the text size. If the text size is too large, crash or deadlock will occur.
694 if( textSize > MAX_TEXT_LENGTH )
696 DALI_LOG_WARNING( "The text size is too large(%d), limit the length to 32,768u\n", textSize );
697 textSize = MAX_TEXT_LENGTH;
700 // Convert text into UTF-32
701 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
702 utf32Characters.Resize( textSize );
704 // Transform a text array encoded in utf8 into an array encoded in utf32.
705 // It returns the actual number of characters.
706 Length characterCount = Utf8ToUtf32( utf8, textSize, utf32Characters.Begin() );
707 utf32Characters.Resize( characterCount );
709 DALI_ASSERT_DEBUG( textSize >= characterCount && "Invalid UTF32 conversion length" );
710 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", this, textSize, mImpl->mModel->mLogicalModel->mText.Count() );
712 // The characters to be added.
713 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
715 // To reset the cursor position
716 lastCursorIndex = characterCount;
718 // Update the rest of the model during size negotiation
719 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
721 // The natural size needs to be re-calculated.
722 mImpl->mRecalculateNaturalSize = true;
724 // The text direction needs to be updated.
725 mImpl->mUpdateTextDirection = true;
727 // Apply modifications to the model
728 mImpl->mOperationsPending = ALL_OPERATIONS;
732 ShowPlaceholderText();
735 // Resets the cursor position.
736 ResetCursorPosition( lastCursorIndex );
738 // Scrolls the text to make the cursor visible.
739 ResetScrollPosition();
741 mImpl->RequestRelayout();
743 if( NULL != mImpl->mEventData )
745 // Cancel previously queued events
746 mImpl->mEventData->mEventQueue.clear();
749 // Do this last since it provides callbacks into application code.
750 if( NULL != mImpl->mEditableControlInterface )
752 mImpl->mEditableControlInterface->TextChanged();
756 void Controller::GetText( std::string& text ) const
758 if( !mImpl->IsShowingPlaceholderText() )
760 // Retrieves the text string.
761 mImpl->GetText( 0u, text );
765 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this );
769 void Controller::SetPlaceholderText( PlaceholderType type, const std::string& text )
771 if( NULL != mImpl->mEventData )
773 if( PLACEHOLDER_TYPE_INACTIVE == type )
775 mImpl->mEventData->mPlaceholderTextInactive = text;
779 mImpl->mEventData->mPlaceholderTextActive = text;
782 // Update placeholder if there is no text
783 if( mImpl->IsShowingPlaceholderText() ||
784 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
786 ShowPlaceholderText();
791 void Controller::GetPlaceholderText( PlaceholderType type, std::string& text ) const
793 if( NULL != mImpl->mEventData )
795 if( PLACEHOLDER_TYPE_INACTIVE == type )
797 text = mImpl->mEventData->mPlaceholderTextInactive;
801 text = mImpl->mEventData->mPlaceholderTextActive;
806 void Controller::UpdateAfterFontChange( const std::string& newDefaultFont )
808 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
810 if( !mImpl->mFontDefaults->familyDefined ) // If user defined font then should not update when system font changes
812 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
813 mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
817 mImpl->RequestRelayout();
821 // public : Default style & Input style
823 void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
825 if( NULL == mImpl->mFontDefaults )
827 mImpl->mFontDefaults = new FontDefaults();
830 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
831 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
832 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
834 // Clear the font-specific data
837 mImpl->RequestRelayout();
840 const std::string& Controller::GetDefaultFontFamily() const
842 if( NULL != mImpl->mFontDefaults )
844 return mImpl->mFontDefaults->mFontDescription.family;
850 void Controller::SetPlaceholderFontFamily( const std::string& placeholderTextFontFamily )
852 if( NULL != mImpl->mEventData )
854 if( NULL == mImpl->mEventData->mPlaceholderFont )
856 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
859 mImpl->mEventData->mPlaceholderFont->mFontDescription.family = placeholderTextFontFamily;
860 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetPlaceholderFontFamily %s\n", placeholderTextFontFamily.c_str());
861 mImpl->mEventData->mPlaceholderFont->familyDefined = !placeholderTextFontFamily.empty();
863 mImpl->RequestRelayout();
867 const std::string& Controller::GetPlaceholderFontFamily() const
869 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
871 return mImpl->mEventData->mPlaceholderFont->mFontDescription.family;
877 void Controller::SetDefaultFontWeight( FontWeight weight )
879 if( NULL == mImpl->mFontDefaults )
881 mImpl->mFontDefaults = new FontDefaults();
884 mImpl->mFontDefaults->mFontDescription.weight = weight;
885 mImpl->mFontDefaults->weightDefined = true;
887 // Clear the font-specific data
890 mImpl->RequestRelayout();
893 bool Controller::IsDefaultFontWeightDefined() const
895 if( NULL != mImpl->mFontDefaults )
897 return mImpl->mFontDefaults->weightDefined;
903 FontWeight Controller::GetDefaultFontWeight() const
905 if( NULL != mImpl->mFontDefaults )
907 return mImpl->mFontDefaults->mFontDescription.weight;
910 return TextAbstraction::FontWeight::NORMAL;
913 void Controller::SetPlaceholderTextFontWeight( FontWeight weight )
915 if( NULL != mImpl->mEventData )
917 if( NULL == mImpl->mEventData->mPlaceholderFont )
919 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
922 mImpl->mEventData->mPlaceholderFont->mFontDescription.weight = weight;
923 mImpl->mEventData->mPlaceholderFont->weightDefined = true;
925 mImpl->RequestRelayout();
929 bool Controller::IsPlaceholderTextFontWeightDefined() const
931 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
933 return mImpl->mEventData->mPlaceholderFont->weightDefined;
938 FontWeight Controller::GetPlaceholderTextFontWeight() const
940 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
942 return mImpl->mEventData->mPlaceholderFont->mFontDescription.weight;
945 return TextAbstraction::FontWeight::NORMAL;
948 void Controller::SetDefaultFontWidth( FontWidth width )
950 if( NULL == mImpl->mFontDefaults )
952 mImpl->mFontDefaults = new FontDefaults();
955 mImpl->mFontDefaults->mFontDescription.width = width;
956 mImpl->mFontDefaults->widthDefined = true;
958 // Clear the font-specific data
961 mImpl->RequestRelayout();
964 bool Controller::IsDefaultFontWidthDefined() const
966 if( NULL != mImpl->mFontDefaults )
968 return mImpl->mFontDefaults->widthDefined;
974 FontWidth Controller::GetDefaultFontWidth() const
976 if( NULL != mImpl->mFontDefaults )
978 return mImpl->mFontDefaults->mFontDescription.width;
981 return TextAbstraction::FontWidth::NORMAL;
984 void Controller::SetPlaceholderTextFontWidth( FontWidth width )
986 if( NULL != mImpl->mEventData )
988 if( NULL == mImpl->mEventData->mPlaceholderFont )
990 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
993 mImpl->mEventData->mPlaceholderFont->mFontDescription.width = width;
994 mImpl->mEventData->mPlaceholderFont->widthDefined = true;
996 mImpl->RequestRelayout();
1000 bool Controller::IsPlaceholderTextFontWidthDefined() const
1002 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1004 return mImpl->mEventData->mPlaceholderFont->widthDefined;
1009 FontWidth Controller::GetPlaceholderTextFontWidth() const
1011 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1013 return mImpl->mEventData->mPlaceholderFont->mFontDescription.width;
1016 return TextAbstraction::FontWidth::NORMAL;
1019 void Controller::SetDefaultFontSlant( FontSlant slant )
1021 if( NULL == mImpl->mFontDefaults )
1023 mImpl->mFontDefaults = new FontDefaults();
1026 mImpl->mFontDefaults->mFontDescription.slant = slant;
1027 mImpl->mFontDefaults->slantDefined = true;
1029 // Clear the font-specific data
1032 mImpl->RequestRelayout();
1035 bool Controller::IsDefaultFontSlantDefined() const
1037 if( NULL != mImpl->mFontDefaults )
1039 return mImpl->mFontDefaults->slantDefined;
1044 FontSlant Controller::GetDefaultFontSlant() const
1046 if( NULL != mImpl->mFontDefaults )
1048 return mImpl->mFontDefaults->mFontDescription.slant;
1051 return TextAbstraction::FontSlant::NORMAL;
1054 void Controller::SetPlaceholderTextFontSlant( FontSlant slant )
1056 if( NULL != mImpl->mEventData )
1058 if( NULL == mImpl->mEventData->mPlaceholderFont )
1060 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
1063 mImpl->mEventData->mPlaceholderFont->mFontDescription.slant = slant;
1064 mImpl->mEventData->mPlaceholderFont->slantDefined = true;
1066 mImpl->RequestRelayout();
1070 bool Controller::IsPlaceholderTextFontSlantDefined() const
1072 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1074 return mImpl->mEventData->mPlaceholderFont->slantDefined;
1079 FontSlant Controller::GetPlaceholderTextFontSlant() const
1081 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1083 return mImpl->mEventData->mPlaceholderFont->mFontDescription.slant;
1086 return TextAbstraction::FontSlant::NORMAL;
1089 void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
1091 if( NULL == mImpl->mFontDefaults )
1093 mImpl->mFontDefaults = new FontDefaults();
1100 mImpl->mFontDefaults->mDefaultPointSize = fontSize;
1101 mImpl->mFontDefaults->sizeDefined = true;
1106 // Point size = Pixel size * 72.f / DPI
1107 unsigned int horizontalDpi = 0u;
1108 unsigned int verticalDpi = 0u;
1109 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1110 fontClient.GetDpi( horizontalDpi, verticalDpi );
1112 mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
1113 mImpl->mFontDefaults->sizeDefined = true;
1118 // Clear the font-specific data
1121 mImpl->RequestRelayout();
1124 float Controller::GetDefaultFontSize( FontSizeType type ) const
1127 if( NULL != mImpl->mFontDefaults )
1133 value = mImpl->mFontDefaults->mDefaultPointSize;
1138 // Pixel size = Point size * DPI / 72.f
1139 unsigned int horizontalDpi = 0u;
1140 unsigned int verticalDpi = 0u;
1141 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1142 fontClient.GetDpi( horizontalDpi, verticalDpi );
1144 value = mImpl->mFontDefaults->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1154 void Controller::SetPlaceholderTextFontSize( float fontSize, FontSizeType type )
1156 if( NULL != mImpl->mEventData )
1158 if( NULL == mImpl->mEventData->mPlaceholderFont )
1160 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
1167 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = fontSize;
1168 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1169 mImpl->mEventData->mIsPlaceholderPixelSize = false; // Font size flag
1174 // Point size = Pixel size * 72.f / DPI
1175 unsigned int horizontalDpi = 0u;
1176 unsigned int verticalDpi = 0u;
1177 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1178 fontClient.GetDpi( horizontalDpi, verticalDpi );
1180 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
1181 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1182 mImpl->mEventData->mIsPlaceholderPixelSize = true; // Font size flag
1187 mImpl->RequestRelayout();
1191 float Controller::GetPlaceholderTextFontSize( FontSizeType type ) const
1194 if( NULL != mImpl->mEventData )
1200 if( NULL != mImpl->mEventData->mPlaceholderFont )
1202 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize;
1206 // If the placeholder text font size is not set, then return the default font size.
1207 value = GetDefaultFontSize( POINT_SIZE );
1213 if( NULL != mImpl->mEventData->mPlaceholderFont )
1215 // Pixel size = Point size * DPI / 72.f
1216 unsigned int horizontalDpi = 0u;
1217 unsigned int verticalDpi = 0u;
1218 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1219 fontClient.GetDpi( horizontalDpi, verticalDpi );
1221 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1225 // If the placeholder text font size is not set, then return the default font size.
1226 value = GetDefaultFontSize( PIXEL_SIZE );
1237 void Controller::SetDefaultColor( const Vector4& color )
1239 mImpl->mTextColor = color;
1241 if( !mImpl->IsShowingPlaceholderText() )
1243 mImpl->mModel->mVisualModel->SetTextColor( color );
1245 mImpl->RequestRelayout();
1249 const Vector4& Controller::GetDefaultColor() const
1251 return mImpl->mTextColor;
1254 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
1256 if( NULL != mImpl->mEventData )
1258 mImpl->mEventData->mPlaceholderTextColor = textColor;
1261 if( mImpl->IsShowingPlaceholderText() )
1263 mImpl->mModel->mVisualModel->SetTextColor( textColor );
1264 mImpl->RequestRelayout();
1268 const Vector4& Controller::GetPlaceholderTextColor() const
1270 if( NULL != mImpl->mEventData )
1272 return mImpl->mEventData->mPlaceholderTextColor;
1275 return Color::BLACK;
1278 void Controller::SetShadowOffset( const Vector2& shadowOffset )
1280 mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
1282 mImpl->RequestRelayout();
1285 const Vector2& Controller::GetShadowOffset() const
1287 return mImpl->mModel->mVisualModel->GetShadowOffset();
1290 void Controller::SetShadowColor( const Vector4& shadowColor )
1292 mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
1294 mImpl->RequestRelayout();
1297 const Vector4& Controller::GetShadowColor() const
1299 return mImpl->mModel->mVisualModel->GetShadowColor();
1302 void Controller::SetShadowBlurRadius( const float& shadowBlurRadius )
1304 if ( fabsf( GetShadowBlurRadius() - shadowBlurRadius ) > Math::MACHINE_EPSILON_1 )
1306 mImpl->mModel->mVisualModel->SetShadowBlurRadius( shadowBlurRadius );
1308 mImpl->RequestRelayout();
1312 const float& Controller::GetShadowBlurRadius() const
1314 return mImpl->mModel->mVisualModel->GetShadowBlurRadius();
1317 void Controller::SetUnderlineColor( const Vector4& color )
1319 mImpl->mModel->mVisualModel->SetUnderlineColor( color );
1321 mImpl->RequestRelayout();
1324 const Vector4& Controller::GetUnderlineColor() const
1326 return mImpl->mModel->mVisualModel->GetUnderlineColor();
1329 void Controller::SetUnderlineEnabled( bool enabled )
1331 mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
1333 mImpl->RequestRelayout();
1336 bool Controller::IsUnderlineEnabled() const
1338 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
1341 void Controller::SetUnderlineHeight( float height )
1343 mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
1345 mImpl->RequestRelayout();
1348 float Controller::GetUnderlineHeight() const
1350 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
1353 void Controller::SetOutlineColor( const Vector4& color )
1355 mImpl->mModel->mVisualModel->SetOutlineColor( color );
1357 mImpl->RequestRelayout();
1360 const Vector4& Controller::GetOutlineColor() const
1362 return mImpl->mModel->mVisualModel->GetOutlineColor();
1365 void Controller::SetOutlineWidth( uint16_t width )
1367 mImpl->mModel->mVisualModel->SetOutlineWidth( width );
1369 mImpl->RequestRelayout();
1372 uint16_t Controller::GetOutlineWidth() const
1374 return mImpl->mModel->mVisualModel->GetOutlineWidth();
1377 void Controller::SetBackgroundColor( const Vector4& color )
1379 mImpl->mModel->mVisualModel->SetBackgroundColor( color );
1381 mImpl->RequestRelayout();
1384 const Vector4& Controller::GetBackgroundColor() const
1386 return mImpl->mModel->mVisualModel->GetBackgroundColor();
1389 void Controller::SetBackgroundEnabled( bool enabled )
1391 mImpl->mModel->mVisualModel->SetBackgroundEnabled( enabled );
1393 mImpl->RequestRelayout();
1396 bool Controller::IsBackgroundEnabled() const
1398 return mImpl->mModel->mVisualModel->IsBackgroundEnabled();
1401 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
1403 if( NULL == mImpl->mEmbossDefaults )
1405 mImpl->mEmbossDefaults = new EmbossDefaults();
1408 mImpl->mEmbossDefaults->properties = embossProperties;
1411 const std::string& Controller::GetDefaultEmbossProperties() const
1413 if( NULL != mImpl->mEmbossDefaults )
1415 return mImpl->mEmbossDefaults->properties;
1418 return EMPTY_STRING;
1421 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
1423 if( NULL == mImpl->mOutlineDefaults )
1425 mImpl->mOutlineDefaults = new OutlineDefaults();
1428 mImpl->mOutlineDefaults->properties = outlineProperties;
1431 const std::string& Controller::GetDefaultOutlineProperties() const
1433 if( NULL != mImpl->mOutlineDefaults )
1435 return mImpl->mOutlineDefaults->properties;
1438 return EMPTY_STRING;
1441 bool Controller::SetDefaultLineSpacing( float lineSpacing )
1443 if( std::abs(lineSpacing - mImpl->mLayoutEngine.GetDefaultLineSpacing()) > Math::MACHINE_EPSILON_1000 )
1445 mImpl->mLayoutEngine.SetDefaultLineSpacing(lineSpacing);
1446 mImpl->mRecalculateNaturalSize = true;
1452 float Controller::GetDefaultLineSpacing() const
1454 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
1457 void Controller::SetInputColor( const Vector4& color )
1459 if( NULL != mImpl->mEventData )
1461 mImpl->mEventData->mInputStyle.textColor = color;
1462 mImpl->mEventData->mInputStyle.isDefaultColor = false;
1464 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1466 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
1468 // Get start and end position of selection
1469 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
1470 const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
1472 // Add the color run.
1473 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1474 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
1476 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
1477 colorRun.color = color;
1478 colorRun.characterRun.characterIndex = startOfSelectedText;
1479 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1481 // Request to relayout.
1482 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1483 mImpl->RequestRelayout();
1485 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1486 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1487 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1492 const Vector4& Controller::GetInputColor() const
1494 if( NULL != mImpl->mEventData )
1496 return mImpl->mEventData->mInputStyle.textColor;
1499 // Return the default text's color if there is no EventData.
1500 return mImpl->mTextColor;
1504 void Controller::SetInputFontFamily( const std::string& fontFamily )
1506 if( NULL != mImpl->mEventData )
1508 mImpl->mEventData->mInputStyle.familyName = fontFamily;
1509 mImpl->mEventData->mInputStyle.isFamilyDefined = true;
1511 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1513 CharacterIndex startOfSelectedText = 0u;
1514 Length lengthOfSelectedText = 0u;
1515 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1516 mImpl->mModel->mLogicalModel,
1517 startOfSelectedText,
1518 lengthOfSelectedText );
1520 fontDescriptionRun.familyLength = fontFamily.size();
1521 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
1522 memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength );
1523 fontDescriptionRun.familyDefined = true;
1525 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
1527 // Request to relayout.
1528 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1533 UPDATE_LAYOUT_SIZE |
1536 mImpl->mRecalculateNaturalSize = true;
1537 mImpl->RequestRelayout();
1539 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1540 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1541 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1543 // As the font changes, recalculate the handle positions is needed.
1544 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1545 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1546 mImpl->mEventData->mUpdateHighlightBox = true;
1547 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1552 const std::string& Controller::GetInputFontFamily() const
1554 if( NULL != mImpl->mEventData )
1556 return mImpl->mEventData->mInputStyle.familyName;
1559 // Return the default font's family if there is no EventData.
1560 return GetDefaultFontFamily();
1563 void Controller::SetInputFontWeight( FontWeight weight )
1565 if( NULL != mImpl->mEventData )
1567 mImpl->mEventData->mInputStyle.weight = weight;
1568 mImpl->mEventData->mInputStyle.isWeightDefined = true;
1570 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1572 CharacterIndex startOfSelectedText = 0u;
1573 Length lengthOfSelectedText = 0u;
1574 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1575 mImpl->mModel->mLogicalModel,
1576 startOfSelectedText,
1577 lengthOfSelectedText );
1579 fontDescriptionRun.weight = weight;
1580 fontDescriptionRun.weightDefined = true;
1582 // Request to relayout.
1583 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1588 UPDATE_LAYOUT_SIZE |
1591 mImpl->mRecalculateNaturalSize = true;
1592 mImpl->RequestRelayout();
1594 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1595 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1596 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1598 // As the font might change, recalculate the handle positions is needed.
1599 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1600 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1601 mImpl->mEventData->mUpdateHighlightBox = true;
1602 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1607 bool Controller::IsInputFontWeightDefined() const
1609 bool defined = false;
1611 if( NULL != mImpl->mEventData )
1613 defined = mImpl->mEventData->mInputStyle.isWeightDefined;
1619 FontWeight Controller::GetInputFontWeight() const
1621 if( NULL != mImpl->mEventData )
1623 return mImpl->mEventData->mInputStyle.weight;
1626 return GetDefaultFontWeight();
1629 void Controller::SetInputFontWidth( FontWidth width )
1631 if( NULL != mImpl->mEventData )
1633 mImpl->mEventData->mInputStyle.width = width;
1634 mImpl->mEventData->mInputStyle.isWidthDefined = true;
1636 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1638 CharacterIndex startOfSelectedText = 0u;
1639 Length lengthOfSelectedText = 0u;
1640 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1641 mImpl->mModel->mLogicalModel,
1642 startOfSelectedText,
1643 lengthOfSelectedText );
1645 fontDescriptionRun.width = width;
1646 fontDescriptionRun.widthDefined = true;
1648 // Request to relayout.
1649 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1654 UPDATE_LAYOUT_SIZE |
1657 mImpl->mRecalculateNaturalSize = true;
1658 mImpl->RequestRelayout();
1660 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1661 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1662 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1664 // As the font might change, recalculate the handle positions is needed.
1665 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1666 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1667 mImpl->mEventData->mUpdateHighlightBox = true;
1668 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1673 bool Controller::IsInputFontWidthDefined() const
1675 bool defined = false;
1677 if( NULL != mImpl->mEventData )
1679 defined = mImpl->mEventData->mInputStyle.isWidthDefined;
1685 FontWidth Controller::GetInputFontWidth() const
1687 if( NULL != mImpl->mEventData )
1689 return mImpl->mEventData->mInputStyle.width;
1692 return GetDefaultFontWidth();
1695 void Controller::SetInputFontSlant( FontSlant slant )
1697 if( NULL != mImpl->mEventData )
1699 mImpl->mEventData->mInputStyle.slant = slant;
1700 mImpl->mEventData->mInputStyle.isSlantDefined = true;
1702 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1704 CharacterIndex startOfSelectedText = 0u;
1705 Length lengthOfSelectedText = 0u;
1706 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1707 mImpl->mModel->mLogicalModel,
1708 startOfSelectedText,
1709 lengthOfSelectedText );
1711 fontDescriptionRun.slant = slant;
1712 fontDescriptionRun.slantDefined = true;
1714 // Request to relayout.
1715 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1720 UPDATE_LAYOUT_SIZE |
1723 mImpl->mRecalculateNaturalSize = true;
1724 mImpl->RequestRelayout();
1726 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1727 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1728 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1730 // As the font might change, recalculate the handle positions is needed.
1731 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1732 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1733 mImpl->mEventData->mUpdateHighlightBox = true;
1734 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1739 bool Controller::IsInputFontSlantDefined() const
1741 bool defined = false;
1743 if( NULL != mImpl->mEventData )
1745 defined = mImpl->mEventData->mInputStyle.isSlantDefined;
1751 FontSlant Controller::GetInputFontSlant() const
1753 if( NULL != mImpl->mEventData )
1755 return mImpl->mEventData->mInputStyle.slant;
1758 return GetDefaultFontSlant();
1761 void Controller::SetInputFontPointSize( float size )
1763 if( NULL != mImpl->mEventData )
1765 mImpl->mEventData->mInputStyle.size = size;
1766 mImpl->mEventData->mInputStyle.isSizeDefined = true;
1768 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1770 CharacterIndex startOfSelectedText = 0u;
1771 Length lengthOfSelectedText = 0u;
1772 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1773 mImpl->mModel->mLogicalModel,
1774 startOfSelectedText,
1775 lengthOfSelectedText );
1777 fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
1778 fontDescriptionRun.sizeDefined = true;
1780 // Request to relayout.
1781 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1786 UPDATE_LAYOUT_SIZE |
1789 mImpl->mRecalculateNaturalSize = true;
1790 mImpl->RequestRelayout();
1792 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1793 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1794 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1796 // As the font might change, recalculate the handle positions is needed.
1797 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1798 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1799 mImpl->mEventData->mUpdateHighlightBox = true;
1800 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1805 float Controller::GetInputFontPointSize() const
1807 if( NULL != mImpl->mEventData )
1809 return mImpl->mEventData->mInputStyle.size;
1812 // Return the default font's point size if there is no EventData.
1813 return GetDefaultFontSize( Text::Controller::POINT_SIZE );
1816 void Controller::SetInputLineSpacing( float lineSpacing )
1818 if( NULL != mImpl->mEventData )
1820 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1821 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1825 float Controller::GetInputLineSpacing() const
1827 if( NULL != mImpl->mEventData )
1829 return mImpl->mEventData->mInputStyle.lineSpacing;
1835 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1837 if( NULL != mImpl->mEventData )
1839 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1843 const std::string& Controller::GetInputShadowProperties() const
1845 if( NULL != mImpl->mEventData )
1847 return mImpl->mEventData->mInputStyle.shadowProperties;
1850 return EMPTY_STRING;
1853 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1855 if( NULL != mImpl->mEventData )
1857 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1861 const std::string& Controller::GetInputUnderlineProperties() const
1863 if( NULL != mImpl->mEventData )
1865 return mImpl->mEventData->mInputStyle.underlineProperties;
1868 return EMPTY_STRING;
1871 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
1873 if( NULL != mImpl->mEventData )
1875 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1879 const std::string& Controller::GetInputEmbossProperties() const
1881 if( NULL != mImpl->mEventData )
1883 return mImpl->mEventData->mInputStyle.embossProperties;
1886 return GetDefaultEmbossProperties();
1889 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
1891 if( NULL != mImpl->mEventData )
1893 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1897 const std::string& Controller::GetInputOutlineProperties() const
1899 if( NULL != mImpl->mEventData )
1901 return mImpl->mEventData->mInputStyle.outlineProperties;
1904 return GetDefaultOutlineProperties();
1907 void Controller::SetInputModePassword( bool passwordInput )
1909 if( NULL != mImpl->mEventData )
1911 mImpl->mEventData->mPasswordInput = passwordInput;
1915 bool Controller::IsInputModePassword()
1917 if( NULL != mImpl->mEventData )
1919 return mImpl->mEventData->mPasswordInput;
1924 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
1926 if( NULL != mImpl->mEventData )
1928 mImpl->mEventData->mDoubleTapAction = action;
1932 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1934 NoTextTap::Action action = NoTextTap::NO_ACTION;
1936 if( NULL != mImpl->mEventData )
1938 action = mImpl->mEventData->mDoubleTapAction;
1944 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
1946 if( NULL != mImpl->mEventData )
1948 mImpl->mEventData->mLongPressAction = action;
1952 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1954 NoTextTap::Action action = NoTextTap::NO_ACTION;
1956 if( NULL != mImpl->mEventData )
1958 action = mImpl->mEventData->mLongPressAction;
1964 bool Controller::IsUnderlineSetByString()
1966 return mImpl->mUnderlineSetByString;
1969 void Controller::UnderlineSetByString( bool setByString )
1971 mImpl->mUnderlineSetByString = setByString;
1974 bool Controller::IsShadowSetByString()
1976 return mImpl->mShadowSetByString;
1979 void Controller::ShadowSetByString( bool setByString )
1981 mImpl->mShadowSetByString = setByString;
1984 bool Controller::IsOutlineSetByString()
1986 return mImpl->mOutlineSetByString;
1989 void Controller::OutlineSetByString( bool setByString )
1991 mImpl->mOutlineSetByString = setByString;
1994 bool Controller::IsFontStyleSetByString()
1996 return mImpl->mFontStyleSetByString;
1999 void Controller::FontStyleSetByString( bool setByString )
2001 mImpl->mFontStyleSetByString = setByString;
2004 // public : Queries & retrieves.
2006 Layout::Engine& Controller::GetLayoutEngine()
2008 return mImpl->mLayoutEngine;
2011 View& Controller::GetView()
2013 return mImpl->mView;
2016 Vector3 Controller::GetNaturalSize()
2018 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
2019 Vector3 naturalSize;
2021 // Make sure the model is up-to-date before layouting
2022 ProcessModifyEvents();
2024 if( mImpl->mRecalculateNaturalSize )
2026 // Operations that can be done only once until the text changes.
2027 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2034 GET_GLYPH_METRICS );
2036 // Set the update info to relayout the whole text.
2037 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2038 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2040 // Make sure the model is up-to-date before layouting
2041 mImpl->UpdateModel( onlyOnceOperations );
2043 // Layout the text for the new width.
2044 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT | REORDER );
2046 // Store the actual control's size to restore later.
2047 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
2049 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
2050 static_cast<OperationsMask>( onlyOnceOperations |
2052 naturalSize.GetVectorXY() );
2054 // Do not do again the only once operations.
2055 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2057 // Do the size related operations again.
2058 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
2061 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
2063 // Stores the natural size to avoid recalculate it again
2064 // unless the text/style changes.
2065 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
2067 mImpl->mRecalculateNaturalSize = false;
2069 // Clear the update info. This info will be set the next time the text is updated.
2070 mImpl->mTextUpdateInfo.Clear();
2071 mImpl->mTextUpdateInfo.mClearAll = true;
2073 // Restore the actual control's size.
2074 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
2076 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
2080 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
2082 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
2085 naturalSize.x = ConvertToEven( naturalSize.x );
2086 naturalSize.y = ConvertToEven( naturalSize.y );
2091 bool Controller::CheckForTextFit( float pointSize, Size& layoutSize )
2094 mImpl->mFontDefaults->mFitPointSize = pointSize;
2095 mImpl->mFontDefaults->sizeDefined = true;
2098 // Operations that can be done only once until the text changes.
2099 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2106 GET_GLYPH_METRICS );
2108 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2109 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2111 // Make sure the model is up-to-date before layouting
2112 mImpl->UpdateModel( onlyOnceOperations );
2114 DoRelayout( Size( layoutSize.width, MAX_FLOAT ),
2115 static_cast<OperationsMask>( onlyOnceOperations | LAYOUT),
2118 // Clear the update info. This info will be set the next time the text is updated.
2119 mImpl->mTextUpdateInfo.Clear();
2120 mImpl->mTextUpdateInfo.mClearAll = true;
2122 if( textSize.width > layoutSize.width || textSize.height > layoutSize.height )
2129 void Controller::FitPointSizeforLayout( Size layoutSize )
2131 bool actualellipsis = mImpl->mModel->mElideEnabled;
2132 float minPointSize = mImpl->mTextFitMinSize;
2133 float maxPointSize = mImpl->mTextFitMaxSize;
2134 float pointInterval = mImpl->mTextFitStepSize;
2136 mImpl->mModel->mElideEnabled = false;
2137 Vector<float> pointSizeArray;
2140 if( pointInterval < 1.f )
2142 mImpl->mTextFitStepSize = pointInterval = 1.0f;
2145 pointSizeArray.Reserve( static_cast< unsigned int >( ceil( ( maxPointSize - minPointSize ) / pointInterval ) ) );
2147 for( float i = minPointSize; i < maxPointSize; i += pointInterval )
2149 pointSizeArray.PushBack( i );
2152 pointSizeArray.PushBack( maxPointSize );
2154 int bestSizeIndex = 0;
2155 int min = bestSizeIndex + 1;
2156 int max = pointSizeArray.Size() - 1;
2159 int destI = ( min + max ) / 2;
2161 if( CheckForTextFit( pointSizeArray[destI], layoutSize ) )
2163 bestSizeIndex = min;
2169 bestSizeIndex = max;
2173 mImpl->mModel->mElideEnabled = actualellipsis;
2174 mImpl->mFontDefaults->mFitPointSize = pointSizeArray[bestSizeIndex];
2175 mImpl->mFontDefaults->sizeDefined = true;
2179 float Controller::GetHeightForWidth( float width )
2181 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
2182 // Make sure the model is up-to-date before layouting
2183 ProcessModifyEvents();
2186 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ||
2187 mImpl->mTextUpdateInfo.mFullRelayoutNeeded ||
2188 mImpl->mTextUpdateInfo.mClearAll )
2190 // Operations that can be done only once until the text changes.
2191 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2198 GET_GLYPH_METRICS );
2200 // Set the update info to relayout the whole text.
2201 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2202 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2204 // Make sure the model is up-to-date before layouting
2205 mImpl->UpdateModel( onlyOnceOperations );
2208 // Layout the text for the new width.
2209 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
2211 // Store the actual control's width.
2212 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
2214 DoRelayout( Size( width, MAX_FLOAT ),
2215 static_cast<OperationsMask>( onlyOnceOperations |
2219 // Do not do again the only once operations.
2220 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2222 // Do the size related operations again.
2223 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
2227 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
2229 // Clear the update info. This info will be set the next time the text is updated.
2230 mImpl->mTextUpdateInfo.Clear();
2231 mImpl->mTextUpdateInfo.mClearAll = true;
2233 // Restore the actual control's width.
2234 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
2236 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
2240 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
2241 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
2244 return layoutSize.height;
2247 int Controller::GetLineCount( float width )
2249 GetHeightForWidth( width );
2250 int numberofLines = mImpl->mModel->GetNumberOfLines();
2251 return numberofLines;
2254 const ModelInterface* const Controller::GetTextModel() const
2256 return mImpl->mModel.Get();
2259 float Controller::GetScrollAmountByUserInput()
2261 float scrollAmount = 0.0f;
2263 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
2265 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
2266 mImpl->mEventData->mCheckScrollAmount = false;
2268 return scrollAmount;
2271 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
2273 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
2276 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
2277 layoutHeight = layout.height;
2278 scrollPosition = mImpl->mModel->mScrollPosition.y;
2279 isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
2283 void Controller::SetHiddenInputOption(const Property::Map& options )
2285 if( NULL == mImpl->mHiddenInput )
2287 mImpl->mHiddenInput = new HiddenText( this );
2289 mImpl->mHiddenInput->SetProperties(options);
2292 void Controller::GetHiddenInputOption(Property::Map& options )
2294 if( NULL != mImpl->mHiddenInput )
2296 mImpl->mHiddenInput->GetProperties(options);
2300 void Controller::SetPlaceholderProperty( const Property::Map& map )
2302 const Property::Map::SizeType count = map.Count();
2304 for( Property::Map::SizeType position = 0; position < count; ++position )
2306 KeyValuePair keyValue = map.GetKeyValue( position );
2307 Property::Key& key = keyValue.first;
2308 Property::Value& value = keyValue.second;
2310 if( key == Toolkit::Text::PlaceHolder::Property::TEXT || key == PLACEHOLDER_TEXT )
2312 std::string text = "";
2314 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
2316 else if( key == Toolkit::Text::PlaceHolder::Property::TEXT_FOCUSED || key == PLACEHOLDER_TEXT_FOCUSED )
2318 std::string text = "";
2320 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
2322 else if( key == Toolkit::Text::PlaceHolder::Property::COLOR || key == PLACEHOLDER_COLOR )
2325 value.Get( textColor );
2326 if( GetPlaceholderTextColor() != textColor )
2328 SetPlaceholderTextColor( textColor );
2331 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_FAMILY || key == PLACEHOLDER_FONT_FAMILY )
2333 std::string fontFamily = "";
2334 value.Get( fontFamily );
2335 SetPlaceholderFontFamily( fontFamily );
2337 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_STYLE || key == PLACEHOLDER_FONT_STYLE )
2339 SetFontStyleProperty( this, value, Text::FontStyle::PLACEHOLDER );
2341 else if( key == Toolkit::Text::PlaceHolder::Property::POINT_SIZE || key == PLACEHOLDER_POINT_SIZE )
2344 value.Get( pointSize );
2345 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
2347 SetPlaceholderTextFontSize( pointSize, Text::Controller::POINT_SIZE );
2350 else if( key == Toolkit::Text::PlaceHolder::Property::PIXEL_SIZE || key == PLACEHOLDER_PIXEL_SIZE )
2353 value.Get( pixelSize );
2354 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
2356 SetPlaceholderTextFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
2359 else if( key == Toolkit::Text::PlaceHolder::Property::ELLIPSIS || key == PLACEHOLDER_ELLIPSIS )
2362 value.Get( ellipsis );
2363 SetPlaceholderTextElideEnabled( ellipsis );
2368 void Controller::GetPlaceholderProperty( Property::Map& map )
2370 if( NULL != mImpl->mEventData )
2372 if( !mImpl->mEventData->mPlaceholderTextActive.empty() )
2374 map[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = mImpl->mEventData->mPlaceholderTextActive;
2376 if( !mImpl->mEventData->mPlaceholderTextInactive.empty() )
2378 map[ Text::PlaceHolder::Property::TEXT ] = mImpl->mEventData->mPlaceholderTextInactive;
2381 map[ Text::PlaceHolder::Property::COLOR ] = mImpl->mEventData->mPlaceholderTextColor;
2382 map[ Text::PlaceHolder::Property::FONT_FAMILY ] = GetPlaceholderFontFamily();
2384 Property::Value fontStyleMapGet;
2385 GetFontStyleProperty( this, fontStyleMapGet, Text::FontStyle::PLACEHOLDER );
2386 map[ Text::PlaceHolder::Property::FONT_STYLE ] = fontStyleMapGet;
2388 // Choose font size : POINT_SIZE or PIXEL_SIZE
2389 if( !mImpl->mEventData->mIsPlaceholderPixelSize )
2391 map[ Text::PlaceHolder::Property::POINT_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE );
2395 map[ Text::PlaceHolder::Property::PIXEL_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE );
2398 if( mImpl->mEventData->mPlaceholderEllipsisFlag )
2400 map[ Text::PlaceHolder::Property::ELLIPSIS ] = IsPlaceholderTextElideEnabled();
2405 Toolkit::DevelText::TextDirection::Type Controller::GetTextDirection()
2407 // Make sure the model is up-to-date before layouting
2408 ProcessModifyEvents();
2410 if ( mImpl->mUpdateTextDirection )
2412 // Operations that can be done only once until the text changes.
2413 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2420 GET_GLYPH_METRICS );
2422 // Set the update info to relayout the whole text.
2423 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2424 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2426 // Make sure the model is up-to-date before layouting
2427 mImpl->UpdateModel( onlyOnceOperations );
2429 Vector3 naturalSize;
2430 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
2431 static_cast<OperationsMask>( onlyOnceOperations |
2432 LAYOUT | REORDER | UPDATE_DIRECTION ),
2433 naturalSize.GetVectorXY() );
2435 // Do not do again the only once operations.
2436 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2438 // Clear the update info. This info will be set the next time the text is updated.
2439 mImpl->mTextUpdateInfo.Clear();
2441 mImpl->mUpdateTextDirection = false;
2444 return mImpl->mIsTextDirectionRTL ? Toolkit::DevelText::TextDirection::RIGHT_TO_LEFT : Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT;
2447 Toolkit::DevelText::VerticalLineAlignment::Type Controller::GetVerticalLineAlignment() const
2449 return mImpl->mModel->GetVerticalLineAlignment();
2452 void Controller::SetVerticalLineAlignment( Toolkit::DevelText::VerticalLineAlignment::Type alignment )
2454 mImpl->mModel->mVerticalLineAlignment = alignment;
2457 // public : Relayout.
2459 Controller::UpdateTextType Controller::Relayout( const Size& size, Dali::LayoutDirection::Type layoutDirection )
2461 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
2463 UpdateTextType updateTextType = NONE_UPDATED;
2465 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
2467 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
2469 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
2470 updateTextType = MODEL_UPDATED;
2473 // Clear the update info. This info will be set the next time the text is updated.
2474 mImpl->mTextUpdateInfo.Clear();
2476 // Not worth to relayout if width or height is equal to zero.
2477 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
2479 return updateTextType;
2482 // Whether a new size has been set.
2483 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
2487 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
2489 if( ( 0 == mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd ) &&
2490 ( 0 == mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) &&
2491 ( ( mImpl->mModel->mVisualModel->mControlSize.width < Math::MACHINE_EPSILON_1000 ) || ( mImpl->mModel->mVisualModel->mControlSize.height < Math::MACHINE_EPSILON_1000 ) ) )
2493 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
2496 // Layout operations that need to be done if the size changes.
2497 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2500 UPDATE_LAYOUT_SIZE |
2502 // Set the update info to relayout the whole text.
2503 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2504 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2506 // Store the size used to layout the text.
2507 mImpl->mModel->mVisualModel->mControlSize = size;
2510 // Whether there are modify events.
2511 if( 0u != mImpl->mModifyEvents.Count() )
2513 // Style operations that need to be done if the text is modified.
2514 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2518 // Set the update info to elide the text.
2519 if( mImpl->mModel->mElideEnabled ||
2520 ( ( NULL != mImpl->mEventData ) && mImpl->mEventData->mIsPlaceholderElideEnabled ) )
2522 // Update Text layout for applying elided
2523 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2526 UPDATE_LAYOUT_SIZE |
2528 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2529 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2532 if( mImpl->mModel->mMatchSystemLanguageDirection && mImpl->mLayoutDirection != layoutDirection )
2534 // Clear the update info. This info will be set the next time the text is updated.
2535 mImpl->mTextUpdateInfo.mClearAll = true;
2536 // Apply modifications to the model
2537 // Shape the text again is needed because characters like '()[]{}' have to be mirrored and the glyphs generated again.
2538 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2545 mImpl->mLayoutDirection = layoutDirection;
2548 // Make sure the model is up-to-date before layouting.
2549 ProcessModifyEvents();
2550 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
2554 updated = DoRelayout( size,
2555 mImpl->mOperationsPending,
2556 layoutSize ) || updated;
2561 updateTextType = MODEL_UPDATED;
2564 // Do not re-do any operation until something changes.
2565 mImpl->mOperationsPending = NO_OPERATION;
2566 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
2568 // Whether the text control is editable
2569 const bool isEditable = NULL != mImpl->mEventData;
2571 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
2573 if( newSize && isEditable )
2575 offset = mImpl->mModel->mScrollPosition;
2578 if( !isEditable || !IsMultiLineEnabled() )
2580 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
2581 CalculateVerticalOffset( size );
2588 // If there is a new size, the scroll position needs to be clamped.
2589 mImpl->ClampHorizontalScroll( layoutSize );
2591 // Update the decorator's positions is needed if there is a new size.
2592 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
2595 // Move the cursor, grab handle etc.
2596 if( mImpl->ProcessInputEvents() )
2598 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
2602 // Clear the update info. This info will be set the next time the text is updated.
2603 mImpl->mTextUpdateInfo.Clear();
2604 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
2606 return updateTextType;
2609 void Controller::RequestRelayout()
2611 mImpl->RequestRelayout();
2614 // public : Input style change signals.
2616 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
2618 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
2621 void Controller::ProcessInputStyleChangedSignals()
2623 if( NULL == mImpl->mEventData )
2629 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
2630 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
2634 const InputStyle::Mask mask = *it;
2636 if( NULL != mImpl->mEditableControlInterface )
2638 // Emit the input style changed signal.
2639 mImpl->mEditableControlInterface->InputStyleChanged( mask );
2643 mImpl->mEventData->mInputStyleChangedQueue.Clear();
2646 // public : Text-input Event Queuing.
2648 void Controller::KeyboardFocusGainEvent()
2650 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
2652 if( NULL != mImpl->mEventData )
2654 if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
2655 ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
2657 mImpl->ChangeState( EventData::EDITING );
2658 mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
2659 mImpl->mEventData->mUpdateInputStyle = true;
2660 mImpl->mEventData->mScrollAfterUpdatePosition = true;
2662 mImpl->NotifyInputMethodContextMultiLineStatus();
2663 if( mImpl->IsShowingPlaceholderText() )
2665 // Show alternative placeholder-text when editing
2666 ShowPlaceholderText();
2669 mImpl->RequestRelayout();
2673 void Controller::KeyboardFocusLostEvent()
2675 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
2677 if( NULL != mImpl->mEventData )
2679 if( EventData::INTERRUPTED != mImpl->mEventData->mState )
2681 mImpl->ChangeState( EventData::INACTIVE );
2683 if( !mImpl->IsShowingRealText() )
2685 // Revert to regular placeholder-text when not editing
2686 ShowPlaceholderText();
2690 mImpl->RequestRelayout();
2693 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
2695 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
2697 bool textChanged = false;
2698 bool relayoutNeeded = false;
2700 if( ( NULL != mImpl->mEventData ) &&
2701 ( keyEvent.state == KeyEvent::Down ) )
2703 int keyCode = keyEvent.keyCode;
2704 const std::string& keyString = keyEvent.keyPressed;
2705 const std::string keyName = keyEvent.keyPressedName;
2707 const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
2709 // Pre-process to separate modifying events from non-modifying input events.
2712 // In some platforms arrive key events with no key code.
2716 else if( Dali::DALI_KEY_ESCAPE == keyCode || Dali::DALI_KEY_BACK == keyCode || Dali::DALI_KEY_SEARCH == keyCode )
2721 else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) ||
2722 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
2723 ( Dali::DALI_KEY_CURSOR_UP == keyCode ) ||
2724 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) )
2726 // If don't have any text, do nothing.
2727 if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
2732 uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition;
2733 uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2734 uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition );
2735 uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines();
2737 // Logic to determine whether this text control will lose focus or not.
2738 if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2739 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2740 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) ||
2741 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) ||
2742 ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) ||
2743 ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) )
2745 // Release the active highlight.
2746 if( mImpl->mEventData->mState == EventData::SELECTING )
2748 mImpl->ChangeState( EventData::EDITING );
2750 // Update selection position.
2751 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2752 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2753 mImpl->mEventData->mUpdateCursorPosition = true;
2754 mImpl->RequestRelayout();
2759 mImpl->mEventData->mCheckScrollAmount = true;
2760 Event event( Event::CURSOR_KEY_EVENT );
2761 event.p1.mInt = keyCode;
2762 event.p2.mBool = keyEvent.IsShiftModifier();
2763 mImpl->mEventData->mEventQueue.push_back( event );
2765 // Will request for relayout.
2766 relayoutNeeded = true;
2768 else if ( Dali::DevelKey::DALI_KEY_CONTROL_LEFT == keyCode || Dali::DevelKey::DALI_KEY_CONTROL_RIGHT == keyCode )
2770 // Left or Right Control key event is received before Ctrl-C/V/X key event is received
2771 // If not handle it here, any selected text will be deleted
2776 else if ( keyEvent.IsCtrlModifier() )
2778 bool consumed = false;
2779 if (keyName == KEY_C_NAME)
2781 // Ctrl-C to copy the selected text
2782 TextPopupButtonTouched( Toolkit::TextSelectionPopup::COPY );
2785 else if (keyName == KEY_V_NAME)
2787 // Ctrl-V to paste the copied text
2788 TextPopupButtonTouched( Toolkit::TextSelectionPopup::PASTE );
2791 else if (keyName == KEY_X_NAME)
2793 // Ctrl-X to cut the selected text
2794 TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
2799 else if( ( Dali::DALI_KEY_BACKSPACE == keyCode ) ||
2800 ( Dali::DevelKey::DALI_KEY_DELETE == keyCode ) )
2802 textChanged = DeleteEvent( keyCode );
2804 // Will request for relayout.
2805 relayoutNeeded = true;
2807 else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
2808 IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
2809 IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
2811 // Power key/Menu/Home key behaviour does not allow edit mode to resume.
2812 mImpl->ChangeState( EventData::INACTIVE );
2814 // Will request for relayout.
2815 relayoutNeeded = true;
2817 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2819 else if( ( Dali::DALI_KEY_SHIFT_LEFT == keyCode ) || ( Dali::DALI_KEY_SHIFT_RIGHT == keyCode ) )
2821 // 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
2822 // and a character is typed after the type of a upper case latin character.
2827 else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
2829 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2835 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
2837 if( !keyString.empty() )
2839 // InputMethodContext is no longer handling key-events
2840 mImpl->ClearPreEditFlag();
2842 InsertText( keyString, COMMIT );
2846 // Will request for relayout.
2847 relayoutNeeded = true;
2852 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
2853 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
2855 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
2856 ( Dali::DALI_KEY_SHIFT_RIGHT != keyCode ) &&
2857 ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
2858 ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
2860 // Should not change the state if the key is the shift send by the InputMethodContext.
2861 // Otherwise, when the state is SELECTING the text controller can't send the right
2862 // surrounding info to the InputMethodContext.
2863 mImpl->ChangeState( EventData::EDITING );
2865 // Will request for relayout.
2866 relayoutNeeded = true;
2869 if( relayoutNeeded )
2871 mImpl->RequestRelayout();
2876 ( NULL != mImpl->mEditableControlInterface ) )
2878 // Do this last since it provides callbacks into application code
2879 mImpl->mEditableControlInterface->TextChanged();
2885 void Controller::TapEvent( unsigned int tapCount, float x, float y )
2887 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
2889 if( NULL != mImpl->mEventData )
2891 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
2892 EventData::State state( mImpl->mEventData->mState );
2893 bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
2895 if( mImpl->IsClipboardVisible() )
2897 if( EventData::INACTIVE == state || EventData::EDITING == state)
2899 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2901 relayoutNeeded = true;
2903 else if( 1u == tapCount )
2905 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
2907 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
2910 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
2912 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2913 relayoutNeeded = true;
2917 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
2919 // Hide placeholder text
2923 if( EventData::INACTIVE == state )
2925 mImpl->ChangeState( EventData::EDITING );
2927 else if( !mImpl->IsClipboardEmpty() )
2929 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
2931 relayoutNeeded = true;
2934 else if( 2u == tapCount )
2936 if( mImpl->mEventData->mSelectionEnabled &&
2937 mImpl->IsShowingRealText() )
2939 relayoutNeeded = true;
2940 mImpl->mEventData->mIsLeftHandleSelected = true;
2941 mImpl->mEventData->mIsRightHandleSelected = true;
2945 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
2946 if( relayoutNeeded )
2948 Event event( Event::TAP_EVENT );
2949 event.p1.mUint = tapCount;
2950 event.p2.mFloat = x;
2951 event.p3.mFloat = y;
2952 mImpl->mEventData->mEventQueue.push_back( event );
2954 mImpl->RequestRelayout();
2958 // Reset keyboard as tap event has occurred.
2959 mImpl->ResetInputMethodContext();
2962 void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
2964 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
2966 if( NULL != mImpl->mEventData )
2968 Event event( Event::PAN_EVENT );
2969 event.p1.mInt = state;
2970 event.p2.mFloat = displacement.x;
2971 event.p3.mFloat = displacement.y;
2972 mImpl->mEventData->mEventQueue.push_back( event );
2974 mImpl->RequestRelayout();
2978 void Controller::LongPressEvent( Gesture::State state, float x, float y )
2980 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
2982 if( ( state == Gesture::Started ) &&
2983 ( NULL != mImpl->mEventData ) )
2985 // The 1st long-press on inactive text-field is treated as tap
2986 if( EventData::INACTIVE == mImpl->mEventData->mState )
2988 mImpl->ChangeState( EventData::EDITING );
2990 Event event( Event::TAP_EVENT );
2992 event.p2.mFloat = x;
2993 event.p3.mFloat = y;
2994 mImpl->mEventData->mEventQueue.push_back( event );
2996 mImpl->RequestRelayout();
2998 else if( !mImpl->IsShowingRealText() )
3000 Event event( Event::LONG_PRESS_EVENT );
3001 event.p1.mInt = state;
3002 event.p2.mFloat = x;
3003 event.p3.mFloat = y;
3004 mImpl->mEventData->mEventQueue.push_back( event );
3005 mImpl->RequestRelayout();
3007 else if( !mImpl->IsClipboardVisible() )
3009 // Reset the InputMethodContext to commit the pre-edit before selecting the text.
3010 mImpl->ResetInputMethodContext();
3012 Event event( Event::LONG_PRESS_EVENT );
3013 event.p1.mInt = state;
3014 event.p2.mFloat = x;
3015 event.p3.mFloat = y;
3016 mImpl->mEventData->mEventQueue.push_back( event );
3017 mImpl->RequestRelayout();
3019 mImpl->mEventData->mIsLeftHandleSelected = true;
3020 mImpl->mEventData->mIsRightHandleSelected = true;
3025 void Controller::SelectEvent( float x, float y, bool selectAll )
3027 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
3029 if( NULL != mImpl->mEventData )
3033 Event event( Event::SELECT_ALL );
3034 mImpl->mEventData->mEventQueue.push_back( event );
3038 Event event( Event::SELECT );
3039 event.p2.mFloat = x;
3040 event.p3.mFloat = y;
3041 mImpl->mEventData->mEventQueue.push_back( event );
3044 mImpl->mEventData->mCheckScrollAmount = true;
3045 mImpl->mEventData->mIsLeftHandleSelected = true;
3046 mImpl->mEventData->mIsRightHandleSelected = true;
3047 mImpl->RequestRelayout();
3051 InputMethodContext::CallbackData Controller::OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
3053 // Whether the text needs to be relaid-out.
3054 bool requestRelayout = false;
3056 // Whether to retrieve the text and cursor position to be sent to the InputMethodContext.
3057 bool retrieveText = false;
3058 bool retrieveCursor = false;
3060 switch( inputMethodContextEvent.eventName )
3062 case InputMethodContext::COMMIT:
3064 InsertText( inputMethodContextEvent.predictiveString, Text::Controller::COMMIT );
3065 requestRelayout = true;
3066 retrieveCursor = true;
3069 case InputMethodContext::PRE_EDIT:
3071 InsertText( inputMethodContextEvent.predictiveString, Text::Controller::PRE_EDIT );
3072 requestRelayout = true;
3073 retrieveCursor = true;
3076 case InputMethodContext::DELETE_SURROUNDING:
3078 const bool textDeleted = RemoveText( inputMethodContextEvent.cursorOffset,
3079 inputMethodContextEvent.numberOfChars,
3080 DONT_UPDATE_INPUT_STYLE );
3084 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3085 !mImpl->IsPlaceholderAvailable() )
3087 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3091 ShowPlaceholderText();
3093 mImpl->mEventData->mUpdateCursorPosition = true;
3094 mImpl->mEventData->mScrollAfterDelete = true;
3096 requestRelayout = true;
3100 case InputMethodContext::GET_SURROUNDING:
3102 retrieveText = true;
3103 retrieveCursor = true;
3106 case InputMethodContext::PRIVATE_COMMAND:
3108 // PRIVATECOMMAND event is just for getting the private command message
3109 retrieveText = true;
3110 retrieveCursor = true;
3113 case InputMethodContext::VOID:
3120 if( requestRelayout )
3122 mImpl->mOperationsPending = ALL_OPERATIONS;
3123 mImpl->RequestRelayout();
3127 CharacterIndex cursorPosition = 0u;
3128 Length numberOfWhiteSpaces = 0u;
3130 if( retrieveCursor )
3132 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
3134 cursorPosition = mImpl->GetLogicalCursorPosition();
3136 if( cursorPosition < numberOfWhiteSpaces )
3138 cursorPosition = 0u;
3142 cursorPosition -= numberOfWhiteSpaces;
3148 if( !mImpl->IsShowingPlaceholderText() )
3150 // Retrieves the normal text string.
3151 mImpl->GetText( numberOfWhiteSpaces, text );
3155 // When the current text is Placeholder Text, the surrounding text should be empty string.
3156 // It means DALi should send empty string ("") to IME.
3161 InputMethodContext::CallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
3163 if( requestRelayout &&
3164 ( NULL != mImpl->mEditableControlInterface ) )
3166 // Do this last since it provides callbacks into application code
3167 mImpl->mEditableControlInterface->TextChanged();
3170 return callbackData;
3173 void Controller::PasteClipboardItemEvent()
3175 // Retrieve the clipboard contents first
3176 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
3177 std::string stringToPaste( notifier.GetContent() );
3179 // Commit the current pre-edit text; the contents of the clipboard should be appended
3180 mImpl->ResetInputMethodContext();
3182 // Temporary disable hiding clipboard
3183 mImpl->SetClipboardHideEnable( false );
3186 PasteText( stringToPaste );
3188 mImpl->SetClipboardHideEnable( true );
3191 // protected : Inherit from Text::Decorator::ControllerInterface.
3193 void Controller::GetTargetSize( Vector2& targetSize )
3195 targetSize = mImpl->mModel->mVisualModel->mControlSize;
3198 void Controller::AddDecoration( Actor& actor, bool needsClipping )
3200 if( NULL != mImpl->mEditableControlInterface )
3202 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
3206 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
3208 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
3210 if( NULL != mImpl->mEventData )
3212 switch( handleType )
3216 Event event( Event::GRAB_HANDLE_EVENT );
3217 event.p1.mUint = state;
3218 event.p2.mFloat = x;
3219 event.p3.mFloat = y;
3221 mImpl->mEventData->mEventQueue.push_back( event );
3224 case LEFT_SELECTION_HANDLE:
3226 Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
3227 event.p1.mUint = state;
3228 event.p2.mFloat = x;
3229 event.p3.mFloat = y;
3231 mImpl->mEventData->mEventQueue.push_back( event );
3234 case RIGHT_SELECTION_HANDLE:
3236 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
3237 event.p1.mUint = state;
3238 event.p2.mFloat = x;
3239 event.p3.mFloat = y;
3241 mImpl->mEventData->mEventQueue.push_back( event );
3244 case LEFT_SELECTION_HANDLE_MARKER:
3245 case RIGHT_SELECTION_HANDLE_MARKER:
3247 // Markers do not move the handles.
3250 case HANDLE_TYPE_COUNT:
3252 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
3256 mImpl->RequestRelayout();
3260 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
3262 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
3264 if( NULL == mImpl->mEventData )
3271 case Toolkit::TextSelectionPopup::CUT:
3273 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
3274 mImpl->mOperationsPending = ALL_OPERATIONS;
3276 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3277 !mImpl->IsPlaceholderAvailable() )
3279 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3283 ShowPlaceholderText();
3286 mImpl->mEventData->mUpdateCursorPosition = true;
3287 mImpl->mEventData->mScrollAfterDelete = true;
3289 mImpl->RequestRelayout();
3291 if( NULL != mImpl->mEditableControlInterface )
3293 mImpl->mEditableControlInterface->TextChanged();
3297 case Toolkit::TextSelectionPopup::COPY:
3299 mImpl->SendSelectionToClipboard( false ); // Text not modified
3301 mImpl->mEventData->mUpdateCursorPosition = true;
3303 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
3306 case Toolkit::TextSelectionPopup::PASTE:
3308 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
3311 case Toolkit::TextSelectionPopup::SELECT:
3313 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
3315 if( mImpl->mEventData->mSelectionEnabled )
3317 // Creates a SELECT event.
3318 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
3322 case Toolkit::TextSelectionPopup::SELECT_ALL:
3324 // Creates a SELECT_ALL event
3325 SelectEvent( 0.f, 0.f, true );
3328 case Toolkit::TextSelectionPopup::CLIPBOARD:
3330 mImpl->ShowClipboard();
3333 case Toolkit::TextSelectionPopup::NONE:
3341 void Controller::DisplayTimeExpired()
3343 mImpl->mEventData->mUpdateCursorPosition = true;
3344 // Apply modifications to the model
3345 mImpl->mOperationsPending = ALL_OPERATIONS;
3347 mImpl->RequestRelayout();
3350 // private : Update.
3352 void Controller::InsertText( const std::string& text, Controller::InsertType type )
3354 bool removedPrevious = false;
3355 bool removedSelected = false;
3356 bool maxLengthReached = false;
3358 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
3360 if( NULL == mImpl->mEventData )
3365 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
3366 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
3367 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3369 // TODO: At the moment the underline runs are only for pre-edit.
3370 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
3372 // Remove the previous InputMethodContext pre-edit.
3373 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
3375 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
3376 mImpl->mEventData->mPreEditLength,
3377 DONT_UPDATE_INPUT_STYLE );
3379 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
3380 mImpl->mEventData->mPreEditLength = 0u;
3384 // Remove the previous Selection.
3385 removedSelected = RemoveSelectedText();
3389 Vector<Character> utf32Characters;
3390 Length characterCount = 0u;
3394 // Convert text into UTF-32
3395 utf32Characters.Resize( text.size() );
3397 // This is a bit horrible but std::string returns a (signed) char*
3398 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
3400 // Transform a text array encoded in utf8 into an array encoded in utf32.
3401 // It returns the actual number of characters.
3402 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
3403 utf32Characters.Resize( characterCount );
3405 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
3406 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
3409 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
3411 // The placeholder text is no longer needed
3412 if( mImpl->IsShowingPlaceholderText() )
3417 mImpl->ChangeState( EventData::EDITING );
3419 // Handle the InputMethodContext (predicitive text) state changes
3420 if( COMMIT == type )
3422 // InputMethodContext is no longer handling key-events
3423 mImpl->ClearPreEditFlag();
3427 if( !mImpl->mEventData->mPreEditFlag )
3429 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
3431 // Record the start of the pre-edit text
3432 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
3435 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
3436 mImpl->mEventData->mPreEditFlag = true;
3438 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3441 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
3443 // Restrict new text to fit within Maximum characters setting.
3444 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
3445 maxLengthReached = ( characterCount > maxSizeOfNewText );
3447 // The cursor position.
3448 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3450 // Update the text's style.
3452 // Updates the text style runs by adding characters.
3453 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
3455 // Get the character index from the cursor index.
3456 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
3458 // Retrieve the text's style for the given index.
3460 mImpl->RetrieveDefaultInputStyle( style );
3461 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
3463 // Whether to add a new text color run.
3464 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor ) && !mImpl->mEventData->mInputStyle.isDefaultColor;
3466 // Whether to add a new font run.
3467 const bool addFontNameRun = ( style.familyName != mImpl->mEventData->mInputStyle.familyName ) && mImpl->mEventData->mInputStyle.isFamilyDefined;
3468 const bool addFontWeightRun = ( style.weight != mImpl->mEventData->mInputStyle.weight ) && mImpl->mEventData->mInputStyle.isWeightDefined;
3469 const bool addFontWidthRun = ( style.width != mImpl->mEventData->mInputStyle.width ) && mImpl->mEventData->mInputStyle.isWidthDefined;
3470 const bool addFontSlantRun = ( style.slant != mImpl->mEventData->mInputStyle.slant ) && mImpl->mEventData->mInputStyle.isSlantDefined;
3471 const bool addFontSizeRun = ( style.size != mImpl->mEventData->mInputStyle.size ) && mImpl->mEventData->mInputStyle.isSizeDefined ;
3476 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
3477 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
3479 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
3480 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
3481 colorRun.characterRun.characterIndex = cursorIndex;
3482 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3485 if( addFontNameRun ||
3491 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
3492 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
3494 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
3496 if( addFontNameRun )
3498 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
3499 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
3500 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
3501 fontDescriptionRun.familyDefined = true;
3503 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
3506 if( addFontWeightRun )
3508 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
3509 fontDescriptionRun.weightDefined = true;
3512 if( addFontWidthRun )
3514 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
3515 fontDescriptionRun.widthDefined = true;
3518 if( addFontSlantRun )
3520 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
3521 fontDescriptionRun.slantDefined = true;
3524 if( addFontSizeRun )
3526 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
3527 fontDescriptionRun.sizeDefined = true;
3530 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
3531 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3534 // Insert at current cursor position.
3535 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
3537 if( cursorIndex < numberOfCharactersInModel )
3539 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3543 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3546 // Mark the first paragraph to be updated.
3547 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3549 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3550 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3551 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
3552 mImpl->mTextUpdateInfo.mClearAll = true;
3556 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3557 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
3560 // Update the cursor index.
3561 cursorIndex += maxSizeOfNewText;
3563 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 );
3566 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
3567 mImpl->IsPlaceholderAvailable() )
3569 // Show place-holder if empty after removing the pre-edit text
3570 ShowPlaceholderText();
3571 mImpl->mEventData->mUpdateCursorPosition = true;
3572 mImpl->ClearPreEditFlag();
3574 else if( removedPrevious ||
3576 ( 0 != utf32Characters.Count() ) )
3578 // Queue an inserted event
3579 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
3581 mImpl->mEventData->mUpdateCursorPosition = true;
3582 if( removedSelected )
3584 mImpl->mEventData->mScrollAfterDelete = true;
3588 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3592 if( maxLengthReached )
3594 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
3596 mImpl->ResetInputMethodContext();
3598 if( NULL != mImpl->mEditableControlInterface )
3600 // Do this last since it provides callbacks into application code
3601 mImpl->mEditableControlInterface->MaxLengthReached();
3606 void Controller::PasteText( const std::string& stringToPaste )
3608 InsertText( stringToPaste, Text::Controller::COMMIT );
3609 mImpl->ChangeState( EventData::EDITING );
3610 mImpl->RequestRelayout();
3612 if( NULL != mImpl->mEditableControlInterface )
3614 // Do this last since it provides callbacks into application code
3615 mImpl->mEditableControlInterface->TextChanged();
3619 bool Controller::RemoveText( int cursorOffset,
3620 int numberOfCharacters,
3621 UpdateInputStyleType type )
3623 bool removed = false;
3625 if( NULL == mImpl->mEventData )
3630 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
3631 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
3633 if( !mImpl->IsShowingPlaceholderText() )
3635 // Delete at current cursor position
3636 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
3637 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3639 CharacterIndex cursorIndex = 0;
3641 // Validate the cursor position & number of characters
3642 if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
3644 cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
3647 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
3649 numberOfCharacters = currentText.Count() - cursorIndex;
3652 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.
3653 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
3655 // Mark the paragraphs to be updated.
3656 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3658 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3659 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3660 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
3661 mImpl->mTextUpdateInfo.mClearAll = true;
3665 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3666 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
3669 // Update the input style and remove the text's style before removing the text.
3671 if( UPDATE_INPUT_STYLE == type )
3673 // Keep a copy of the current input style.
3674 InputStyle currentInputStyle;
3675 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
3677 // Set first the default input style.
3678 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
3680 // Update the input style.
3681 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
3683 // Compare if the input style has changed.
3684 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
3686 if( hasInputStyleChanged )
3688 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
3689 // Queue the input style changed signal.
3690 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
3694 // Updates the text style runs by removing characters. Runs with no characters are removed.
3695 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
3697 // Remove the characters.
3698 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
3699 Vector<Character>::Iterator last = first + numberOfCharacters;
3701 currentText.Erase( first, last );
3703 // Cursor position retreat
3704 oldCursorIndex = cursorIndex;
3706 mImpl->mEventData->mScrollAfterDelete = true;
3708 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
3716 bool Controller::RemoveSelectedText()
3718 bool textRemoved( false );
3720 if( EventData::SELECTING == mImpl->mEventData->mState )
3722 std::string removedString;
3723 mImpl->RetrieveSelection( removedString, true );
3725 if( !removedString.empty() )
3728 mImpl->ChangeState( EventData::EDITING );
3735 // private : Relayout.
3737 bool Controller::DoRelayout( const Size& size,
3738 OperationsMask operationsRequired,
3741 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
3742 bool viewUpdated( false );
3744 // Calculate the operations to be done.
3745 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
3747 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
3748 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
3750 // Get the current layout size.
3751 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3753 if( NO_OPERATION != ( LAYOUT & operations ) )
3755 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
3757 // Some vectors with data needed to layout and reorder may be void
3758 // after the first time the text has been laid out.
3759 // Fill the vectors again.
3761 // Calculate the number of glyphs to layout.
3762 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
3763 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
3764 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
3765 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
3767 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
3768 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
3770 // Make sure the index is not out of bound
3771 if ( charactersToGlyph.Count() != glyphsPerCharacter.Count() ||
3772 requestedNumberOfCharacters > charactersToGlyph.Count() ||
3773 ( lastIndex >= charactersToGlyph.Count() && charactersToGlyph.Count() > 0u ) )
3775 std::string currentText;
3776 GetText( currentText );
3778 DALI_LOG_ERROR( "Controller::DoRelayout: Attempting to access invalid buffer\n" );
3779 DALI_LOG_ERROR( "Current text is: %s\n", currentText.c_str() );
3780 DALI_LOG_ERROR( "startIndex: %u, lastIndex: %u, requestedNumberOfCharacters: %u, charactersToGlyph.Count = %lu, glyphsPerCharacter.Count = %lu\n", startIndex, lastIndex, requestedNumberOfCharacters, charactersToGlyph.Count(), glyphsPerCharacter.Count());
3785 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
3786 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
3788 if( 0u == totalNumberOfGlyphs )
3790 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3792 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
3795 // Nothing else to do if there is no glyphs.
3796 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
3800 const Vector<LineBreakInfo>& lineBreakInfo = mImpl->mModel->mLogicalModel->mLineBreakInfo;
3801 const Vector<WordBreakInfo>& wordBreakInfo = mImpl->mModel->mLogicalModel->mWordBreakInfo;
3802 const Vector<CharacterDirection>& characterDirection = mImpl->mModel->mLogicalModel->mCharacterDirections;
3803 const Vector<GlyphInfo>& glyphs = mImpl->mModel->mVisualModel->mGlyphs;
3804 const Vector<CharacterIndex>& glyphsToCharactersMap = mImpl->mModel->mVisualModel->mGlyphsToCharacters;
3805 const Vector<Length>& charactersPerGlyph = mImpl->mModel->mVisualModel->mCharactersPerGlyph;
3806 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
3807 const float outlineWidth = static_cast<float>( mImpl->mModel->GetOutlineWidth() );
3809 // Set the layout parameters.
3810 Layout::Parameters layoutParameters( size,
3812 lineBreakInfo.Begin(),
3813 wordBreakInfo.Begin(),
3814 ( 0u != characterDirection.Count() ) ? characterDirection.Begin() : NULL,
3816 glyphsToCharactersMap.Begin(),
3817 charactersPerGlyph.Begin(),
3818 charactersToGlyphBuffer,
3819 glyphsPerCharacterBuffer,
3820 totalNumberOfGlyphs,
3821 mImpl->mModel->mHorizontalAlignment,
3822 mImpl->mModel->mLineWrapMode,
3824 mImpl->mModel->mIgnoreSpacesAfterText,
3825 mImpl->mModel->mMatchSystemLanguageDirection );
3827 // Resize the vector of positions to have the same size than the vector of glyphs.
3828 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
3829 glyphPositions.Resize( totalNumberOfGlyphs );
3831 // Whether the last character is a new paragraph character.
3832 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
3833 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
3835 // The initial glyph and the number of glyphs to layout.
3836 layoutParameters.startGlyphIndex = startGlyphIndex;
3837 layoutParameters.numberOfGlyphs = numberOfGlyphs;
3838 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
3839 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
3841 // Update the ellipsis
3842 bool elideTextEnabled = mImpl->mModel->mElideEnabled;
3844 if( NULL != mImpl->mEventData )
3846 if( mImpl->mEventData->mPlaceholderEllipsisFlag && mImpl->IsShowingPlaceholderText() )
3848 elideTextEnabled = mImpl->mEventData->mIsPlaceholderElideEnabled;
3850 else if( EventData::INACTIVE != mImpl->mEventData->mState )
3852 // Disable ellipsis when editing
3853 elideTextEnabled = false;
3856 // Reset the scroll position in inactive state
3857 if( elideTextEnabled && ( mImpl->mEventData->mState == EventData::INACTIVE ) )
3859 ResetScrollPosition();
3863 // Update the visual model.
3864 bool isAutoScrollEnabled = mImpl->mIsAutoScrollEnabled;
3866 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
3868 mImpl->mModel->mVisualModel->mLines,
3871 isAutoScrollEnabled );
3872 mImpl->mIsAutoScrollEnabled = isAutoScrollEnabled;
3874 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
3878 layoutSize = newLayoutSize;
3880 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
3882 mImpl->mIsTextDirectionRTL = false;
3885 // Reorder the lines
3886 if( NO_OPERATION != ( REORDER & operations ) )
3888 Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = mImpl->mModel->mLogicalModel->mBidirectionalParagraphInfo;
3889 Vector<BidirectionalLineInfoRun>& bidirectionalLineInfo = mImpl->mModel->mLogicalModel->mBidirectionalLineInfo;
3891 // Check first if there are paragraphs with bidirectional info.
3892 if( 0u != bidirectionalInfo.Count() )
3895 const Length numberOfLines = mImpl->mModel->mVisualModel->mLines.Count();
3897 // Reorder the lines.
3898 bidirectionalLineInfo.Reserve( numberOfLines ); // Reserve because is not known yet how many lines have right to left characters.
3899 ReorderLines( bidirectionalInfo,
3901 requestedNumberOfCharacters,
3902 mImpl->mModel->mVisualModel->mLines,
3903 bidirectionalLineInfo );
3905 // Set the bidirectional info per line into the layout parameters.
3906 layoutParameters.lineBidirectionalInfoRunsBuffer = bidirectionalLineInfo.Begin();
3907 layoutParameters.numberOfBidirectionalInfoRuns = bidirectionalLineInfo.Count();
3909 // Re-layout the text. Reorder those lines with right to left characters.
3910 mImpl->mLayoutEngine.ReLayoutRightToLeftLines( layoutParameters,
3912 requestedNumberOfCharacters,
3915 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && ( numberOfLines > 0 ) )
3917 const LineRun* const firstline = mImpl->mModel->mVisualModel->mLines.Begin();
3920 mImpl->mIsTextDirectionRTL = firstline->direction;
3926 // Sets the layout size.
3927 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3929 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
3934 if( NO_OPERATION != ( ALIGN & operations ) )
3936 // The laid-out lines.
3937 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
3939 // Need to align with the control's size as the text may contain lines
3940 // starting either with left to right text or right to left.
3941 mImpl->mLayoutEngine.Align( size,
3943 requestedNumberOfCharacters,
3944 mImpl->mModel->mHorizontalAlignment,
3946 mImpl->mModel->mAlignmentOffset,
3947 mImpl->mLayoutDirection,
3948 mImpl->mModel->mMatchSystemLanguageDirection );
3952 #if defined(DEBUG_ENABLED)
3953 std::string currentText;
3954 GetText( currentText );
3955 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mIsTextDirectionRTL[%s] [%s]\n", this, (mImpl->mIsTextDirectionRTL)?"true":"false", currentText.c_str() );
3957 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
3961 void Controller::CalculateVerticalOffset( const Size& controlSize )
3963 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3965 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
3967 // Get the line height of the default font.
3968 layoutSize.height = mImpl->GetDefaultFontLineHeight();
3971 switch( mImpl->mModel->mVerticalAlignment )
3973 case VerticalAlignment::TOP:
3975 mImpl->mModel->mScrollPosition.y = 0.f;
3978 case VerticalAlignment::CENTER:
3980 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
3983 case VerticalAlignment::BOTTOM:
3985 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
3991 // private : Events.
3993 void Controller::ProcessModifyEvents()
3995 Vector<ModifyEvent>& events = mImpl->mModifyEvents;
3997 if( 0u == events.Count() )
4003 for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
4004 endIt = events.End();
4008 const ModifyEvent& event = *it;
4010 if( ModifyEvent::TEXT_REPLACED == event.type )
4012 // A (single) replace event should come first, otherwise we wasted time processing NOOP events
4013 DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
4015 TextReplacedEvent();
4017 else if( ModifyEvent::TEXT_INSERTED == event.type )
4019 TextInsertedEvent();
4021 else if( ModifyEvent::TEXT_DELETED == event.type )
4023 // Placeholder-text cannot be deleted
4024 if( !mImpl->IsShowingPlaceholderText() )
4031 if( NULL != mImpl->mEventData )
4033 // When the text is being modified, delay cursor blinking
4034 mImpl->mEventData->mDecorator->DelayCursorBlink();
4036 // Update selection position after modifying the text
4037 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
4038 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
4041 // Discard temporary text
4045 void Controller::TextReplacedEvent()
4047 // The natural size needs to be re-calculated.
4048 mImpl->mRecalculateNaturalSize = true;
4050 // The text direction needs to be updated.
4051 mImpl->mUpdateTextDirection = true;
4053 // Apply modifications to the model
4054 mImpl->mOperationsPending = ALL_OPERATIONS;
4057 void Controller::TextInsertedEvent()
4059 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
4061 if( NULL == mImpl->mEventData )
4066 mImpl->mEventData->mCheckScrollAmount = true;
4068 // The natural size needs to be re-calculated.
4069 mImpl->mRecalculateNaturalSize = true;
4071 // The text direction needs to be updated.
4072 mImpl->mUpdateTextDirection = true;
4074 // Apply modifications to the model; TODO - Optimize this
4075 mImpl->mOperationsPending = ALL_OPERATIONS;
4078 void Controller::TextDeletedEvent()
4080 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
4082 if( NULL == mImpl->mEventData )
4087 mImpl->mEventData->mCheckScrollAmount = true;
4089 // The natural size needs to be re-calculated.
4090 mImpl->mRecalculateNaturalSize = true;
4092 // The text direction needs to be updated.
4093 mImpl->mUpdateTextDirection = true;
4095 // Apply modifications to the model; TODO - Optimize this
4096 mImpl->mOperationsPending = ALL_OPERATIONS;
4099 bool Controller::DeleteEvent( int keyCode )
4101 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p KeyCode : %d \n", this, keyCode );
4103 bool removed = false;
4105 if( NULL == mImpl->mEventData )
4110 // InputMethodContext is no longer handling key-events
4111 mImpl->ClearPreEditFlag();
4113 if( EventData::SELECTING == mImpl->mEventData->mState )
4115 removed = RemoveSelectedText();
4117 else if( ( mImpl->mEventData->mPrimaryCursorPosition > 0 ) && ( keyCode == Dali::DALI_KEY_BACKSPACE) )
4119 // Remove the character before the current cursor position
4120 removed = RemoveText( -1,
4122 UPDATE_INPUT_STYLE );
4124 else if( keyCode == Dali::DevelKey::DALI_KEY_DELETE )
4126 // Remove the character after the current cursor position
4127 removed = RemoveText( 0,
4129 UPDATE_INPUT_STYLE );
4134 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
4135 !mImpl->IsPlaceholderAvailable() )
4137 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
4141 ShowPlaceholderText();
4143 mImpl->mEventData->mUpdateCursorPosition = true;
4144 mImpl->mEventData->mScrollAfterDelete = true;
4150 // private : Helpers.
4152 void Controller::ResetText()
4155 mImpl->mModel->mLogicalModel->mText.Clear();
4157 // Reset the embedded images buffer.
4158 mImpl->mModel->mLogicalModel->ClearEmbeddedImages();
4160 // We have cleared everything including the placeholder-text
4161 mImpl->PlaceholderCleared();
4163 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4164 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4165 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
4167 // Clear any previous text.
4168 mImpl->mTextUpdateInfo.mClearAll = true;
4170 // The natural size needs to be re-calculated.
4171 mImpl->mRecalculateNaturalSize = true;
4173 // The text direction needs to be updated.
4174 mImpl->mUpdateTextDirection = true;
4176 // Apply modifications to the model
4177 mImpl->mOperationsPending = ALL_OPERATIONS;
4180 void Controller::ShowPlaceholderText()
4182 if( mImpl->IsPlaceholderAvailable() )
4184 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
4186 if( NULL == mImpl->mEventData )
4191 mImpl->mEventData->mIsShowingPlaceholderText = true;
4193 // Disable handles when showing place-holder text
4194 mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
4195 mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
4196 mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
4198 const char* text( NULL );
4201 // TODO - Switch Placeholder text when changing state
4202 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
4203 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
4205 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
4206 size = mImpl->mEventData->mPlaceholderTextActive.size();
4210 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
4211 size = mImpl->mEventData->mPlaceholderTextInactive.size();
4214 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4215 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4217 // Reset model for showing placeholder.
4218 mImpl->mModel->mLogicalModel->mText.Clear();
4219 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
4221 // Convert text into UTF-32
4222 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
4223 utf32Characters.Resize( size );
4225 // This is a bit horrible but std::string returns a (signed) char*
4226 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
4228 // Transform a text array encoded in utf8 into an array encoded in utf32.
4229 // It returns the actual number of characters.
4230 const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
4231 utf32Characters.Resize( characterCount );
4233 // The characters to be added.
4234 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
4236 // Reset the cursor position
4237 mImpl->mEventData->mPrimaryCursorPosition = 0;
4239 // The natural size needs to be re-calculated.
4240 mImpl->mRecalculateNaturalSize = true;
4242 // The text direction needs to be updated.
4243 mImpl->mUpdateTextDirection = true;
4245 // Apply modifications to the model
4246 mImpl->mOperationsPending = ALL_OPERATIONS;
4248 // Update the rest of the model during size negotiation
4249 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
4253 void Controller::ClearFontData()
4255 if( mImpl->mFontDefaults )
4257 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
4260 // Set flags to update the model.
4261 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4262 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4263 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
4265 mImpl->mTextUpdateInfo.mClearAll = true;
4266 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
4267 mImpl->mRecalculateNaturalSize = true;
4269 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
4275 UPDATE_LAYOUT_SIZE |
4280 void Controller::ClearStyleData()
4282 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
4283 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
4286 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
4288 // Reset the cursor position
4289 if( NULL != mImpl->mEventData )
4291 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
4293 // Update the cursor if it's in editing mode.
4294 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
4296 mImpl->mEventData->mUpdateCursorPosition = true;
4301 void Controller::ResetScrollPosition()
4303 if( NULL != mImpl->mEventData )
4305 // Reset the scroll position.
4306 mImpl->mModel->mScrollPosition = Vector2::ZERO;
4307 mImpl->mEventData->mScrollAfterUpdatePosition = true;
4311 void Controller::SetControlInterface( ControlInterface* controlInterface )
4313 mImpl->mControlInterface = controlInterface;
4316 bool Controller::ShouldClearFocusOnEscape() const
4318 return mImpl->mShouldClearFocusOnEscape;
4321 // private : Private contructors & copy operator.
4323 Controller::Controller()
4326 mImpl = new Controller::Impl( NULL, NULL );
4329 Controller::Controller( ControlInterface* controlInterface )
4331 mImpl = new Controller::Impl( controlInterface, NULL );
4334 Controller::Controller( ControlInterface* controlInterface,
4335 EditableControlInterface* editableControlInterface )
4337 mImpl = new Controller::Impl( controlInterface,
4338 editableControlInterface );
4341 // The copy constructor and operator are left unimplemented.
4343 // protected : Destructor.
4345 Controller::~Controller()
4352 } // namespace Toolkit