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 const OperationsMask operations = mImpl->mOperationsPending;
2132 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
2134 bool actualellipsis = mImpl->mModel->mElideEnabled;
2135 float minPointSize = mImpl->mTextFitMinSize;
2136 float maxPointSize = mImpl->mTextFitMaxSize;
2137 float pointInterval = mImpl->mTextFitStepSize;
2139 mImpl->mModel->mElideEnabled = false;
2140 Vector<float> pointSizeArray;
2143 if( pointInterval < 1.f )
2145 mImpl->mTextFitStepSize = pointInterval = 1.0f;
2148 pointSizeArray.Reserve( static_cast< unsigned int >( ceil( ( maxPointSize - minPointSize ) / pointInterval ) ) );
2150 for( float i = minPointSize; i < maxPointSize; i += pointInterval )
2152 pointSizeArray.PushBack( i );
2155 pointSizeArray.PushBack( maxPointSize );
2157 int bestSizeIndex = 0;
2158 int min = bestSizeIndex + 1;
2159 int max = pointSizeArray.Size() - 1;
2162 int destI = ( min + max ) / 2;
2164 if( CheckForTextFit( pointSizeArray[destI], layoutSize ) )
2166 bestSizeIndex = min;
2172 bestSizeIndex = max;
2176 mImpl->mModel->mElideEnabled = actualellipsis;
2177 mImpl->mFontDefaults->mFitPointSize = pointSizeArray[bestSizeIndex];
2178 mImpl->mFontDefaults->sizeDefined = true;
2183 float Controller::GetHeightForWidth( float width )
2185 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
2186 // Make sure the model is up-to-date before layouting
2187 ProcessModifyEvents();
2190 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ||
2191 mImpl->mTextUpdateInfo.mFullRelayoutNeeded ||
2192 mImpl->mTextUpdateInfo.mClearAll )
2194 // Operations that can be done only once until the text changes.
2195 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2202 GET_GLYPH_METRICS );
2204 // Set the update info to relayout the whole text.
2205 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2206 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2208 // Make sure the model is up-to-date before layouting
2209 mImpl->UpdateModel( onlyOnceOperations );
2212 // Layout the text for the new width.
2213 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
2215 // Store the actual control's width.
2216 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
2218 DoRelayout( Size( width, MAX_FLOAT ),
2219 static_cast<OperationsMask>( onlyOnceOperations |
2223 // Do not do again the only once operations.
2224 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2226 // Do the size related operations again.
2227 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
2231 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
2233 // Clear the update info. This info will be set the next time the text is updated.
2234 mImpl->mTextUpdateInfo.Clear();
2235 mImpl->mTextUpdateInfo.mClearAll = true;
2237 // Restore the actual control's width.
2238 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
2240 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
2244 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
2245 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
2248 return layoutSize.height;
2251 int Controller::GetLineCount( float width )
2253 GetHeightForWidth( width );
2254 int numberofLines = mImpl->mModel->GetNumberOfLines();
2255 return numberofLines;
2258 const ModelInterface* const Controller::GetTextModel() const
2260 return mImpl->mModel.Get();
2263 float Controller::GetScrollAmountByUserInput()
2265 float scrollAmount = 0.0f;
2267 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
2269 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
2270 mImpl->mEventData->mCheckScrollAmount = false;
2272 return scrollAmount;
2275 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
2277 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
2280 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
2281 layoutHeight = layout.height;
2282 scrollPosition = mImpl->mModel->mScrollPosition.y;
2283 isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
2287 void Controller::SetHiddenInputOption(const Property::Map& options )
2289 if( NULL == mImpl->mHiddenInput )
2291 mImpl->mHiddenInput = new HiddenText( this );
2293 mImpl->mHiddenInput->SetProperties(options);
2296 void Controller::GetHiddenInputOption(Property::Map& options )
2298 if( NULL != mImpl->mHiddenInput )
2300 mImpl->mHiddenInput->GetProperties(options);
2304 void Controller::SetPlaceholderProperty( const Property::Map& map )
2306 const Property::Map::SizeType count = map.Count();
2308 for( Property::Map::SizeType position = 0; position < count; ++position )
2310 KeyValuePair keyValue = map.GetKeyValue( position );
2311 Property::Key& key = keyValue.first;
2312 Property::Value& value = keyValue.second;
2314 if( key == Toolkit::Text::PlaceHolder::Property::TEXT || key == PLACEHOLDER_TEXT )
2316 std::string text = "";
2318 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
2320 else if( key == Toolkit::Text::PlaceHolder::Property::TEXT_FOCUSED || key == PLACEHOLDER_TEXT_FOCUSED )
2322 std::string text = "";
2324 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
2326 else if( key == Toolkit::Text::PlaceHolder::Property::COLOR || key == PLACEHOLDER_COLOR )
2329 value.Get( textColor );
2330 if( GetPlaceholderTextColor() != textColor )
2332 SetPlaceholderTextColor( textColor );
2335 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_FAMILY || key == PLACEHOLDER_FONT_FAMILY )
2337 std::string fontFamily = "";
2338 value.Get( fontFamily );
2339 SetPlaceholderFontFamily( fontFamily );
2341 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_STYLE || key == PLACEHOLDER_FONT_STYLE )
2343 SetFontStyleProperty( this, value, Text::FontStyle::PLACEHOLDER );
2345 else if( key == Toolkit::Text::PlaceHolder::Property::POINT_SIZE || key == PLACEHOLDER_POINT_SIZE )
2348 value.Get( pointSize );
2349 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
2351 SetPlaceholderTextFontSize( pointSize, Text::Controller::POINT_SIZE );
2354 else if( key == Toolkit::Text::PlaceHolder::Property::PIXEL_SIZE || key == PLACEHOLDER_PIXEL_SIZE )
2357 value.Get( pixelSize );
2358 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
2360 SetPlaceholderTextFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
2363 else if( key == Toolkit::Text::PlaceHolder::Property::ELLIPSIS || key == PLACEHOLDER_ELLIPSIS )
2366 value.Get( ellipsis );
2367 SetPlaceholderTextElideEnabled( ellipsis );
2372 void Controller::GetPlaceholderProperty( Property::Map& map )
2374 if( NULL != mImpl->mEventData )
2376 if( !mImpl->mEventData->mPlaceholderTextActive.empty() )
2378 map[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = mImpl->mEventData->mPlaceholderTextActive;
2380 if( !mImpl->mEventData->mPlaceholderTextInactive.empty() )
2382 map[ Text::PlaceHolder::Property::TEXT ] = mImpl->mEventData->mPlaceholderTextInactive;
2385 map[ Text::PlaceHolder::Property::COLOR ] = mImpl->mEventData->mPlaceholderTextColor;
2386 map[ Text::PlaceHolder::Property::FONT_FAMILY ] = GetPlaceholderFontFamily();
2388 Property::Value fontStyleMapGet;
2389 GetFontStyleProperty( this, fontStyleMapGet, Text::FontStyle::PLACEHOLDER );
2390 map[ Text::PlaceHolder::Property::FONT_STYLE ] = fontStyleMapGet;
2392 // Choose font size : POINT_SIZE or PIXEL_SIZE
2393 if( !mImpl->mEventData->mIsPlaceholderPixelSize )
2395 map[ Text::PlaceHolder::Property::POINT_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE );
2399 map[ Text::PlaceHolder::Property::PIXEL_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE );
2402 if( mImpl->mEventData->mPlaceholderEllipsisFlag )
2404 map[ Text::PlaceHolder::Property::ELLIPSIS ] = IsPlaceholderTextElideEnabled();
2409 Toolkit::DevelText::TextDirection::Type Controller::GetTextDirection()
2411 // Make sure the model is up-to-date before layouting
2412 ProcessModifyEvents();
2414 if ( mImpl->mUpdateTextDirection )
2416 // Operations that can be done only once until the text changes.
2417 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2424 GET_GLYPH_METRICS );
2426 // Set the update info to relayout the whole text.
2427 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2428 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2430 // Make sure the model is up-to-date before layouting
2431 mImpl->UpdateModel( onlyOnceOperations );
2433 Vector3 naturalSize;
2434 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
2435 static_cast<OperationsMask>( onlyOnceOperations |
2436 LAYOUT | REORDER | UPDATE_DIRECTION ),
2437 naturalSize.GetVectorXY() );
2439 // Do not do again the only once operations.
2440 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2442 // Clear the update info. This info will be set the next time the text is updated.
2443 mImpl->mTextUpdateInfo.Clear();
2445 mImpl->mUpdateTextDirection = false;
2448 return mImpl->mIsTextDirectionRTL ? Toolkit::DevelText::TextDirection::RIGHT_TO_LEFT : Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT;
2451 Toolkit::DevelText::VerticalLineAlignment::Type Controller::GetVerticalLineAlignment() const
2453 return mImpl->mModel->GetVerticalLineAlignment();
2456 void Controller::SetVerticalLineAlignment( Toolkit::DevelText::VerticalLineAlignment::Type alignment )
2458 mImpl->mModel->mVerticalLineAlignment = alignment;
2461 // public : Relayout.
2463 Controller::UpdateTextType Controller::Relayout( const Size& size, Dali::LayoutDirection::Type layoutDirection )
2465 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
2467 UpdateTextType updateTextType = NONE_UPDATED;
2469 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
2471 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
2473 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
2474 updateTextType = MODEL_UPDATED;
2477 // Clear the update info. This info will be set the next time the text is updated.
2478 mImpl->mTextUpdateInfo.Clear();
2480 // Not worth to relayout if width or height is equal to zero.
2481 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
2483 return updateTextType;
2486 // Whether a new size has been set.
2487 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
2491 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
2493 if( ( 0 == mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd ) &&
2494 ( 0 == mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) &&
2495 ( ( mImpl->mModel->mVisualModel->mControlSize.width < Math::MACHINE_EPSILON_1000 ) || ( mImpl->mModel->mVisualModel->mControlSize.height < Math::MACHINE_EPSILON_1000 ) ) )
2497 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
2500 // Layout operations that need to be done if the size changes.
2501 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2504 UPDATE_LAYOUT_SIZE |
2506 // Set the update info to relayout the whole text.
2507 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2508 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2510 // Store the size used to layout the text.
2511 mImpl->mModel->mVisualModel->mControlSize = size;
2514 // Whether there are modify events.
2515 if( 0u != mImpl->mModifyEvents.Count() )
2517 // Style operations that need to be done if the text is modified.
2518 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2522 // Set the update info to elide the text.
2523 if( mImpl->mModel->mElideEnabled ||
2524 ( ( NULL != mImpl->mEventData ) && mImpl->mEventData->mIsPlaceholderElideEnabled ) )
2526 // Update Text layout for applying elided
2527 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2530 UPDATE_LAYOUT_SIZE |
2532 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2533 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2536 if( mImpl->mModel->mMatchSystemLanguageDirection && mImpl->mLayoutDirection != layoutDirection )
2538 // Clear the update info. This info will be set the next time the text is updated.
2539 mImpl->mTextUpdateInfo.mClearAll = true;
2540 // Apply modifications to the model
2541 // Shape the text again is needed because characters like '()[]{}' have to be mirrored and the glyphs generated again.
2542 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2549 mImpl->mLayoutDirection = layoutDirection;
2552 // Make sure the model is up-to-date before layouting.
2553 ProcessModifyEvents();
2554 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
2558 updated = DoRelayout( size,
2559 mImpl->mOperationsPending,
2560 layoutSize ) || updated;
2565 updateTextType = MODEL_UPDATED;
2568 // Do not re-do any operation until something changes.
2569 mImpl->mOperationsPending = NO_OPERATION;
2570 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
2572 // Whether the text control is editable
2573 const bool isEditable = NULL != mImpl->mEventData;
2575 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
2577 if( newSize && isEditable )
2579 offset = mImpl->mModel->mScrollPosition;
2582 if( !isEditable || !IsMultiLineEnabled() )
2584 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
2585 CalculateVerticalOffset( size );
2592 // If there is a new size, the scroll position needs to be clamped.
2593 mImpl->ClampHorizontalScroll( layoutSize );
2595 // Update the decorator's positions is needed if there is a new size.
2596 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
2599 // Move the cursor, grab handle etc.
2600 if( mImpl->ProcessInputEvents() )
2602 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
2606 // Clear the update info. This info will be set the next time the text is updated.
2607 mImpl->mTextUpdateInfo.Clear();
2608 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
2610 return updateTextType;
2613 void Controller::RequestRelayout()
2615 mImpl->RequestRelayout();
2618 // public : Input style change signals.
2620 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
2622 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
2625 void Controller::ProcessInputStyleChangedSignals()
2627 if( NULL == mImpl->mEventData )
2633 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
2634 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
2638 const InputStyle::Mask mask = *it;
2640 if( NULL != mImpl->mEditableControlInterface )
2642 // Emit the input style changed signal.
2643 mImpl->mEditableControlInterface->InputStyleChanged( mask );
2647 mImpl->mEventData->mInputStyleChangedQueue.Clear();
2650 // public : Text-input Event Queuing.
2652 void Controller::KeyboardFocusGainEvent()
2654 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
2656 if( NULL != mImpl->mEventData )
2658 if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
2659 ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
2661 mImpl->ChangeState( EventData::EDITING );
2662 mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
2663 mImpl->mEventData->mUpdateInputStyle = true;
2664 mImpl->mEventData->mScrollAfterUpdatePosition = true;
2666 mImpl->NotifyInputMethodContextMultiLineStatus();
2667 if( mImpl->IsShowingPlaceholderText() )
2669 // Show alternative placeholder-text when editing
2670 ShowPlaceholderText();
2673 mImpl->RequestRelayout();
2677 void Controller::KeyboardFocusLostEvent()
2679 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
2681 if( NULL != mImpl->mEventData )
2683 if( EventData::INTERRUPTED != mImpl->mEventData->mState )
2685 mImpl->ChangeState( EventData::INACTIVE );
2687 if( !mImpl->IsShowingRealText() )
2689 // Revert to regular placeholder-text when not editing
2690 ShowPlaceholderText();
2694 mImpl->RequestRelayout();
2697 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
2699 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
2701 bool textChanged = false;
2702 bool relayoutNeeded = false;
2704 if( ( NULL != mImpl->mEventData ) &&
2705 ( keyEvent.state == KeyEvent::Down ) )
2707 int keyCode = keyEvent.keyCode;
2708 const std::string& keyString = keyEvent.keyPressed;
2709 const std::string keyName = keyEvent.keyPressedName;
2711 const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
2713 // Pre-process to separate modifying events from non-modifying input events.
2716 // In some platforms arrive key events with no key code.
2720 else if( Dali::DALI_KEY_ESCAPE == keyCode || Dali::DALI_KEY_BACK == keyCode || Dali::DALI_KEY_SEARCH == keyCode )
2725 else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) ||
2726 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
2727 ( Dali::DALI_KEY_CURSOR_UP == keyCode ) ||
2728 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) )
2730 // If don't have any text, do nothing.
2731 if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
2736 uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition;
2737 uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2738 uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition );
2739 uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines();
2741 // Logic to determine whether this text control will lose focus or not.
2742 if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2743 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2744 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) ||
2745 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) ||
2746 ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) ||
2747 ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) )
2749 // Release the active highlight.
2750 if( mImpl->mEventData->mState == EventData::SELECTING )
2752 mImpl->ChangeState( EventData::EDITING );
2754 // Update selection position.
2755 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2756 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2757 mImpl->mEventData->mUpdateCursorPosition = true;
2758 mImpl->RequestRelayout();
2763 mImpl->mEventData->mCheckScrollAmount = true;
2764 Event event( Event::CURSOR_KEY_EVENT );
2765 event.p1.mInt = keyCode;
2766 event.p2.mBool = keyEvent.IsShiftModifier();
2767 mImpl->mEventData->mEventQueue.push_back( event );
2769 // Will request for relayout.
2770 relayoutNeeded = true;
2772 else if ( Dali::DevelKey::DALI_KEY_CONTROL_LEFT == keyCode || Dali::DevelKey::DALI_KEY_CONTROL_RIGHT == keyCode )
2774 // Left or Right Control key event is received before Ctrl-C/V/X key event is received
2775 // If not handle it here, any selected text will be deleted
2780 else if ( keyEvent.IsCtrlModifier() )
2782 bool consumed = false;
2783 if (keyName == KEY_C_NAME)
2785 // Ctrl-C to copy the selected text
2786 TextPopupButtonTouched( Toolkit::TextSelectionPopup::COPY );
2789 else if (keyName == KEY_V_NAME)
2791 // Ctrl-V to paste the copied text
2792 TextPopupButtonTouched( Toolkit::TextSelectionPopup::PASTE );
2795 else if (keyName == KEY_X_NAME)
2797 // Ctrl-X to cut the selected text
2798 TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
2803 else if( ( Dali::DALI_KEY_BACKSPACE == keyCode ) ||
2804 ( Dali::DevelKey::DALI_KEY_DELETE == keyCode ) )
2806 textChanged = DeleteEvent( keyCode );
2808 // Will request for relayout.
2809 relayoutNeeded = true;
2811 else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
2812 IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
2813 IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
2815 // Power key/Menu/Home key behaviour does not allow edit mode to resume.
2816 mImpl->ChangeState( EventData::INACTIVE );
2818 // Will request for relayout.
2819 relayoutNeeded = true;
2821 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2823 else if( ( Dali::DALI_KEY_SHIFT_LEFT == keyCode ) || ( Dali::DALI_KEY_SHIFT_RIGHT == keyCode ) )
2825 // 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
2826 // and a character is typed after the type of a upper case latin character.
2831 else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
2833 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2839 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
2841 if( !keyString.empty() )
2843 // InputMethodContext is no longer handling key-events
2844 mImpl->ClearPreEditFlag();
2846 InsertText( keyString, COMMIT );
2850 // Will request for relayout.
2851 relayoutNeeded = true;
2856 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
2857 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
2859 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
2860 ( Dali::DALI_KEY_SHIFT_RIGHT != keyCode ) &&
2861 ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
2862 ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
2864 // Should not change the state if the key is the shift send by the InputMethodContext.
2865 // Otherwise, when the state is SELECTING the text controller can't send the right
2866 // surrounding info to the InputMethodContext.
2867 mImpl->ChangeState( EventData::EDITING );
2869 // Will request for relayout.
2870 relayoutNeeded = true;
2873 if( relayoutNeeded )
2875 mImpl->RequestRelayout();
2880 ( NULL != mImpl->mEditableControlInterface ) )
2882 // Do this last since it provides callbacks into application code
2883 mImpl->mEditableControlInterface->TextChanged();
2889 void Controller::TapEvent( unsigned int tapCount, float x, float y )
2891 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
2893 if( NULL != mImpl->mEventData )
2895 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
2896 EventData::State state( mImpl->mEventData->mState );
2897 bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
2899 if( mImpl->IsClipboardVisible() )
2901 if( EventData::INACTIVE == state || EventData::EDITING == state)
2903 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2905 relayoutNeeded = true;
2907 else if( 1u == tapCount )
2909 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
2911 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
2914 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
2916 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2917 relayoutNeeded = true;
2921 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
2923 // Hide placeholder text
2927 if( EventData::INACTIVE == state )
2929 mImpl->ChangeState( EventData::EDITING );
2931 else if( !mImpl->IsClipboardEmpty() )
2933 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
2935 relayoutNeeded = true;
2938 else if( 2u == tapCount )
2940 if( mImpl->mEventData->mSelectionEnabled &&
2941 mImpl->IsShowingRealText() )
2943 relayoutNeeded = true;
2944 mImpl->mEventData->mIsLeftHandleSelected = true;
2945 mImpl->mEventData->mIsRightHandleSelected = true;
2949 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
2950 if( relayoutNeeded )
2952 Event event( Event::TAP_EVENT );
2953 event.p1.mUint = tapCount;
2954 event.p2.mFloat = x;
2955 event.p3.mFloat = y;
2956 mImpl->mEventData->mEventQueue.push_back( event );
2958 mImpl->RequestRelayout();
2962 // Reset keyboard as tap event has occurred.
2963 mImpl->ResetInputMethodContext();
2966 void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
2968 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
2970 if( NULL != mImpl->mEventData )
2972 Event event( Event::PAN_EVENT );
2973 event.p1.mInt = state;
2974 event.p2.mFloat = displacement.x;
2975 event.p3.mFloat = displacement.y;
2976 mImpl->mEventData->mEventQueue.push_back( event );
2978 mImpl->RequestRelayout();
2982 void Controller::LongPressEvent( Gesture::State state, float x, float y )
2984 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
2986 if( ( state == Gesture::Started ) &&
2987 ( NULL != mImpl->mEventData ) )
2989 // The 1st long-press on inactive text-field is treated as tap
2990 if( EventData::INACTIVE == mImpl->mEventData->mState )
2992 mImpl->ChangeState( EventData::EDITING );
2994 Event event( Event::TAP_EVENT );
2996 event.p2.mFloat = x;
2997 event.p3.mFloat = y;
2998 mImpl->mEventData->mEventQueue.push_back( event );
3000 mImpl->RequestRelayout();
3002 else if( !mImpl->IsShowingRealText() )
3004 Event event( Event::LONG_PRESS_EVENT );
3005 event.p1.mInt = state;
3006 event.p2.mFloat = x;
3007 event.p3.mFloat = y;
3008 mImpl->mEventData->mEventQueue.push_back( event );
3009 mImpl->RequestRelayout();
3011 else if( !mImpl->IsClipboardVisible() )
3013 // Reset the InputMethodContext to commit the pre-edit before selecting the text.
3014 mImpl->ResetInputMethodContext();
3016 Event event( Event::LONG_PRESS_EVENT );
3017 event.p1.mInt = state;
3018 event.p2.mFloat = x;
3019 event.p3.mFloat = y;
3020 mImpl->mEventData->mEventQueue.push_back( event );
3021 mImpl->RequestRelayout();
3023 mImpl->mEventData->mIsLeftHandleSelected = true;
3024 mImpl->mEventData->mIsRightHandleSelected = true;
3029 void Controller::SelectEvent( float x, float y, bool selectAll )
3031 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
3033 if( NULL != mImpl->mEventData )
3037 Event event( Event::SELECT_ALL );
3038 mImpl->mEventData->mEventQueue.push_back( event );
3042 Event event( Event::SELECT );
3043 event.p2.mFloat = x;
3044 event.p3.mFloat = y;
3045 mImpl->mEventData->mEventQueue.push_back( event );
3048 mImpl->mEventData->mCheckScrollAmount = true;
3049 mImpl->mEventData->mIsLeftHandleSelected = true;
3050 mImpl->mEventData->mIsRightHandleSelected = true;
3051 mImpl->RequestRelayout();
3055 InputMethodContext::CallbackData Controller::OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
3057 // Whether the text needs to be relaid-out.
3058 bool requestRelayout = false;
3060 // Whether to retrieve the text and cursor position to be sent to the InputMethodContext.
3061 bool retrieveText = false;
3062 bool retrieveCursor = false;
3064 switch( inputMethodContextEvent.eventName )
3066 case InputMethodContext::COMMIT:
3068 InsertText( inputMethodContextEvent.predictiveString, Text::Controller::COMMIT );
3069 requestRelayout = true;
3070 retrieveCursor = true;
3073 case InputMethodContext::PRE_EDIT:
3075 InsertText( inputMethodContextEvent.predictiveString, Text::Controller::PRE_EDIT );
3076 requestRelayout = true;
3077 retrieveCursor = true;
3080 case InputMethodContext::DELETE_SURROUNDING:
3082 const bool textDeleted = RemoveText( inputMethodContextEvent.cursorOffset,
3083 inputMethodContextEvent.numberOfChars,
3084 DONT_UPDATE_INPUT_STYLE );
3088 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3089 !mImpl->IsPlaceholderAvailable() )
3091 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3095 ShowPlaceholderText();
3097 mImpl->mEventData->mUpdateCursorPosition = true;
3098 mImpl->mEventData->mScrollAfterDelete = true;
3100 requestRelayout = true;
3104 case InputMethodContext::GET_SURROUNDING:
3106 retrieveText = true;
3107 retrieveCursor = true;
3110 case InputMethodContext::PRIVATE_COMMAND:
3112 // PRIVATECOMMAND event is just for getting the private command message
3113 retrieveText = true;
3114 retrieveCursor = true;
3117 case InputMethodContext::VOID:
3124 if( requestRelayout )
3126 mImpl->mOperationsPending = ALL_OPERATIONS;
3127 mImpl->RequestRelayout();
3131 CharacterIndex cursorPosition = 0u;
3132 Length numberOfWhiteSpaces = 0u;
3134 if( retrieveCursor )
3136 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
3138 cursorPosition = mImpl->GetLogicalCursorPosition();
3140 if( cursorPosition < numberOfWhiteSpaces )
3142 cursorPosition = 0u;
3146 cursorPosition -= numberOfWhiteSpaces;
3152 if( !mImpl->IsShowingPlaceholderText() )
3154 // Retrieves the normal text string.
3155 mImpl->GetText( numberOfWhiteSpaces, text );
3159 // When the current text is Placeholder Text, the surrounding text should be empty string.
3160 // It means DALi should send empty string ("") to IME.
3165 InputMethodContext::CallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
3167 if( requestRelayout &&
3168 ( NULL != mImpl->mEditableControlInterface ) )
3170 // Do this last since it provides callbacks into application code
3171 mImpl->mEditableControlInterface->TextChanged();
3174 return callbackData;
3177 void Controller::PasteClipboardItemEvent()
3179 // Retrieve the clipboard contents first
3180 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
3181 std::string stringToPaste( notifier.GetContent() );
3183 // Commit the current pre-edit text; the contents of the clipboard should be appended
3184 mImpl->ResetInputMethodContext();
3186 // Temporary disable hiding clipboard
3187 mImpl->SetClipboardHideEnable( false );
3190 PasteText( stringToPaste );
3192 mImpl->SetClipboardHideEnable( true );
3195 // protected : Inherit from Text::Decorator::ControllerInterface.
3197 void Controller::GetTargetSize( Vector2& targetSize )
3199 targetSize = mImpl->mModel->mVisualModel->mControlSize;
3202 void Controller::AddDecoration( Actor& actor, bool needsClipping )
3204 if( NULL != mImpl->mEditableControlInterface )
3206 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
3210 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
3212 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
3214 if( NULL != mImpl->mEventData )
3216 switch( handleType )
3220 Event event( Event::GRAB_HANDLE_EVENT );
3221 event.p1.mUint = state;
3222 event.p2.mFloat = x;
3223 event.p3.mFloat = y;
3225 mImpl->mEventData->mEventQueue.push_back( event );
3228 case LEFT_SELECTION_HANDLE:
3230 Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
3231 event.p1.mUint = state;
3232 event.p2.mFloat = x;
3233 event.p3.mFloat = y;
3235 mImpl->mEventData->mEventQueue.push_back( event );
3238 case RIGHT_SELECTION_HANDLE:
3240 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
3241 event.p1.mUint = state;
3242 event.p2.mFloat = x;
3243 event.p3.mFloat = y;
3245 mImpl->mEventData->mEventQueue.push_back( event );
3248 case LEFT_SELECTION_HANDLE_MARKER:
3249 case RIGHT_SELECTION_HANDLE_MARKER:
3251 // Markers do not move the handles.
3254 case HANDLE_TYPE_COUNT:
3256 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
3260 mImpl->RequestRelayout();
3264 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
3266 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
3268 if( NULL == mImpl->mEventData )
3275 case Toolkit::TextSelectionPopup::CUT:
3277 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
3278 mImpl->mOperationsPending = ALL_OPERATIONS;
3280 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3281 !mImpl->IsPlaceholderAvailable() )
3283 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3287 ShowPlaceholderText();
3290 mImpl->mEventData->mUpdateCursorPosition = true;
3291 mImpl->mEventData->mScrollAfterDelete = true;
3293 mImpl->RequestRelayout();
3295 if( NULL != mImpl->mEditableControlInterface )
3297 mImpl->mEditableControlInterface->TextChanged();
3301 case Toolkit::TextSelectionPopup::COPY:
3303 mImpl->SendSelectionToClipboard( false ); // Text not modified
3305 mImpl->mEventData->mUpdateCursorPosition = true;
3307 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
3310 case Toolkit::TextSelectionPopup::PASTE:
3312 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
3315 case Toolkit::TextSelectionPopup::SELECT:
3317 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
3319 if( mImpl->mEventData->mSelectionEnabled )
3321 // Creates a SELECT event.
3322 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
3326 case Toolkit::TextSelectionPopup::SELECT_ALL:
3328 // Creates a SELECT_ALL event
3329 SelectEvent( 0.f, 0.f, true );
3332 case Toolkit::TextSelectionPopup::CLIPBOARD:
3334 mImpl->ShowClipboard();
3337 case Toolkit::TextSelectionPopup::NONE:
3345 void Controller::DisplayTimeExpired()
3347 mImpl->mEventData->mUpdateCursorPosition = true;
3348 // Apply modifications to the model
3349 mImpl->mOperationsPending = ALL_OPERATIONS;
3351 mImpl->RequestRelayout();
3354 // private : Update.
3356 void Controller::InsertText( const std::string& text, Controller::InsertType type )
3358 bool removedPrevious = false;
3359 bool removedSelected = false;
3360 bool maxLengthReached = false;
3362 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
3364 if( NULL == mImpl->mEventData )
3369 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
3370 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
3371 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3373 // TODO: At the moment the underline runs are only for pre-edit.
3374 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
3376 // Remove the previous InputMethodContext pre-edit.
3377 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
3379 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
3380 mImpl->mEventData->mPreEditLength,
3381 DONT_UPDATE_INPUT_STYLE );
3383 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
3384 mImpl->mEventData->mPreEditLength = 0u;
3388 // Remove the previous Selection.
3389 removedSelected = RemoveSelectedText();
3393 Vector<Character> utf32Characters;
3394 Length characterCount = 0u;
3398 // Convert text into UTF-32
3399 utf32Characters.Resize( text.size() );
3401 // This is a bit horrible but std::string returns a (signed) char*
3402 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
3404 // Transform a text array encoded in utf8 into an array encoded in utf32.
3405 // It returns the actual number of characters.
3406 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
3407 utf32Characters.Resize( characterCount );
3409 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
3410 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
3413 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
3415 // The placeholder text is no longer needed
3416 if( mImpl->IsShowingPlaceholderText() )
3421 mImpl->ChangeState( EventData::EDITING );
3423 // Handle the InputMethodContext (predicitive text) state changes
3424 if( COMMIT == type )
3426 // InputMethodContext is no longer handling key-events
3427 mImpl->ClearPreEditFlag();
3431 if( !mImpl->mEventData->mPreEditFlag )
3433 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
3435 // Record the start of the pre-edit text
3436 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
3439 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
3440 mImpl->mEventData->mPreEditFlag = true;
3442 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3445 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
3447 // Restrict new text to fit within Maximum characters setting.
3448 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
3449 maxLengthReached = ( characterCount > maxSizeOfNewText );
3451 // The cursor position.
3452 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3454 // Update the text's style.
3456 // Updates the text style runs by adding characters.
3457 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
3459 // Get the character index from the cursor index.
3460 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
3462 // Retrieve the text's style for the given index.
3464 mImpl->RetrieveDefaultInputStyle( style );
3465 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
3467 // Whether to add a new text color run.
3468 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor ) && !mImpl->mEventData->mInputStyle.isDefaultColor;
3470 // Whether to add a new font run.
3471 const bool addFontNameRun = ( style.familyName != mImpl->mEventData->mInputStyle.familyName ) && mImpl->mEventData->mInputStyle.isFamilyDefined;
3472 const bool addFontWeightRun = ( style.weight != mImpl->mEventData->mInputStyle.weight ) && mImpl->mEventData->mInputStyle.isWeightDefined;
3473 const bool addFontWidthRun = ( style.width != mImpl->mEventData->mInputStyle.width ) && mImpl->mEventData->mInputStyle.isWidthDefined;
3474 const bool addFontSlantRun = ( style.slant != mImpl->mEventData->mInputStyle.slant ) && mImpl->mEventData->mInputStyle.isSlantDefined;
3475 const bool addFontSizeRun = ( style.size != mImpl->mEventData->mInputStyle.size ) && mImpl->mEventData->mInputStyle.isSizeDefined ;
3480 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
3481 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
3483 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
3484 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
3485 colorRun.characterRun.characterIndex = cursorIndex;
3486 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3489 if( addFontNameRun ||
3495 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
3496 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
3498 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
3500 if( addFontNameRun )
3502 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
3503 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
3504 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
3505 fontDescriptionRun.familyDefined = true;
3507 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
3510 if( addFontWeightRun )
3512 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
3513 fontDescriptionRun.weightDefined = true;
3516 if( addFontWidthRun )
3518 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
3519 fontDescriptionRun.widthDefined = true;
3522 if( addFontSlantRun )
3524 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
3525 fontDescriptionRun.slantDefined = true;
3528 if( addFontSizeRun )
3530 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
3531 fontDescriptionRun.sizeDefined = true;
3534 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
3535 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3538 // Insert at current cursor position.
3539 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
3541 if( cursorIndex < numberOfCharactersInModel )
3543 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3547 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3550 // Mark the first paragraph to be updated.
3551 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3553 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3554 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3555 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
3556 mImpl->mTextUpdateInfo.mClearAll = true;
3560 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3561 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
3564 // Update the cursor index.
3565 cursorIndex += maxSizeOfNewText;
3567 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 );
3570 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
3571 mImpl->IsPlaceholderAvailable() )
3573 // Show place-holder if empty after removing the pre-edit text
3574 ShowPlaceholderText();
3575 mImpl->mEventData->mUpdateCursorPosition = true;
3576 mImpl->ClearPreEditFlag();
3578 else if( removedPrevious ||
3580 ( 0 != utf32Characters.Count() ) )
3582 // Queue an inserted event
3583 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
3585 mImpl->mEventData->mUpdateCursorPosition = true;
3586 if( removedSelected )
3588 mImpl->mEventData->mScrollAfterDelete = true;
3592 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3596 if( maxLengthReached )
3598 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
3600 mImpl->ResetInputMethodContext();
3602 if( NULL != mImpl->mEditableControlInterface )
3604 // Do this last since it provides callbacks into application code
3605 mImpl->mEditableControlInterface->MaxLengthReached();
3610 void Controller::PasteText( const std::string& stringToPaste )
3612 InsertText( stringToPaste, Text::Controller::COMMIT );
3613 mImpl->ChangeState( EventData::EDITING );
3614 mImpl->RequestRelayout();
3616 if( NULL != mImpl->mEditableControlInterface )
3618 // Do this last since it provides callbacks into application code
3619 mImpl->mEditableControlInterface->TextChanged();
3623 bool Controller::RemoveText( int cursorOffset,
3624 int numberOfCharacters,
3625 UpdateInputStyleType type )
3627 bool removed = false;
3629 if( NULL == mImpl->mEventData )
3634 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
3635 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
3637 if( !mImpl->IsShowingPlaceholderText() )
3639 // Delete at current cursor position
3640 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
3641 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3643 CharacterIndex cursorIndex = 0;
3645 // Validate the cursor position & number of characters
3646 if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
3648 cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
3651 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
3653 numberOfCharacters = currentText.Count() - cursorIndex;
3656 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.
3657 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
3659 // Mark the paragraphs to be updated.
3660 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3662 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3663 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3664 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
3665 mImpl->mTextUpdateInfo.mClearAll = true;
3669 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3670 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
3673 // Update the input style and remove the text's style before removing the text.
3675 if( UPDATE_INPUT_STYLE == type )
3677 // Keep a copy of the current input style.
3678 InputStyle currentInputStyle;
3679 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
3681 // Set first the default input style.
3682 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
3684 // Update the input style.
3685 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
3687 // Compare if the input style has changed.
3688 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
3690 if( hasInputStyleChanged )
3692 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
3693 // Queue the input style changed signal.
3694 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
3698 // Updates the text style runs by removing characters. Runs with no characters are removed.
3699 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
3701 // Remove the characters.
3702 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
3703 Vector<Character>::Iterator last = first + numberOfCharacters;
3705 currentText.Erase( first, last );
3707 // Cursor position retreat
3708 oldCursorIndex = cursorIndex;
3710 mImpl->mEventData->mScrollAfterDelete = true;
3712 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
3720 bool Controller::RemoveSelectedText()
3722 bool textRemoved( false );
3724 if( EventData::SELECTING == mImpl->mEventData->mState )
3726 std::string removedString;
3727 mImpl->RetrieveSelection( removedString, true );
3729 if( !removedString.empty() )
3732 mImpl->ChangeState( EventData::EDITING );
3739 // private : Relayout.
3741 bool Controller::DoRelayout( const Size& size,
3742 OperationsMask operationsRequired,
3745 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
3746 bool viewUpdated( false );
3748 // Calculate the operations to be done.
3749 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
3751 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
3752 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
3754 // Get the current layout size.
3755 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3757 if( NO_OPERATION != ( LAYOUT & operations ) )
3759 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
3761 // Some vectors with data needed to layout and reorder may be void
3762 // after the first time the text has been laid out.
3763 // Fill the vectors again.
3765 // Calculate the number of glyphs to layout.
3766 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
3767 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
3768 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
3769 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
3771 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
3772 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
3774 // Make sure the index is not out of bound
3775 if ( charactersToGlyph.Count() != glyphsPerCharacter.Count() ||
3776 requestedNumberOfCharacters > charactersToGlyph.Count() ||
3777 ( lastIndex >= charactersToGlyph.Count() && charactersToGlyph.Count() > 0u ) )
3779 std::string currentText;
3780 GetText( currentText );
3782 DALI_LOG_ERROR( "Controller::DoRelayout: Attempting to access invalid buffer\n" );
3783 DALI_LOG_ERROR( "Current text is: %s\n", currentText.c_str() );
3784 DALI_LOG_ERROR( "startIndex: %u, lastIndex: %u, requestedNumberOfCharacters: %u, charactersToGlyph.Count = %lu, glyphsPerCharacter.Count = %lu\n", startIndex, lastIndex, requestedNumberOfCharacters, charactersToGlyph.Count(), glyphsPerCharacter.Count());
3789 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
3790 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
3792 if( 0u == totalNumberOfGlyphs )
3794 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3796 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
3799 // Nothing else to do if there is no glyphs.
3800 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
3804 const Vector<LineBreakInfo>& lineBreakInfo = mImpl->mModel->mLogicalModel->mLineBreakInfo;
3805 const Vector<WordBreakInfo>& wordBreakInfo = mImpl->mModel->mLogicalModel->mWordBreakInfo;
3806 const Vector<CharacterDirection>& characterDirection = mImpl->mModel->mLogicalModel->mCharacterDirections;
3807 const Vector<GlyphInfo>& glyphs = mImpl->mModel->mVisualModel->mGlyphs;
3808 const Vector<CharacterIndex>& glyphsToCharactersMap = mImpl->mModel->mVisualModel->mGlyphsToCharacters;
3809 const Vector<Length>& charactersPerGlyph = mImpl->mModel->mVisualModel->mCharactersPerGlyph;
3810 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
3811 const float outlineWidth = static_cast<float>( mImpl->mModel->GetOutlineWidth() );
3813 // Set the layout parameters.
3814 Layout::Parameters layoutParameters( size,
3816 lineBreakInfo.Begin(),
3817 wordBreakInfo.Begin(),
3818 ( 0u != characterDirection.Count() ) ? characterDirection.Begin() : NULL,
3820 glyphsToCharactersMap.Begin(),
3821 charactersPerGlyph.Begin(),
3822 charactersToGlyphBuffer,
3823 glyphsPerCharacterBuffer,
3824 totalNumberOfGlyphs,
3825 mImpl->mModel->mHorizontalAlignment,
3826 mImpl->mModel->mLineWrapMode,
3828 mImpl->mModel->mIgnoreSpacesAfterText,
3829 mImpl->mModel->mMatchSystemLanguageDirection );
3831 // Resize the vector of positions to have the same size than the vector of glyphs.
3832 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
3833 glyphPositions.Resize( totalNumberOfGlyphs );
3835 // Whether the last character is a new paragraph character.
3836 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
3837 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
3839 // The initial glyph and the number of glyphs to layout.
3840 layoutParameters.startGlyphIndex = startGlyphIndex;
3841 layoutParameters.numberOfGlyphs = numberOfGlyphs;
3842 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
3843 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
3845 // Update the ellipsis
3846 bool elideTextEnabled = mImpl->mModel->mElideEnabled;
3848 if( NULL != mImpl->mEventData )
3850 if( mImpl->mEventData->mPlaceholderEllipsisFlag && mImpl->IsShowingPlaceholderText() )
3852 elideTextEnabled = mImpl->mEventData->mIsPlaceholderElideEnabled;
3854 else if( EventData::INACTIVE != mImpl->mEventData->mState )
3856 // Disable ellipsis when editing
3857 elideTextEnabled = false;
3860 // Reset the scroll position in inactive state
3861 if( elideTextEnabled && ( mImpl->mEventData->mState == EventData::INACTIVE ) )
3863 ResetScrollPosition();
3867 // Update the visual model.
3868 bool isAutoScrollEnabled = mImpl->mIsAutoScrollEnabled;
3870 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
3872 mImpl->mModel->mVisualModel->mLines,
3875 isAutoScrollEnabled );
3876 mImpl->mIsAutoScrollEnabled = isAutoScrollEnabled;
3878 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
3882 layoutSize = newLayoutSize;
3884 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
3886 mImpl->mIsTextDirectionRTL = false;
3889 // Reorder the lines
3890 if( NO_OPERATION != ( REORDER & operations ) )
3892 Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = mImpl->mModel->mLogicalModel->mBidirectionalParagraphInfo;
3893 Vector<BidirectionalLineInfoRun>& bidirectionalLineInfo = mImpl->mModel->mLogicalModel->mBidirectionalLineInfo;
3895 // Check first if there are paragraphs with bidirectional info.
3896 if( 0u != bidirectionalInfo.Count() )
3899 const Length numberOfLines = mImpl->mModel->mVisualModel->mLines.Count();
3901 // Reorder the lines.
3902 bidirectionalLineInfo.Reserve( numberOfLines ); // Reserve because is not known yet how many lines have right to left characters.
3903 ReorderLines( bidirectionalInfo,
3905 requestedNumberOfCharacters,
3906 mImpl->mModel->mVisualModel->mLines,
3907 bidirectionalLineInfo );
3909 // Set the bidirectional info per line into the layout parameters.
3910 layoutParameters.lineBidirectionalInfoRunsBuffer = bidirectionalLineInfo.Begin();
3911 layoutParameters.numberOfBidirectionalInfoRuns = bidirectionalLineInfo.Count();
3913 // Re-layout the text. Reorder those lines with right to left characters.
3914 mImpl->mLayoutEngine.ReLayoutRightToLeftLines( layoutParameters,
3916 requestedNumberOfCharacters,
3919 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && ( numberOfLines > 0 ) )
3921 const LineRun* const firstline = mImpl->mModel->mVisualModel->mLines.Begin();
3924 mImpl->mIsTextDirectionRTL = firstline->direction;
3930 // Sets the layout size.
3931 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3933 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
3938 if( NO_OPERATION != ( ALIGN & operations ) )
3940 // The laid-out lines.
3941 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
3943 // Need to align with the control's size as the text may contain lines
3944 // starting either with left to right text or right to left.
3945 mImpl->mLayoutEngine.Align( size,
3947 requestedNumberOfCharacters,
3948 mImpl->mModel->mHorizontalAlignment,
3950 mImpl->mModel->mAlignmentOffset,
3951 mImpl->mLayoutDirection,
3952 mImpl->mModel->mMatchSystemLanguageDirection );
3956 #if defined(DEBUG_ENABLED)
3957 std::string currentText;
3958 GetText( currentText );
3959 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mIsTextDirectionRTL[%s] [%s]\n", this, (mImpl->mIsTextDirectionRTL)?"true":"false", currentText.c_str() );
3961 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
3965 void Controller::CalculateVerticalOffset( const Size& controlSize )
3967 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3969 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
3971 // Get the line height of the default font.
3972 layoutSize.height = mImpl->GetDefaultFontLineHeight();
3975 switch( mImpl->mModel->mVerticalAlignment )
3977 case VerticalAlignment::TOP:
3979 mImpl->mModel->mScrollPosition.y = 0.f;
3982 case VerticalAlignment::CENTER:
3984 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
3987 case VerticalAlignment::BOTTOM:
3989 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
3995 // private : Events.
3997 void Controller::ProcessModifyEvents()
3999 Vector<ModifyEvent>& events = mImpl->mModifyEvents;
4001 if( 0u == events.Count() )
4007 for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
4008 endIt = events.End();
4012 const ModifyEvent& event = *it;
4014 if( ModifyEvent::TEXT_REPLACED == event.type )
4016 // A (single) replace event should come first, otherwise we wasted time processing NOOP events
4017 DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
4019 TextReplacedEvent();
4021 else if( ModifyEvent::TEXT_INSERTED == event.type )
4023 TextInsertedEvent();
4025 else if( ModifyEvent::TEXT_DELETED == event.type )
4027 // Placeholder-text cannot be deleted
4028 if( !mImpl->IsShowingPlaceholderText() )
4035 if( NULL != mImpl->mEventData )
4037 // When the text is being modified, delay cursor blinking
4038 mImpl->mEventData->mDecorator->DelayCursorBlink();
4040 // Update selection position after modifying the text
4041 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
4042 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
4045 // Discard temporary text
4049 void Controller::TextReplacedEvent()
4051 // The natural size needs to be re-calculated.
4052 mImpl->mRecalculateNaturalSize = true;
4054 // The text direction needs to be updated.
4055 mImpl->mUpdateTextDirection = true;
4057 // Apply modifications to the model
4058 mImpl->mOperationsPending = ALL_OPERATIONS;
4061 void Controller::TextInsertedEvent()
4063 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
4065 if( NULL == mImpl->mEventData )
4070 mImpl->mEventData->mCheckScrollAmount = true;
4072 // The natural size needs to be re-calculated.
4073 mImpl->mRecalculateNaturalSize = true;
4075 // The text direction needs to be updated.
4076 mImpl->mUpdateTextDirection = true;
4078 // Apply modifications to the model; TODO - Optimize this
4079 mImpl->mOperationsPending = ALL_OPERATIONS;
4082 void Controller::TextDeletedEvent()
4084 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
4086 if( NULL == mImpl->mEventData )
4091 mImpl->mEventData->mCheckScrollAmount = true;
4093 // The natural size needs to be re-calculated.
4094 mImpl->mRecalculateNaturalSize = true;
4096 // The text direction needs to be updated.
4097 mImpl->mUpdateTextDirection = true;
4099 // Apply modifications to the model; TODO - Optimize this
4100 mImpl->mOperationsPending = ALL_OPERATIONS;
4103 bool Controller::DeleteEvent( int keyCode )
4105 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p KeyCode : %d \n", this, keyCode );
4107 bool removed = false;
4109 if( NULL == mImpl->mEventData )
4114 // InputMethodContext is no longer handling key-events
4115 mImpl->ClearPreEditFlag();
4117 if( EventData::SELECTING == mImpl->mEventData->mState )
4119 removed = RemoveSelectedText();
4121 else if( ( mImpl->mEventData->mPrimaryCursorPosition > 0 ) && ( keyCode == Dali::DALI_KEY_BACKSPACE) )
4123 // Remove the character before the current cursor position
4124 removed = RemoveText( -1,
4126 UPDATE_INPUT_STYLE );
4128 else if( keyCode == Dali::DevelKey::DALI_KEY_DELETE )
4130 // Remove the character after the current cursor position
4131 removed = RemoveText( 0,
4133 UPDATE_INPUT_STYLE );
4138 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
4139 !mImpl->IsPlaceholderAvailable() )
4141 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
4145 ShowPlaceholderText();
4147 mImpl->mEventData->mUpdateCursorPosition = true;
4148 mImpl->mEventData->mScrollAfterDelete = true;
4154 // private : Helpers.
4156 void Controller::ResetText()
4159 mImpl->mModel->mLogicalModel->mText.Clear();
4161 // Reset the embedded images buffer.
4162 mImpl->mModel->mLogicalModel->ClearEmbeddedImages();
4164 // We have cleared everything including the placeholder-text
4165 mImpl->PlaceholderCleared();
4167 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4168 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4169 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
4171 // Clear any previous text.
4172 mImpl->mTextUpdateInfo.mClearAll = true;
4174 // The natural size needs to be re-calculated.
4175 mImpl->mRecalculateNaturalSize = true;
4177 // The text direction needs to be updated.
4178 mImpl->mUpdateTextDirection = true;
4180 // Apply modifications to the model
4181 mImpl->mOperationsPending = ALL_OPERATIONS;
4184 void Controller::ShowPlaceholderText()
4186 if( mImpl->IsPlaceholderAvailable() )
4188 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
4190 if( NULL == mImpl->mEventData )
4195 mImpl->mEventData->mIsShowingPlaceholderText = true;
4197 // Disable handles when showing place-holder text
4198 mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
4199 mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
4200 mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
4202 const char* text( NULL );
4205 // TODO - Switch Placeholder text when changing state
4206 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
4207 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
4209 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
4210 size = mImpl->mEventData->mPlaceholderTextActive.size();
4214 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
4215 size = mImpl->mEventData->mPlaceholderTextInactive.size();
4218 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4219 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4221 // Reset model for showing placeholder.
4222 mImpl->mModel->mLogicalModel->mText.Clear();
4223 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
4225 // Convert text into UTF-32
4226 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
4227 utf32Characters.Resize( size );
4229 // This is a bit horrible but std::string returns a (signed) char*
4230 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
4232 // Transform a text array encoded in utf8 into an array encoded in utf32.
4233 // It returns the actual number of characters.
4234 const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
4235 utf32Characters.Resize( characterCount );
4237 // The characters to be added.
4238 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
4240 // Reset the cursor position
4241 mImpl->mEventData->mPrimaryCursorPosition = 0;
4243 // The natural size needs to be re-calculated.
4244 mImpl->mRecalculateNaturalSize = true;
4246 // The text direction needs to be updated.
4247 mImpl->mUpdateTextDirection = true;
4249 // Apply modifications to the model
4250 mImpl->mOperationsPending = ALL_OPERATIONS;
4252 // Update the rest of the model during size negotiation
4253 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
4257 void Controller::ClearFontData()
4259 if( mImpl->mFontDefaults )
4261 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
4264 // Set flags to update the model.
4265 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4266 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4267 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
4269 mImpl->mTextUpdateInfo.mClearAll = true;
4270 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
4271 mImpl->mRecalculateNaturalSize = true;
4273 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
4279 UPDATE_LAYOUT_SIZE |
4284 void Controller::ClearStyleData()
4286 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
4287 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
4290 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
4292 // Reset the cursor position
4293 if( NULL != mImpl->mEventData )
4295 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
4297 // Update the cursor if it's in editing mode.
4298 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
4300 mImpl->mEventData->mUpdateCursorPosition = true;
4305 void Controller::ResetScrollPosition()
4307 if( NULL != mImpl->mEventData )
4309 // Reset the scroll position.
4310 mImpl->mModel->mScrollPosition = Vector2::ZERO;
4311 mImpl->mEventData->mScrollAfterUpdatePosition = true;
4315 void Controller::SetControlInterface( ControlInterface* controlInterface )
4317 mImpl->mControlInterface = controlInterface;
4320 bool Controller::ShouldClearFocusOnEscape() const
4322 return mImpl->mShouldClearFocusOnEscape;
4325 // private : Private contructors & copy operator.
4327 Controller::Controller()
4330 mImpl = new Controller::Impl( NULL, NULL );
4333 Controller::Controller( ControlInterface* controlInterface )
4335 mImpl = new Controller::Impl( controlInterface, NULL );
4338 Controller::Controller( ControlInterface* controlInterface,
4339 EditableControlInterface* editableControlInterface )
4341 mImpl = new Controller::Impl( controlInterface,
4342 editableControlInterface );
4345 // The copy constructor and operator are left unimplemented.
4347 // protected : Destructor.
4349 Controller::~Controller()
4356 } // namespace Toolkit