2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/text/text-controller.h>
25 #include <dali/public-api/adaptor-framework/key.h>
26 #include <dali/integration-api/debug.h>
27 #include <dali/devel-api/adaptor-framework/clipboard-event-notifier.h>
28 #include <dali/devel-api/text-abstraction/font-client.h>
29 #include <dali/devel-api/adaptor-framework/key-devel.h>
32 #include <dali-toolkit/public-api/controls/text-controls/placeholder-properties.h>
33 #include <dali-toolkit/internal/text/bidirectional-support.h>
34 #include <dali-toolkit/internal/text/character-set-conversion.h>
35 #include <dali-toolkit/internal/text/layouts/layout-parameters.h>
36 #include <dali-toolkit/internal/text/markup-processor.h>
37 #include <dali-toolkit/internal/text/multi-language-support.h>
38 #include <dali-toolkit/internal/text/text-controller-impl.h>
39 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
40 #include <dali-toolkit/internal/text/text-font-style.h>
45 #if defined(DEBUG_ENABLED)
46 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
49 const float MAX_FLOAT = std::numeric_limits<float>::max();
51 const std::string EMPTY_STRING("");
53 const std::string KEY_C_NAME = "c";
54 const std::string KEY_V_NAME = "v";
55 const std::string KEY_X_NAME = "x";
57 const char * const PLACEHOLDER_TEXT = "text";
58 const char * const PLACEHOLDER_TEXT_FOCUSED = "textFocused";
59 const char * const PLACEHOLDER_COLOR = "color";
60 const char * const PLACEHOLDER_FONT_FAMILY = "fontFamily";
61 const char * const PLACEHOLDER_FONT_STYLE = "fontStyle";
62 const char * const PLACEHOLDER_POINT_SIZE = "pointSize";
63 const char * const PLACEHOLDER_PIXEL_SIZE = "pixelSize";
64 const char * const PLACEHOLDER_ELLIPSIS = "ellipsis";
65 const unsigned int MAX_TEXT_LENGTH = 1024u * 32u;
67 float ConvertToEven( float value )
69 int intValue(static_cast<int>( value ));
70 return static_cast<float>( intValue + ( intValue & 1 ) );
73 int ConvertPixelToPint( float pixel )
75 unsigned int horizontalDpi = 0u;
76 unsigned int verticalDpi = 0u;
77 Dali::TextAbstraction::FontClient fontClient = Dali::TextAbstraction::FontClient::Get();
78 fontClient.GetDpi( horizontalDpi, verticalDpi );
80 return ( pixel * 72.f ) / static_cast< float >( horizontalDpi );
96 * @brief Adds a new font description run for the selected text.
98 * The new font parameters are added after the call to this method.
100 * @param[in] eventData The event data pointer.
101 * @param[in] logicalModel The logical model where to add the new font description run.
102 * @param[out] startOfSelectedText Index to the first selected character.
103 * @param[out] lengthOfSelectedText Number of selected characters.
105 FontDescriptionRun& UpdateSelectionFontStyleRun( EventData* eventData,
106 LogicalModelPtr logicalModel,
107 CharacterIndex& startOfSelectedText,
108 Length& lengthOfSelectedText )
110 const bool handlesCrossed = eventData->mLeftSelectionPosition > eventData->mRightSelectionPosition;
112 // Get start and end position of selection
113 startOfSelectedText = handlesCrossed ? eventData->mRightSelectionPosition : eventData->mLeftSelectionPosition;
114 lengthOfSelectedText = ( handlesCrossed ? eventData->mLeftSelectionPosition : eventData->mRightSelectionPosition ) - startOfSelectedText;
117 const VectorBase::SizeType numberOfRuns = logicalModel->mFontDescriptionRuns.Count();
118 logicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
120 FontDescriptionRun& fontDescriptionRun = *( logicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
122 fontDescriptionRun.characterRun.characterIndex = startOfSelectedText;
123 fontDescriptionRun.characterRun.numberOfCharacters = lengthOfSelectedText;
125 // Recalculate the selection highlight as the metrics may have changed.
126 eventData->mUpdateLeftSelectionPosition = true;
127 eventData->mUpdateRightSelectionPosition = true;
128 eventData->mUpdateHighlightBox = true;
130 return fontDescriptionRun;
133 // public : Constructor.
135 ControllerPtr Controller::New()
137 return ControllerPtr( new Controller() );
140 ControllerPtr Controller::New( ControlInterface* controlInterface )
142 return ControllerPtr( new Controller( controlInterface ) );
145 ControllerPtr Controller::New( ControlInterface* controlInterface,
146 EditableControlInterface* editableControlInterface )
148 return ControllerPtr( new Controller( controlInterface,
149 editableControlInterface ) );
152 // public : Configure the text controller.
154 void Controller::EnableTextInput( DecoratorPtr decorator, InputMethodContext& inputMethodContext )
158 delete mImpl->mEventData;
159 mImpl->mEventData = NULL;
161 // Nothing else to do.
165 if( NULL == mImpl->mEventData )
167 mImpl->mEventData = new EventData( decorator, inputMethodContext );
171 void Controller::SetGlyphType( TextAbstraction::GlyphType glyphType )
173 // Metrics for bitmap & vector based glyphs are different
174 mImpl->mMetrics->SetGlyphType( glyphType );
176 // Clear the font-specific data
179 mImpl->RequestRelayout();
182 void Controller::SetMarkupProcessorEnabled( bool enable )
184 if( enable != mImpl->mMarkupProcessorEnabled )
186 //If Text was already set, call the SetText again for enabling or disabling markup
187 mImpl->mMarkupProcessorEnabled = enable;
194 bool Controller::IsMarkupProcessorEnabled() const
196 return mImpl->mMarkupProcessorEnabled;
199 void Controller::SetAutoScrollEnabled( bool enable )
201 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled[%s] SingleBox[%s]-> [%p]\n", (enable)?"true":"false", ( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX)?"true":"false", this );
203 if( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX )
207 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled for SINGLE_LINE_BOX\n" );
208 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
218 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled Disabling autoscroll\n");
219 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
226 mImpl->mIsAutoScrollEnabled = enable;
227 mImpl->RequestRelayout();
231 DALI_LOG_WARNING( "Attempted AutoScrolling on a non SINGLE_LINE_BOX, request ignored\n" );
232 mImpl->mIsAutoScrollEnabled = false;
236 bool Controller::IsAutoScrollEnabled() const
238 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::IsAutoScrollEnabled[%s]\n", mImpl->mIsAutoScrollEnabled?"true":"false" );
240 return mImpl->mIsAutoScrollEnabled;
243 CharacterDirection Controller::GetAutoScrollDirection() const
245 return mImpl->mIsTextDirectionRTL;
248 float Controller::GetAutoScrollLineAlignment() const
252 if( mImpl->mModel->mVisualModel &&
253 ( 0u != mImpl->mModel->mVisualModel->mLines.Count() ) )
255 offset = ( *mImpl->mModel->mVisualModel->mLines.Begin() ).alignmentOffset;
261 void Controller::SetHorizontalScrollEnabled( bool enable )
263 if( ( NULL != mImpl->mEventData ) &&
264 mImpl->mEventData->mDecorator )
266 mImpl->mEventData->mDecorator->SetHorizontalScrollEnabled( enable );
269 bool Controller::IsHorizontalScrollEnabled() const
271 if( ( NULL != mImpl->mEventData ) &&
272 mImpl->mEventData->mDecorator )
274 return mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
280 void Controller::SetVerticalScrollEnabled( bool enable )
282 if( ( NULL != mImpl->mEventData ) &&
283 mImpl->mEventData->mDecorator )
285 if( mImpl->mEventData->mDecorator )
287 mImpl->mEventData->mDecorator->SetVerticalScrollEnabled( enable );
292 bool Controller::IsVerticalScrollEnabled() const
294 if( ( NULL != mImpl->mEventData ) &&
295 mImpl->mEventData->mDecorator )
297 return mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
303 void Controller::SetSmoothHandlePanEnabled( bool enable )
305 if( ( NULL != mImpl->mEventData ) &&
306 mImpl->mEventData->mDecorator )
308 mImpl->mEventData->mDecorator->SetSmoothHandlePanEnabled( enable );
312 bool Controller::IsSmoothHandlePanEnabled() const
314 if( ( NULL != mImpl->mEventData ) &&
315 mImpl->mEventData->mDecorator )
317 return mImpl->mEventData->mDecorator->IsSmoothHandlePanEnabled();
323 void Controller::SetMaximumNumberOfCharacters( Length maxCharacters )
325 mImpl->mMaximumNumberOfCharacters = std::min( maxCharacters, MAX_TEXT_LENGTH );
328 int Controller::GetMaximumNumberOfCharacters()
330 return mImpl->mMaximumNumberOfCharacters;
333 void Controller::SetEnableCursorBlink( bool enable )
335 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "TextInput disabled" );
337 if( NULL != mImpl->mEventData )
339 mImpl->mEventData->mCursorBlinkEnabled = enable;
342 mImpl->mEventData->mDecorator )
344 mImpl->mEventData->mDecorator->StopCursorBlink();
349 bool Controller::GetEnableCursorBlink() const
351 if( NULL != mImpl->mEventData )
353 return mImpl->mEventData->mCursorBlinkEnabled;
359 void Controller::SetMultiLineEnabled( bool enable )
361 const Layout::Engine::Type layout = enable ? Layout::Engine::MULTI_LINE_BOX : Layout::Engine::SINGLE_LINE_BOX;
363 if( layout != mImpl->mLayoutEngine.GetLayout() )
365 // Set the layout type.
366 mImpl->mLayoutEngine.SetLayout( layout );
368 // Set the flags to redo the layout operations
369 const OperationsMask layoutOperations = static_cast<OperationsMask>( LAYOUT |
374 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
375 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | layoutOperations );
377 // Need to recalculate natural size
378 mImpl->mRecalculateNaturalSize = true;
380 mImpl->RequestRelayout();
384 bool Controller::IsMultiLineEnabled() const
386 return Layout::Engine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
389 void Controller::SetHorizontalAlignment( Text::HorizontalAlignment::Type alignment )
391 if( alignment != mImpl->mModel->mHorizontalAlignment )
393 // Set the alignment.
394 mImpl->mModel->mHorizontalAlignment = alignment;
396 // Set the flag to redo the alignment operation.
397 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
399 mImpl->RequestRelayout();
403 Text::HorizontalAlignment::Type Controller::GetHorizontalAlignment() const
405 return mImpl->mModel->mHorizontalAlignment;
408 void Controller::SetVerticalAlignment( VerticalAlignment::Type alignment )
410 if( alignment != mImpl->mModel->mVerticalAlignment )
412 // Set the alignment.
413 mImpl->mModel->mVerticalAlignment = alignment;
415 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
417 mImpl->RequestRelayout();
421 VerticalAlignment::Type Controller::GetVerticalAlignment() const
423 return mImpl->mModel->mVerticalAlignment;
426 bool Controller::IsIgnoreSpacesAfterText() const
428 return mImpl->mModel->mIgnoreSpacesAfterText;
431 void Controller::SetIgnoreSpacesAfterText( bool ignore )
433 mImpl->mModel->mIgnoreSpacesAfterText = ignore;
436 bool Controller::IsMatchSystemLanguageDirection() const
438 return mImpl->mModel->mMatchSystemLanguageDirection;
441 void Controller::SetMatchSystemLanguageDirection( bool match )
443 mImpl->mModel->mMatchSystemLanguageDirection = match;
446 void Controller::SetLayoutDirection( Dali::LayoutDirection::Type layoutDirection )
448 mImpl->mLayoutDirection = layoutDirection;
451 bool Controller::IsShowingRealText() const
453 return mImpl->IsShowingRealText();
457 void Controller::SetLineWrapMode( Text::LineWrap::Mode lineWrapMode )
459 if( lineWrapMode != mImpl->mModel->mLineWrapMode )
461 // Set the text wrap mode.
462 mImpl->mModel->mLineWrapMode = lineWrapMode;
465 // Update Text layout for applying wrap mode
466 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
471 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
472 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
473 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
476 mImpl->RequestRelayout();
480 Text::LineWrap::Mode Controller::GetLineWrapMode() const
482 return mImpl->mModel->mLineWrapMode;
485 void Controller::SetTextElideEnabled( bool enabled )
487 mImpl->mModel->mElideEnabled = enabled;
490 bool Controller::IsTextElideEnabled() const
492 return mImpl->mModel->mElideEnabled;
495 void Controller::SetTextFitEnabled(bool enabled)
497 mImpl->mTextFitEnabled = enabled;
500 bool Controller::IsTextFitEnabled() const
502 return mImpl->mTextFitEnabled;
505 void Controller::SetTextFitMinSize( float minSize, FontSizeType type )
511 mImpl->mTextFitMinSize = minSize;
516 mImpl->mTextFitMinSize = ConvertPixelToPint( minSize );
522 float Controller::GetTextFitMinSize() const
524 return mImpl->mTextFitMinSize;
527 void Controller::SetTextFitMaxSize( float maxSize, FontSizeType type )
533 mImpl->mTextFitMaxSize = maxSize;
538 mImpl->mTextFitMaxSize = ConvertPixelToPint( maxSize );
544 float Controller::GetTextFitMaxSize() const
546 return mImpl->mTextFitMaxSize;
549 void Controller::SetTextFitStepSize( float step, FontSizeType type )
555 mImpl->mTextFitStepSize = step;
560 mImpl->mTextFitStepSize = ConvertPixelToPint( step );
566 float Controller::GetTextFitStepSize() const
568 return mImpl->mTextFitStepSize;
571 void Controller::SetTextFitContentSize(Vector2 size)
573 mImpl->mTextFitContentSize = size;
576 Vector2 Controller::GetTextFitContentSize() const
578 return mImpl->mTextFitContentSize;
581 void Controller::SetPlaceholderTextElideEnabled( bool enabled )
583 mImpl->mEventData->mIsPlaceholderElideEnabled = enabled;
584 mImpl->mEventData->mPlaceholderEllipsisFlag = true;
586 // Update placeholder if there is no text
587 if( mImpl->IsShowingPlaceholderText() ||
588 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
590 ShowPlaceholderText();
594 bool Controller::IsPlaceholderTextElideEnabled() const
596 return mImpl->mEventData->mIsPlaceholderElideEnabled;
599 void Controller::SetSelectionEnabled( bool enabled )
601 mImpl->mEventData->mSelectionEnabled = enabled;
604 bool Controller::IsSelectionEnabled() const
606 return mImpl->mEventData->mSelectionEnabled;
609 void Controller::SetShiftSelectionEnabled( bool enabled )
611 mImpl->mEventData->mShiftSelectionFlag = enabled;
614 bool Controller::IsShiftSelectionEnabled() const
616 return mImpl->mEventData->mShiftSelectionFlag;
619 void Controller::SetGrabHandleEnabled( bool enabled )
621 mImpl->mEventData->mGrabHandleEnabled = enabled;
624 bool Controller::IsGrabHandleEnabled() const
626 return mImpl->mEventData->mGrabHandleEnabled;
629 void Controller::SetGrabHandlePopupEnabled(bool enabled)
631 mImpl->mEventData->mGrabHandlePopupEnabled = enabled;
634 bool Controller::IsGrabHandlePopupEnabled() const
636 return mImpl->mEventData->mGrabHandlePopupEnabled;
641 void Controller::SetText( const std::string& text )
643 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" );
645 // Reset keyboard as text changed
646 mImpl->ResetInputMethodContext();
648 // Remove the previously set text and style.
654 CharacterIndex lastCursorIndex = 0u;
656 if( NULL != mImpl->mEventData )
658 // If popup shown then hide it by switching to Editing state
659 if( ( EventData::SELECTING == mImpl->mEventData->mState ) ||
660 ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
661 ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) ||
662 ( EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState ) )
664 mImpl->ChangeState( EventData::EDITING );
670 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mTextColor );
672 MarkupProcessData markupProcessData( mImpl->mModel->mLogicalModel->mColorRuns,
673 mImpl->mModel->mLogicalModel->mFontDescriptionRuns,
674 mImpl->mModel->mLogicalModel->mEmbeddedItems );
676 Length textSize = 0u;
677 const uint8_t* utf8 = NULL;
678 if( mImpl->mMarkupProcessorEnabled )
680 ProcessMarkupString( text, markupProcessData );
681 textSize = markupProcessData.markupProcessedText.size();
683 // This is a bit horrible but std::string returns a (signed) char*
684 utf8 = reinterpret_cast<const uint8_t*>( markupProcessData.markupProcessedText.c_str() );
688 textSize = text.size();
690 // This is a bit horrible but std::string returns a (signed) char*
691 utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
694 // Limit the text size. If the text size is too large, crash or deadlock will occur.
695 if( textSize > MAX_TEXT_LENGTH )
697 DALI_LOG_WARNING( "The text size is too large(%d), limit the length to 32,768u\n", textSize );
698 textSize = MAX_TEXT_LENGTH;
701 // Convert text into UTF-32
702 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
703 utf32Characters.Resize( textSize );
705 // Transform a text array encoded in utf8 into an array encoded in utf32.
706 // It returns the actual number of characters.
707 Length characterCount = Utf8ToUtf32( utf8, textSize, utf32Characters.Begin() );
708 utf32Characters.Resize( characterCount );
710 DALI_ASSERT_DEBUG( textSize >= characterCount && "Invalid UTF32 conversion length" );
711 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", this, textSize, mImpl->mModel->mLogicalModel->mText.Count() );
713 // The characters to be added.
714 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
716 // To reset the cursor position
717 lastCursorIndex = characterCount;
719 // Update the rest of the model during size negotiation
720 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
722 // The natural size needs to be re-calculated.
723 mImpl->mRecalculateNaturalSize = true;
725 // The text direction needs to be updated.
726 mImpl->mUpdateTextDirection = true;
728 // Apply modifications to the model
729 mImpl->mOperationsPending = ALL_OPERATIONS;
733 ShowPlaceholderText();
736 // Resets the cursor position.
737 ResetCursorPosition( lastCursorIndex );
739 // Scrolls the text to make the cursor visible.
740 ResetScrollPosition();
742 mImpl->RequestRelayout();
744 if( NULL != mImpl->mEventData )
746 // Cancel previously queued events
747 mImpl->mEventData->mEventQueue.clear();
750 // Do this last since it provides callbacks into application code.
751 if( NULL != mImpl->mEditableControlInterface )
753 mImpl->mEditableControlInterface->TextChanged();
757 void Controller::GetText( std::string& text ) const
759 if( !mImpl->IsShowingPlaceholderText() )
761 // Retrieves the text string.
762 mImpl->GetText( 0u, text );
766 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this );
770 void Controller::SetPlaceholderText( PlaceholderType type, const std::string& text )
772 if( NULL != mImpl->mEventData )
774 if( PLACEHOLDER_TYPE_INACTIVE == type )
776 mImpl->mEventData->mPlaceholderTextInactive = text;
780 mImpl->mEventData->mPlaceholderTextActive = text;
783 // Update placeholder if there is no text
784 if( mImpl->IsShowingPlaceholderText() ||
785 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
787 ShowPlaceholderText();
792 void Controller::GetPlaceholderText( PlaceholderType type, std::string& text ) const
794 if( NULL != mImpl->mEventData )
796 if( PLACEHOLDER_TYPE_INACTIVE == type )
798 text = mImpl->mEventData->mPlaceholderTextInactive;
802 text = mImpl->mEventData->mPlaceholderTextActive;
807 void Controller::UpdateAfterFontChange( const std::string& newDefaultFont )
809 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
811 if( !mImpl->mFontDefaults->familyDefined ) // If user defined font then should not update when system font changes
813 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
814 mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
818 mImpl->RequestRelayout();
822 // public : Default style & Input style
824 void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
826 if( NULL == mImpl->mFontDefaults )
828 mImpl->mFontDefaults = new FontDefaults();
831 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
832 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
833 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
835 // Clear the font-specific data
838 mImpl->RequestRelayout();
841 const std::string& Controller::GetDefaultFontFamily() const
843 if( NULL != mImpl->mFontDefaults )
845 return mImpl->mFontDefaults->mFontDescription.family;
851 void Controller::SetPlaceholderFontFamily( const std::string& placeholderTextFontFamily )
853 if( NULL != mImpl->mEventData )
855 if( NULL == mImpl->mEventData->mPlaceholderFont )
857 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
860 mImpl->mEventData->mPlaceholderFont->mFontDescription.family = placeholderTextFontFamily;
861 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetPlaceholderFontFamily %s\n", placeholderTextFontFamily.c_str());
862 mImpl->mEventData->mPlaceholderFont->familyDefined = !placeholderTextFontFamily.empty();
864 mImpl->RequestRelayout();
868 const std::string& Controller::GetPlaceholderFontFamily() const
870 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
872 return mImpl->mEventData->mPlaceholderFont->mFontDescription.family;
878 void Controller::SetDefaultFontWeight( FontWeight weight )
880 if( NULL == mImpl->mFontDefaults )
882 mImpl->mFontDefaults = new FontDefaults();
885 mImpl->mFontDefaults->mFontDescription.weight = weight;
886 mImpl->mFontDefaults->weightDefined = true;
888 // Clear the font-specific data
891 mImpl->RequestRelayout();
894 bool Controller::IsDefaultFontWeightDefined() const
896 if( NULL != mImpl->mFontDefaults )
898 return mImpl->mFontDefaults->weightDefined;
904 FontWeight Controller::GetDefaultFontWeight() const
906 if( NULL != mImpl->mFontDefaults )
908 return mImpl->mFontDefaults->mFontDescription.weight;
911 return TextAbstraction::FontWeight::NORMAL;
914 void Controller::SetPlaceholderTextFontWeight( FontWeight weight )
916 if( NULL != mImpl->mEventData )
918 if( NULL == mImpl->mEventData->mPlaceholderFont )
920 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
923 mImpl->mEventData->mPlaceholderFont->mFontDescription.weight = weight;
924 mImpl->mEventData->mPlaceholderFont->weightDefined = true;
926 mImpl->RequestRelayout();
930 bool Controller::IsPlaceholderTextFontWeightDefined() const
932 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
934 return mImpl->mEventData->mPlaceholderFont->weightDefined;
939 FontWeight Controller::GetPlaceholderTextFontWeight() const
941 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
943 return mImpl->mEventData->mPlaceholderFont->mFontDescription.weight;
946 return TextAbstraction::FontWeight::NORMAL;
949 void Controller::SetDefaultFontWidth( FontWidth width )
951 if( NULL == mImpl->mFontDefaults )
953 mImpl->mFontDefaults = new FontDefaults();
956 mImpl->mFontDefaults->mFontDescription.width = width;
957 mImpl->mFontDefaults->widthDefined = true;
959 // Clear the font-specific data
962 mImpl->RequestRelayout();
965 bool Controller::IsDefaultFontWidthDefined() const
967 if( NULL != mImpl->mFontDefaults )
969 return mImpl->mFontDefaults->widthDefined;
975 FontWidth Controller::GetDefaultFontWidth() const
977 if( NULL != mImpl->mFontDefaults )
979 return mImpl->mFontDefaults->mFontDescription.width;
982 return TextAbstraction::FontWidth::NORMAL;
985 void Controller::SetPlaceholderTextFontWidth( FontWidth width )
987 if( NULL != mImpl->mEventData )
989 if( NULL == mImpl->mEventData->mPlaceholderFont )
991 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
994 mImpl->mEventData->mPlaceholderFont->mFontDescription.width = width;
995 mImpl->mEventData->mPlaceholderFont->widthDefined = true;
997 mImpl->RequestRelayout();
1001 bool Controller::IsPlaceholderTextFontWidthDefined() const
1003 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1005 return mImpl->mEventData->mPlaceholderFont->widthDefined;
1010 FontWidth Controller::GetPlaceholderTextFontWidth() const
1012 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1014 return mImpl->mEventData->mPlaceholderFont->mFontDescription.width;
1017 return TextAbstraction::FontWidth::NORMAL;
1020 void Controller::SetDefaultFontSlant( FontSlant slant )
1022 if( NULL == mImpl->mFontDefaults )
1024 mImpl->mFontDefaults = new FontDefaults();
1027 mImpl->mFontDefaults->mFontDescription.slant = slant;
1028 mImpl->mFontDefaults->slantDefined = true;
1030 // Clear the font-specific data
1033 mImpl->RequestRelayout();
1036 bool Controller::IsDefaultFontSlantDefined() const
1038 if( NULL != mImpl->mFontDefaults )
1040 return mImpl->mFontDefaults->slantDefined;
1045 FontSlant Controller::GetDefaultFontSlant() const
1047 if( NULL != mImpl->mFontDefaults )
1049 return mImpl->mFontDefaults->mFontDescription.slant;
1052 return TextAbstraction::FontSlant::NORMAL;
1055 void Controller::SetPlaceholderTextFontSlant( FontSlant slant )
1057 if( NULL != mImpl->mEventData )
1059 if( NULL == mImpl->mEventData->mPlaceholderFont )
1061 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
1064 mImpl->mEventData->mPlaceholderFont->mFontDescription.slant = slant;
1065 mImpl->mEventData->mPlaceholderFont->slantDefined = true;
1067 mImpl->RequestRelayout();
1071 bool Controller::IsPlaceholderTextFontSlantDefined() const
1073 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1075 return mImpl->mEventData->mPlaceholderFont->slantDefined;
1080 FontSlant Controller::GetPlaceholderTextFontSlant() const
1082 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1084 return mImpl->mEventData->mPlaceholderFont->mFontDescription.slant;
1087 return TextAbstraction::FontSlant::NORMAL;
1090 void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
1092 if( NULL == mImpl->mFontDefaults )
1094 mImpl->mFontDefaults = new FontDefaults();
1101 mImpl->mFontDefaults->mDefaultPointSize = fontSize;
1102 mImpl->mFontDefaults->sizeDefined = true;
1107 // Point size = Pixel size * 72.f / DPI
1108 unsigned int horizontalDpi = 0u;
1109 unsigned int verticalDpi = 0u;
1110 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1111 fontClient.GetDpi( horizontalDpi, verticalDpi );
1113 mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
1114 mImpl->mFontDefaults->sizeDefined = true;
1119 // Clear the font-specific data
1122 mImpl->RequestRelayout();
1125 float Controller::GetDefaultFontSize( FontSizeType type ) const
1128 if( NULL != mImpl->mFontDefaults )
1134 value = mImpl->mFontDefaults->mDefaultPointSize;
1139 // Pixel size = Point size * DPI / 72.f
1140 unsigned int horizontalDpi = 0u;
1141 unsigned int verticalDpi = 0u;
1142 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1143 fontClient.GetDpi( horizontalDpi, verticalDpi );
1145 value = mImpl->mFontDefaults->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1155 void Controller::SetPlaceholderTextFontSize( float fontSize, FontSizeType type )
1157 if( NULL != mImpl->mEventData )
1159 if( NULL == mImpl->mEventData->mPlaceholderFont )
1161 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
1168 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = fontSize;
1169 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1170 mImpl->mEventData->mIsPlaceholderPixelSize = false; // Font size flag
1175 // Point size = Pixel size * 72.f / DPI
1176 unsigned int horizontalDpi = 0u;
1177 unsigned int verticalDpi = 0u;
1178 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1179 fontClient.GetDpi( horizontalDpi, verticalDpi );
1181 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
1182 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1183 mImpl->mEventData->mIsPlaceholderPixelSize = true; // Font size flag
1188 mImpl->RequestRelayout();
1192 float Controller::GetPlaceholderTextFontSize( FontSizeType type ) const
1195 if( NULL != mImpl->mEventData )
1201 if( NULL != mImpl->mEventData->mPlaceholderFont )
1203 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize;
1207 // If the placeholder text font size is not set, then return the default font size.
1208 value = GetDefaultFontSize( POINT_SIZE );
1214 if( NULL != mImpl->mEventData->mPlaceholderFont )
1216 // Pixel size = Point size * DPI / 72.f
1217 unsigned int horizontalDpi = 0u;
1218 unsigned int verticalDpi = 0u;
1219 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1220 fontClient.GetDpi( horizontalDpi, verticalDpi );
1222 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1226 // If the placeholder text font size is not set, then return the default font size.
1227 value = GetDefaultFontSize( PIXEL_SIZE );
1238 void Controller::SetDefaultColor( const Vector4& color )
1240 mImpl->mTextColor = color;
1242 if( !mImpl->IsShowingPlaceholderText() )
1244 mImpl->mModel->mVisualModel->SetTextColor( color );
1246 mImpl->RequestRelayout();
1250 const Vector4& Controller::GetDefaultColor() const
1252 return mImpl->mTextColor;
1255 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
1257 if( NULL != mImpl->mEventData )
1259 mImpl->mEventData->mPlaceholderTextColor = textColor;
1262 if( mImpl->IsShowingPlaceholderText() )
1264 mImpl->mModel->mVisualModel->SetTextColor( textColor );
1265 mImpl->RequestRelayout();
1269 const Vector4& Controller::GetPlaceholderTextColor() const
1271 if( NULL != mImpl->mEventData )
1273 return mImpl->mEventData->mPlaceholderTextColor;
1276 return Color::BLACK;
1279 void Controller::SetShadowOffset( const Vector2& shadowOffset )
1281 mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
1283 mImpl->RequestRelayout();
1286 const Vector2& Controller::GetShadowOffset() const
1288 return mImpl->mModel->mVisualModel->GetShadowOffset();
1291 void Controller::SetShadowColor( const Vector4& shadowColor )
1293 mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
1295 mImpl->RequestRelayout();
1298 const Vector4& Controller::GetShadowColor() const
1300 return mImpl->mModel->mVisualModel->GetShadowColor();
1303 void Controller::SetShadowBlurRadius( const float& shadowBlurRadius )
1305 if ( fabsf( GetShadowBlurRadius() - shadowBlurRadius ) > Math::MACHINE_EPSILON_1 )
1307 mImpl->mModel->mVisualModel->SetShadowBlurRadius( shadowBlurRadius );
1309 mImpl->RequestRelayout();
1313 const float& Controller::GetShadowBlurRadius() const
1315 return mImpl->mModel->mVisualModel->GetShadowBlurRadius();
1318 void Controller::SetUnderlineColor( const Vector4& color )
1320 mImpl->mModel->mVisualModel->SetUnderlineColor( color );
1322 mImpl->RequestRelayout();
1325 const Vector4& Controller::GetUnderlineColor() const
1327 return mImpl->mModel->mVisualModel->GetUnderlineColor();
1330 void Controller::SetUnderlineEnabled( bool enabled )
1332 mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
1334 mImpl->RequestRelayout();
1337 bool Controller::IsUnderlineEnabled() const
1339 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
1342 void Controller::SetUnderlineHeight( float height )
1344 mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
1346 mImpl->RequestRelayout();
1349 float Controller::GetUnderlineHeight() const
1351 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
1354 void Controller::SetOutlineColor( const Vector4& color )
1356 mImpl->mModel->mVisualModel->SetOutlineColor( color );
1358 mImpl->RequestRelayout();
1361 const Vector4& Controller::GetOutlineColor() const
1363 return mImpl->mModel->mVisualModel->GetOutlineColor();
1366 void Controller::SetOutlineWidth( uint16_t width )
1368 mImpl->mModel->mVisualModel->SetOutlineWidth( width );
1370 mImpl->RequestRelayout();
1373 uint16_t Controller::GetOutlineWidth() const
1375 return mImpl->mModel->mVisualModel->GetOutlineWidth();
1378 void Controller::SetBackgroundColor( const Vector4& color )
1380 mImpl->mModel->mVisualModel->SetBackgroundColor( color );
1382 mImpl->RequestRelayout();
1385 const Vector4& Controller::GetBackgroundColor() const
1387 return mImpl->mModel->mVisualModel->GetBackgroundColor();
1390 void Controller::SetBackgroundEnabled( bool enabled )
1392 mImpl->mModel->mVisualModel->SetBackgroundEnabled( enabled );
1394 mImpl->RequestRelayout();
1397 bool Controller::IsBackgroundEnabled() const
1399 return mImpl->mModel->mVisualModel->IsBackgroundEnabled();
1402 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
1404 if( NULL == mImpl->mEmbossDefaults )
1406 mImpl->mEmbossDefaults = new EmbossDefaults();
1409 mImpl->mEmbossDefaults->properties = embossProperties;
1412 const std::string& Controller::GetDefaultEmbossProperties() const
1414 if( NULL != mImpl->mEmbossDefaults )
1416 return mImpl->mEmbossDefaults->properties;
1419 return EMPTY_STRING;
1422 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
1424 if( NULL == mImpl->mOutlineDefaults )
1426 mImpl->mOutlineDefaults = new OutlineDefaults();
1429 mImpl->mOutlineDefaults->properties = outlineProperties;
1432 const std::string& Controller::GetDefaultOutlineProperties() const
1434 if( NULL != mImpl->mOutlineDefaults )
1436 return mImpl->mOutlineDefaults->properties;
1439 return EMPTY_STRING;
1442 bool Controller::SetDefaultLineSpacing( float lineSpacing )
1444 if( std::fabs( lineSpacing - mImpl->mLayoutEngine.GetDefaultLineSpacing() ) > Math::MACHINE_EPSILON_1000 )
1446 mImpl->mLayoutEngine.SetDefaultLineSpacing(lineSpacing);
1447 mImpl->mRecalculateNaturalSize = true;
1453 float Controller::GetDefaultLineSpacing() const
1455 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
1458 void Controller::SetInputColor( const Vector4& color )
1460 if( NULL != mImpl->mEventData )
1462 mImpl->mEventData->mInputStyle.textColor = color;
1463 mImpl->mEventData->mInputStyle.isDefaultColor = false;
1465 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1467 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
1469 // Get start and end position of selection
1470 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
1471 const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
1473 // Add the color run.
1474 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1475 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
1477 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
1478 colorRun.color = color;
1479 colorRun.characterRun.characterIndex = startOfSelectedText;
1480 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1482 // Request to relayout.
1483 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1484 mImpl->RequestRelayout();
1486 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1487 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1488 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1493 const Vector4& Controller::GetInputColor() const
1495 if( NULL != mImpl->mEventData )
1497 return mImpl->mEventData->mInputStyle.textColor;
1500 // Return the default text's color if there is no EventData.
1501 return mImpl->mTextColor;
1505 void Controller::SetInputFontFamily( const std::string& fontFamily )
1507 if( NULL != mImpl->mEventData )
1509 mImpl->mEventData->mInputStyle.familyName = fontFamily;
1510 mImpl->mEventData->mInputStyle.isFamilyDefined = true;
1512 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1514 CharacterIndex startOfSelectedText = 0u;
1515 Length lengthOfSelectedText = 0u;
1516 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1517 mImpl->mModel->mLogicalModel,
1518 startOfSelectedText,
1519 lengthOfSelectedText );
1521 fontDescriptionRun.familyLength = fontFamily.size();
1522 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
1523 memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength );
1524 fontDescriptionRun.familyDefined = true;
1526 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
1528 // Request to relayout.
1529 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1534 UPDATE_LAYOUT_SIZE |
1537 mImpl->mRecalculateNaturalSize = true;
1538 mImpl->RequestRelayout();
1540 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1541 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1542 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1544 // As the font changes, recalculate the handle positions is needed.
1545 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1546 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1547 mImpl->mEventData->mUpdateHighlightBox = true;
1548 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1553 const std::string& Controller::GetInputFontFamily() const
1555 if( NULL != mImpl->mEventData )
1557 return mImpl->mEventData->mInputStyle.familyName;
1560 // Return the default font's family if there is no EventData.
1561 return GetDefaultFontFamily();
1564 void Controller::SetInputFontWeight( FontWeight weight )
1566 if( NULL != mImpl->mEventData )
1568 mImpl->mEventData->mInputStyle.weight = weight;
1569 mImpl->mEventData->mInputStyle.isWeightDefined = true;
1571 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1573 CharacterIndex startOfSelectedText = 0u;
1574 Length lengthOfSelectedText = 0u;
1575 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1576 mImpl->mModel->mLogicalModel,
1577 startOfSelectedText,
1578 lengthOfSelectedText );
1580 fontDescriptionRun.weight = weight;
1581 fontDescriptionRun.weightDefined = true;
1583 // Request to relayout.
1584 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1589 UPDATE_LAYOUT_SIZE |
1592 mImpl->mRecalculateNaturalSize = true;
1593 mImpl->RequestRelayout();
1595 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1596 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1597 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1599 // As the font might change, recalculate the handle positions is needed.
1600 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1601 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1602 mImpl->mEventData->mUpdateHighlightBox = true;
1603 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1608 bool Controller::IsInputFontWeightDefined() const
1610 bool defined = false;
1612 if( NULL != mImpl->mEventData )
1614 defined = mImpl->mEventData->mInputStyle.isWeightDefined;
1620 FontWeight Controller::GetInputFontWeight() const
1622 if( NULL != mImpl->mEventData )
1624 return mImpl->mEventData->mInputStyle.weight;
1627 return GetDefaultFontWeight();
1630 void Controller::SetInputFontWidth( FontWidth width )
1632 if( NULL != mImpl->mEventData )
1634 mImpl->mEventData->mInputStyle.width = width;
1635 mImpl->mEventData->mInputStyle.isWidthDefined = true;
1637 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1639 CharacterIndex startOfSelectedText = 0u;
1640 Length lengthOfSelectedText = 0u;
1641 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1642 mImpl->mModel->mLogicalModel,
1643 startOfSelectedText,
1644 lengthOfSelectedText );
1646 fontDescriptionRun.width = width;
1647 fontDescriptionRun.widthDefined = true;
1649 // Request to relayout.
1650 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1655 UPDATE_LAYOUT_SIZE |
1658 mImpl->mRecalculateNaturalSize = true;
1659 mImpl->RequestRelayout();
1661 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1662 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1663 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1665 // As the font might change, recalculate the handle positions is needed.
1666 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1667 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1668 mImpl->mEventData->mUpdateHighlightBox = true;
1669 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1674 bool Controller::IsInputFontWidthDefined() const
1676 bool defined = false;
1678 if( NULL != mImpl->mEventData )
1680 defined = mImpl->mEventData->mInputStyle.isWidthDefined;
1686 FontWidth Controller::GetInputFontWidth() const
1688 if( NULL != mImpl->mEventData )
1690 return mImpl->mEventData->mInputStyle.width;
1693 return GetDefaultFontWidth();
1696 void Controller::SetInputFontSlant( FontSlant slant )
1698 if( NULL != mImpl->mEventData )
1700 mImpl->mEventData->mInputStyle.slant = slant;
1701 mImpl->mEventData->mInputStyle.isSlantDefined = true;
1703 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1705 CharacterIndex startOfSelectedText = 0u;
1706 Length lengthOfSelectedText = 0u;
1707 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1708 mImpl->mModel->mLogicalModel,
1709 startOfSelectedText,
1710 lengthOfSelectedText );
1712 fontDescriptionRun.slant = slant;
1713 fontDescriptionRun.slantDefined = true;
1715 // Request to relayout.
1716 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1721 UPDATE_LAYOUT_SIZE |
1724 mImpl->mRecalculateNaturalSize = true;
1725 mImpl->RequestRelayout();
1727 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1728 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1729 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1731 // As the font might change, recalculate the handle positions is needed.
1732 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1733 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1734 mImpl->mEventData->mUpdateHighlightBox = true;
1735 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1740 bool Controller::IsInputFontSlantDefined() const
1742 bool defined = false;
1744 if( NULL != mImpl->mEventData )
1746 defined = mImpl->mEventData->mInputStyle.isSlantDefined;
1752 FontSlant Controller::GetInputFontSlant() const
1754 if( NULL != mImpl->mEventData )
1756 return mImpl->mEventData->mInputStyle.slant;
1759 return GetDefaultFontSlant();
1762 void Controller::SetInputFontPointSize( float size )
1764 if( NULL != mImpl->mEventData )
1766 mImpl->mEventData->mInputStyle.size = size;
1767 mImpl->mEventData->mInputStyle.isSizeDefined = true;
1769 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1771 CharacterIndex startOfSelectedText = 0u;
1772 Length lengthOfSelectedText = 0u;
1773 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1774 mImpl->mModel->mLogicalModel,
1775 startOfSelectedText,
1776 lengthOfSelectedText );
1778 fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
1779 fontDescriptionRun.sizeDefined = true;
1781 // Request to relayout.
1782 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1787 UPDATE_LAYOUT_SIZE |
1790 mImpl->mRecalculateNaturalSize = true;
1791 mImpl->RequestRelayout();
1793 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1794 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1795 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1797 // As the font might change, recalculate the handle positions is needed.
1798 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1799 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1800 mImpl->mEventData->mUpdateHighlightBox = true;
1801 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1806 float Controller::GetInputFontPointSize() const
1808 if( NULL != mImpl->mEventData )
1810 return mImpl->mEventData->mInputStyle.size;
1813 // Return the default font's point size if there is no EventData.
1814 return GetDefaultFontSize( Text::Controller::POINT_SIZE );
1817 void Controller::SetInputLineSpacing( float lineSpacing )
1819 if( NULL != mImpl->mEventData )
1821 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1822 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1826 float Controller::GetInputLineSpacing() const
1828 if( NULL != mImpl->mEventData )
1830 return mImpl->mEventData->mInputStyle.lineSpacing;
1836 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1838 if( NULL != mImpl->mEventData )
1840 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1844 const std::string& Controller::GetInputShadowProperties() const
1846 if( NULL != mImpl->mEventData )
1848 return mImpl->mEventData->mInputStyle.shadowProperties;
1851 return EMPTY_STRING;
1854 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1856 if( NULL != mImpl->mEventData )
1858 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1862 const std::string& Controller::GetInputUnderlineProperties() const
1864 if( NULL != mImpl->mEventData )
1866 return mImpl->mEventData->mInputStyle.underlineProperties;
1869 return EMPTY_STRING;
1872 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
1874 if( NULL != mImpl->mEventData )
1876 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1880 const std::string& Controller::GetInputEmbossProperties() const
1882 if( NULL != mImpl->mEventData )
1884 return mImpl->mEventData->mInputStyle.embossProperties;
1887 return GetDefaultEmbossProperties();
1890 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
1892 if( NULL != mImpl->mEventData )
1894 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1898 const std::string& Controller::GetInputOutlineProperties() const
1900 if( NULL != mImpl->mEventData )
1902 return mImpl->mEventData->mInputStyle.outlineProperties;
1905 return GetDefaultOutlineProperties();
1908 void Controller::SetInputModePassword( bool passwordInput )
1910 if( NULL != mImpl->mEventData )
1912 mImpl->mEventData->mPasswordInput = passwordInput;
1916 bool Controller::IsInputModePassword()
1918 if( NULL != mImpl->mEventData )
1920 return mImpl->mEventData->mPasswordInput;
1925 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
1927 if( NULL != mImpl->mEventData )
1929 mImpl->mEventData->mDoubleTapAction = action;
1933 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1935 NoTextTap::Action action = NoTextTap::NO_ACTION;
1937 if( NULL != mImpl->mEventData )
1939 action = mImpl->mEventData->mDoubleTapAction;
1945 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
1947 if( NULL != mImpl->mEventData )
1949 mImpl->mEventData->mLongPressAction = action;
1953 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1955 NoTextTap::Action action = NoTextTap::NO_ACTION;
1957 if( NULL != mImpl->mEventData )
1959 action = mImpl->mEventData->mLongPressAction;
1965 bool Controller::IsUnderlineSetByString()
1967 return mImpl->mUnderlineSetByString;
1970 void Controller::UnderlineSetByString( bool setByString )
1972 mImpl->mUnderlineSetByString = setByString;
1975 bool Controller::IsShadowSetByString()
1977 return mImpl->mShadowSetByString;
1980 void Controller::ShadowSetByString( bool setByString )
1982 mImpl->mShadowSetByString = setByString;
1985 bool Controller::IsOutlineSetByString()
1987 return mImpl->mOutlineSetByString;
1990 void Controller::OutlineSetByString( bool setByString )
1992 mImpl->mOutlineSetByString = setByString;
1995 bool Controller::IsFontStyleSetByString()
1997 return mImpl->mFontStyleSetByString;
2000 void Controller::FontStyleSetByString( bool setByString )
2002 mImpl->mFontStyleSetByString = setByString;
2005 // public : Queries & retrieves.
2007 Layout::Engine& Controller::GetLayoutEngine()
2009 return mImpl->mLayoutEngine;
2012 View& Controller::GetView()
2014 return mImpl->mView;
2017 Vector3 Controller::GetNaturalSize()
2019 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
2020 Vector3 naturalSize;
2022 // Make sure the model is up-to-date before layouting
2023 ProcessModifyEvents();
2025 if( mImpl->mRecalculateNaturalSize )
2027 // Operations that can be done only once until the text changes.
2028 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2035 GET_GLYPH_METRICS );
2037 // Set the update info to relayout the whole text.
2038 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2039 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2041 // Make sure the model is up-to-date before layouting
2042 mImpl->UpdateModel( onlyOnceOperations );
2044 // Layout the text for the new width.
2045 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT | REORDER );
2047 // Store the actual control's size to restore later.
2048 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
2050 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
2051 static_cast<OperationsMask>( onlyOnceOperations |
2053 naturalSize.GetVectorXY() );
2055 // Do not do again the only once operations.
2056 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2058 // Do the size related operations again.
2059 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
2062 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
2064 // Stores the natural size to avoid recalculate it again
2065 // unless the text/style changes.
2066 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
2068 mImpl->mRecalculateNaturalSize = false;
2070 // Clear the update info. This info will be set the next time the text is updated.
2071 mImpl->mTextUpdateInfo.Clear();
2072 mImpl->mTextUpdateInfo.mClearAll = true;
2074 // Restore the actual control's size.
2075 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
2077 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
2081 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
2083 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
2086 naturalSize.x = ConvertToEven( naturalSize.x );
2087 naturalSize.y = ConvertToEven( naturalSize.y );
2092 bool Controller::CheckForTextFit( float pointSize, Size& layoutSize )
2095 mImpl->mFontDefaults->mFitPointSize = pointSize;
2096 mImpl->mFontDefaults->sizeDefined = true;
2099 // Operations that can be done only once until the text changes.
2100 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2107 GET_GLYPH_METRICS );
2109 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2110 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2112 // Make sure the model is up-to-date before layouting
2113 mImpl->UpdateModel( onlyOnceOperations );
2115 DoRelayout( Size( layoutSize.width, MAX_FLOAT ),
2116 static_cast<OperationsMask>( onlyOnceOperations | LAYOUT),
2119 // Clear the update info. This info will be set the next time the text is updated.
2120 mImpl->mTextUpdateInfo.Clear();
2121 mImpl->mTextUpdateInfo.mClearAll = true;
2123 if( textSize.width > layoutSize.width || textSize.height > layoutSize.height )
2130 void Controller::FitPointSizeforLayout( Size layoutSize )
2132 const OperationsMask operations = mImpl->mOperationsPending;
2133 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
2135 bool actualellipsis = mImpl->mModel->mElideEnabled;
2136 float minPointSize = mImpl->mTextFitMinSize;
2137 float maxPointSize = mImpl->mTextFitMaxSize;
2138 float pointInterval = mImpl->mTextFitStepSize;
2140 mImpl->mModel->mElideEnabled = false;
2141 Vector<float> pointSizeArray;
2144 if( pointInterval < 1.f )
2146 mImpl->mTextFitStepSize = pointInterval = 1.0f;
2149 pointSizeArray.Reserve( static_cast< unsigned int >( ceil( ( maxPointSize - minPointSize ) / pointInterval ) ) );
2151 for( float i = minPointSize; i < maxPointSize; i += pointInterval )
2153 pointSizeArray.PushBack( i );
2156 pointSizeArray.PushBack( maxPointSize );
2158 int bestSizeIndex = 0;
2159 int min = bestSizeIndex + 1;
2160 int max = pointSizeArray.Size() - 1;
2163 int destI = ( min + max ) / 2;
2165 if( CheckForTextFit( pointSizeArray[destI], layoutSize ) )
2167 bestSizeIndex = min;
2173 bestSizeIndex = max;
2177 mImpl->mModel->mElideEnabled = actualellipsis;
2178 mImpl->mFontDefaults->mFitPointSize = pointSizeArray[bestSizeIndex];
2179 mImpl->mFontDefaults->sizeDefined = true;
2184 float Controller::GetHeightForWidth( float width )
2186 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
2187 // Make sure the model is up-to-date before layouting
2188 ProcessModifyEvents();
2191 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ||
2192 mImpl->mTextUpdateInfo.mFullRelayoutNeeded ||
2193 mImpl->mTextUpdateInfo.mClearAll )
2195 // Operations that can be done only once until the text changes.
2196 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2203 GET_GLYPH_METRICS );
2205 // Set the update info to relayout the whole text.
2206 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2207 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2209 // Make sure the model is up-to-date before layouting
2210 mImpl->UpdateModel( onlyOnceOperations );
2213 // Layout the text for the new width.
2214 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
2216 // Store the actual control's width.
2217 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
2219 DoRelayout( Size( width, MAX_FLOAT ),
2220 static_cast<OperationsMask>( onlyOnceOperations |
2224 // Do not do again the only once operations.
2225 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2227 // Do the size related operations again.
2228 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
2232 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
2234 // Clear the update info. This info will be set the next time the text is updated.
2235 mImpl->mTextUpdateInfo.Clear();
2236 mImpl->mTextUpdateInfo.mClearAll = true;
2238 // Restore the actual control's width.
2239 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
2241 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
2245 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
2246 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
2249 return layoutSize.height;
2252 int Controller::GetLineCount( float width )
2254 GetHeightForWidth( width );
2255 int numberofLines = mImpl->mModel->GetNumberOfLines();
2256 return numberofLines;
2259 const ModelInterface* const Controller::GetTextModel() const
2261 return mImpl->mModel.Get();
2264 float Controller::GetScrollAmountByUserInput()
2266 float scrollAmount = 0.0f;
2268 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
2270 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
2271 mImpl->mEventData->mCheckScrollAmount = false;
2273 return scrollAmount;
2276 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
2278 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
2281 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
2282 layoutHeight = layout.height;
2283 scrollPosition = mImpl->mModel->mScrollPosition.y;
2284 isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
2288 void Controller::SetHiddenInputOption(const Property::Map& options )
2290 if( NULL == mImpl->mHiddenInput )
2292 mImpl->mHiddenInput = new HiddenText( this );
2294 mImpl->mHiddenInput->SetProperties(options);
2297 void Controller::GetHiddenInputOption(Property::Map& options )
2299 if( NULL != mImpl->mHiddenInput )
2301 mImpl->mHiddenInput->GetProperties(options);
2305 void Controller::SetPlaceholderProperty( const Property::Map& map )
2307 const Property::Map::SizeType count = map.Count();
2309 for( Property::Map::SizeType position = 0; position < count; ++position )
2311 KeyValuePair keyValue = map.GetKeyValue( position );
2312 Property::Key& key = keyValue.first;
2313 Property::Value& value = keyValue.second;
2315 if( key == Toolkit::Text::PlaceHolder::Property::TEXT || key == PLACEHOLDER_TEXT )
2317 std::string text = "";
2319 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
2321 else if( key == Toolkit::Text::PlaceHolder::Property::TEXT_FOCUSED || key == PLACEHOLDER_TEXT_FOCUSED )
2323 std::string text = "";
2325 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
2327 else if( key == Toolkit::Text::PlaceHolder::Property::COLOR || key == PLACEHOLDER_COLOR )
2330 value.Get( textColor );
2331 if( GetPlaceholderTextColor() != textColor )
2333 SetPlaceholderTextColor( textColor );
2336 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_FAMILY || key == PLACEHOLDER_FONT_FAMILY )
2338 std::string fontFamily = "";
2339 value.Get( fontFamily );
2340 SetPlaceholderFontFamily( fontFamily );
2342 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_STYLE || key == PLACEHOLDER_FONT_STYLE )
2344 SetFontStyleProperty( this, value, Text::FontStyle::PLACEHOLDER );
2346 else if( key == Toolkit::Text::PlaceHolder::Property::POINT_SIZE || key == PLACEHOLDER_POINT_SIZE )
2349 value.Get( pointSize );
2350 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
2352 SetPlaceholderTextFontSize( pointSize, Text::Controller::POINT_SIZE );
2355 else if( key == Toolkit::Text::PlaceHolder::Property::PIXEL_SIZE || key == PLACEHOLDER_PIXEL_SIZE )
2358 value.Get( pixelSize );
2359 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
2361 SetPlaceholderTextFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
2364 else if( key == Toolkit::Text::PlaceHolder::Property::ELLIPSIS || key == PLACEHOLDER_ELLIPSIS )
2367 value.Get( ellipsis );
2368 SetPlaceholderTextElideEnabled( ellipsis );
2373 void Controller::GetPlaceholderProperty( Property::Map& map )
2375 if( NULL != mImpl->mEventData )
2377 if( !mImpl->mEventData->mPlaceholderTextActive.empty() )
2379 map[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = mImpl->mEventData->mPlaceholderTextActive;
2381 if( !mImpl->mEventData->mPlaceholderTextInactive.empty() )
2383 map[ Text::PlaceHolder::Property::TEXT ] = mImpl->mEventData->mPlaceholderTextInactive;
2386 map[ Text::PlaceHolder::Property::COLOR ] = mImpl->mEventData->mPlaceholderTextColor;
2387 map[ Text::PlaceHolder::Property::FONT_FAMILY ] = GetPlaceholderFontFamily();
2389 Property::Value fontStyleMapGet;
2390 GetFontStyleProperty( this, fontStyleMapGet, Text::FontStyle::PLACEHOLDER );
2391 map[ Text::PlaceHolder::Property::FONT_STYLE ] = fontStyleMapGet;
2393 // Choose font size : POINT_SIZE or PIXEL_SIZE
2394 if( !mImpl->mEventData->mIsPlaceholderPixelSize )
2396 map[ Text::PlaceHolder::Property::POINT_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE );
2400 map[ Text::PlaceHolder::Property::PIXEL_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE );
2403 if( mImpl->mEventData->mPlaceholderEllipsisFlag )
2405 map[ Text::PlaceHolder::Property::ELLIPSIS ] = IsPlaceholderTextElideEnabled();
2410 Toolkit::DevelText::TextDirection::Type Controller::GetTextDirection()
2412 // Make sure the model is up-to-date before layouting
2413 ProcessModifyEvents();
2415 if ( mImpl->mUpdateTextDirection )
2417 // Operations that can be done only once until the text changes.
2418 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2425 GET_GLYPH_METRICS );
2427 // Set the update info to relayout the whole text.
2428 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2429 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2431 // Make sure the model is up-to-date before layouting
2432 mImpl->UpdateModel( onlyOnceOperations );
2434 Vector3 naturalSize;
2435 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
2436 static_cast<OperationsMask>( onlyOnceOperations |
2437 LAYOUT | REORDER | UPDATE_DIRECTION ),
2438 naturalSize.GetVectorXY() );
2440 // Do not do again the only once operations.
2441 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2443 // Clear the update info. This info will be set the next time the text is updated.
2444 mImpl->mTextUpdateInfo.Clear();
2446 mImpl->mUpdateTextDirection = false;
2449 return mImpl->mIsTextDirectionRTL ? Toolkit::DevelText::TextDirection::RIGHT_TO_LEFT : Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT;
2452 Toolkit::DevelText::VerticalLineAlignment::Type Controller::GetVerticalLineAlignment() const
2454 return mImpl->mModel->GetVerticalLineAlignment();
2457 void Controller::SetVerticalLineAlignment( Toolkit::DevelText::VerticalLineAlignment::Type alignment )
2459 mImpl->mModel->mVerticalLineAlignment = alignment;
2462 // public : Relayout.
2464 Controller::UpdateTextType Controller::Relayout( const Size& size, Dali::LayoutDirection::Type layoutDirection )
2466 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
2468 UpdateTextType updateTextType = NONE_UPDATED;
2470 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
2472 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
2474 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
2475 updateTextType = MODEL_UPDATED;
2478 // Clear the update info. This info will be set the next time the text is updated.
2479 mImpl->mTextUpdateInfo.Clear();
2481 // Not worth to relayout if width or height is equal to zero.
2482 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
2484 return updateTextType;
2487 // Whether a new size has been set.
2488 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
2492 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
2494 if( ( 0 == mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd ) &&
2495 ( 0 == mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) &&
2496 ( ( mImpl->mModel->mVisualModel->mControlSize.width < Math::MACHINE_EPSILON_1000 ) || ( mImpl->mModel->mVisualModel->mControlSize.height < Math::MACHINE_EPSILON_1000 ) ) )
2498 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
2501 // Layout operations that need to be done if the size changes.
2502 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2505 UPDATE_LAYOUT_SIZE |
2507 // Set the update info to relayout the whole text.
2508 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2509 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2511 // Store the size used to layout the text.
2512 mImpl->mModel->mVisualModel->mControlSize = size;
2515 // Whether there are modify events.
2516 if( 0u != mImpl->mModifyEvents.Count() )
2518 // Style operations that need to be done if the text is modified.
2519 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2523 // Set the update info to elide the text.
2524 if( mImpl->mModel->mElideEnabled ||
2525 ( ( NULL != mImpl->mEventData ) && mImpl->mEventData->mIsPlaceholderElideEnabled ) )
2527 // Update Text layout for applying elided
2528 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2531 UPDATE_LAYOUT_SIZE |
2533 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2534 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2537 if( mImpl->mModel->mMatchSystemLanguageDirection && mImpl->mLayoutDirection != layoutDirection )
2539 // Clear the update info. This info will be set the next time the text is updated.
2540 mImpl->mTextUpdateInfo.mClearAll = true;
2541 // Apply modifications to the model
2542 // Shape the text again is needed because characters like '()[]{}' have to be mirrored and the glyphs generated again.
2543 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2550 mImpl->mLayoutDirection = layoutDirection;
2553 // Make sure the model is up-to-date before layouting.
2554 ProcessModifyEvents();
2555 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
2559 updated = DoRelayout( size,
2560 mImpl->mOperationsPending,
2561 layoutSize ) || updated;
2566 updateTextType = MODEL_UPDATED;
2569 // Do not re-do any operation until something changes.
2570 mImpl->mOperationsPending = NO_OPERATION;
2571 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
2573 // Whether the text control is editable
2574 const bool isEditable = NULL != mImpl->mEventData;
2576 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
2578 if( newSize && isEditable )
2580 offset = mImpl->mModel->mScrollPosition;
2583 if( !isEditable || !IsMultiLineEnabled() )
2585 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
2586 CalculateVerticalOffset( size );
2593 // If there is a new size, the scroll position needs to be clamped.
2594 mImpl->ClampHorizontalScroll( layoutSize );
2596 // Update the decorator's positions is needed if there is a new size.
2597 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
2600 // Move the cursor, grab handle etc.
2601 if( mImpl->ProcessInputEvents() )
2603 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
2607 // Clear the update info. This info will be set the next time the text is updated.
2608 mImpl->mTextUpdateInfo.Clear();
2609 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
2611 return updateTextType;
2614 void Controller::RequestRelayout()
2616 mImpl->RequestRelayout();
2619 // public : Input style change signals.
2621 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
2623 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
2626 void Controller::ProcessInputStyleChangedSignals()
2628 if( NULL == mImpl->mEventData )
2634 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
2635 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
2639 const InputStyle::Mask mask = *it;
2641 if( NULL != mImpl->mEditableControlInterface )
2643 // Emit the input style changed signal.
2644 mImpl->mEditableControlInterface->InputStyleChanged( mask );
2648 mImpl->mEventData->mInputStyleChangedQueue.Clear();
2651 // public : Text-input Event Queuing.
2653 void Controller::KeyboardFocusGainEvent()
2655 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
2657 if( NULL != mImpl->mEventData )
2659 if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
2660 ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
2662 mImpl->ChangeState( EventData::EDITING );
2663 mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
2664 mImpl->mEventData->mUpdateInputStyle = true;
2665 mImpl->mEventData->mScrollAfterUpdatePosition = true;
2667 mImpl->NotifyInputMethodContextMultiLineStatus();
2668 if( mImpl->IsShowingPlaceholderText() )
2670 // Show alternative placeholder-text when editing
2671 ShowPlaceholderText();
2674 mImpl->RequestRelayout();
2678 void Controller::KeyboardFocusLostEvent()
2680 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
2682 if( NULL != mImpl->mEventData )
2684 if( EventData::INTERRUPTED != mImpl->mEventData->mState )
2686 mImpl->ChangeState( EventData::INACTIVE );
2688 if( !mImpl->IsShowingRealText() )
2690 // Revert to regular placeholder-text when not editing
2691 ShowPlaceholderText();
2695 mImpl->RequestRelayout();
2698 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
2700 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
2702 bool textChanged = false;
2703 bool relayoutNeeded = false;
2705 if( ( NULL != mImpl->mEventData ) &&
2706 ( keyEvent.state == KeyEvent::Down ) )
2708 int keyCode = keyEvent.keyCode;
2709 const std::string& keyString = keyEvent.keyPressed;
2710 const std::string keyName = keyEvent.keyPressedName;
2712 const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
2714 // Pre-process to separate modifying events from non-modifying input events.
2717 // In some platforms arrive key events with no key code.
2721 else if( Dali::DALI_KEY_ESCAPE == keyCode || Dali::DALI_KEY_BACK == keyCode || Dali::DALI_KEY_SEARCH == keyCode )
2726 else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) ||
2727 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
2728 ( Dali::DALI_KEY_CURSOR_UP == keyCode ) ||
2729 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) )
2731 // If don't have any text, do nothing.
2732 if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
2737 uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition;
2738 uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2739 uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition );
2740 uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines();
2742 // Logic to determine whether this text control will lose focus or not.
2743 if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2744 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2745 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) ||
2746 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) ||
2747 ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) ||
2748 ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) )
2750 // Release the active highlight.
2751 if( mImpl->mEventData->mState == EventData::SELECTING )
2753 mImpl->ChangeState( EventData::EDITING );
2755 // Update selection position.
2756 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2757 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2758 mImpl->mEventData->mUpdateCursorPosition = true;
2759 mImpl->RequestRelayout();
2764 mImpl->mEventData->mCheckScrollAmount = true;
2765 Event event( Event::CURSOR_KEY_EVENT );
2766 event.p1.mInt = keyCode;
2767 event.p2.mBool = keyEvent.IsShiftModifier();
2768 mImpl->mEventData->mEventQueue.push_back( event );
2770 // Will request for relayout.
2771 relayoutNeeded = true;
2773 else if ( Dali::DevelKey::DALI_KEY_CONTROL_LEFT == keyCode || Dali::DevelKey::DALI_KEY_CONTROL_RIGHT == keyCode )
2775 // Left or Right Control key event is received before Ctrl-C/V/X key event is received
2776 // If not handle it here, any selected text will be deleted
2781 else if ( keyEvent.IsCtrlModifier() )
2783 bool consumed = false;
2784 if (keyName == KEY_C_NAME)
2786 // Ctrl-C to copy the selected text
2787 TextPopupButtonTouched( Toolkit::TextSelectionPopup::COPY );
2790 else if (keyName == KEY_V_NAME)
2792 // Ctrl-V to paste the copied text
2793 TextPopupButtonTouched( Toolkit::TextSelectionPopup::PASTE );
2796 else if (keyName == KEY_X_NAME)
2798 // Ctrl-X to cut the selected text
2799 TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
2804 else if( ( Dali::DALI_KEY_BACKSPACE == keyCode ) ||
2805 ( Dali::DevelKey::DALI_KEY_DELETE == keyCode ) )
2807 textChanged = DeleteEvent( keyCode );
2809 // Will request for relayout.
2810 relayoutNeeded = true;
2812 else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
2813 IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
2814 IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
2816 // Power key/Menu/Home key behaviour does not allow edit mode to resume.
2817 mImpl->ChangeState( EventData::INACTIVE );
2819 // Will request for relayout.
2820 relayoutNeeded = true;
2822 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2824 else if( ( Dali::DALI_KEY_SHIFT_LEFT == keyCode ) || ( Dali::DALI_KEY_SHIFT_RIGHT == keyCode ) )
2826 // 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
2827 // and a character is typed after the type of a upper case latin character.
2832 else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
2834 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2840 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
2842 if( !keyString.empty() )
2844 // InputMethodContext is no longer handling key-events
2845 mImpl->ClearPreEditFlag();
2847 InsertText( keyString, COMMIT );
2851 // Will request for relayout.
2852 relayoutNeeded = true;
2857 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
2858 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
2860 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
2861 ( Dali::DALI_KEY_SHIFT_RIGHT != keyCode ) &&
2862 ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
2863 ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
2865 // Should not change the state if the key is the shift send by the InputMethodContext.
2866 // Otherwise, when the state is SELECTING the text controller can't send the right
2867 // surrounding info to the InputMethodContext.
2868 mImpl->ChangeState( EventData::EDITING );
2870 // Will request for relayout.
2871 relayoutNeeded = true;
2874 if( relayoutNeeded )
2876 mImpl->RequestRelayout();
2881 ( NULL != mImpl->mEditableControlInterface ) )
2883 // Do this last since it provides callbacks into application code
2884 mImpl->mEditableControlInterface->TextChanged();
2890 void Controller::TapEvent( unsigned int tapCount, float x, float y )
2892 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
2894 if( NULL != mImpl->mEventData )
2896 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
2897 EventData::State state( mImpl->mEventData->mState );
2898 bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
2900 if( mImpl->IsClipboardVisible() )
2902 if( EventData::INACTIVE == state || EventData::EDITING == state)
2904 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2906 relayoutNeeded = true;
2908 else if( 1u == tapCount )
2910 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
2912 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
2915 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
2917 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2918 relayoutNeeded = true;
2922 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
2924 // Hide placeholder text
2928 if( EventData::INACTIVE == state )
2930 mImpl->ChangeState( EventData::EDITING );
2932 else if( !mImpl->IsClipboardEmpty() )
2934 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
2936 relayoutNeeded = true;
2939 else if( 2u == tapCount )
2941 if( mImpl->mEventData->mSelectionEnabled &&
2942 mImpl->IsShowingRealText() )
2944 relayoutNeeded = true;
2945 mImpl->mEventData->mIsLeftHandleSelected = true;
2946 mImpl->mEventData->mIsRightHandleSelected = true;
2950 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
2951 if( relayoutNeeded )
2953 Event event( Event::TAP_EVENT );
2954 event.p1.mUint = tapCount;
2955 event.p2.mFloat = x;
2956 event.p3.mFloat = y;
2957 mImpl->mEventData->mEventQueue.push_back( event );
2959 mImpl->RequestRelayout();
2963 // Reset keyboard as tap event has occurred.
2964 mImpl->ResetInputMethodContext();
2967 void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
2969 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
2971 if( NULL != mImpl->mEventData )
2973 Event event( Event::PAN_EVENT );
2974 event.p1.mInt = state;
2975 event.p2.mFloat = displacement.x;
2976 event.p3.mFloat = displacement.y;
2977 mImpl->mEventData->mEventQueue.push_back( event );
2979 mImpl->RequestRelayout();
2983 void Controller::LongPressEvent( Gesture::State state, float x, float y )
2985 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
2987 if( ( state == Gesture::Started ) &&
2988 ( NULL != mImpl->mEventData ) )
2990 // The 1st long-press on inactive text-field is treated as tap
2991 if( EventData::INACTIVE == mImpl->mEventData->mState )
2993 mImpl->ChangeState( EventData::EDITING );
2995 Event event( Event::TAP_EVENT );
2997 event.p2.mFloat = x;
2998 event.p3.mFloat = y;
2999 mImpl->mEventData->mEventQueue.push_back( event );
3001 mImpl->RequestRelayout();
3003 else if( !mImpl->IsShowingRealText() )
3005 Event event( Event::LONG_PRESS_EVENT );
3006 event.p1.mInt = state;
3007 event.p2.mFloat = x;
3008 event.p3.mFloat = y;
3009 mImpl->mEventData->mEventQueue.push_back( event );
3010 mImpl->RequestRelayout();
3012 else if( !mImpl->IsClipboardVisible() )
3014 // Reset the InputMethodContext to commit the pre-edit before selecting the text.
3015 mImpl->ResetInputMethodContext();
3017 Event event( Event::LONG_PRESS_EVENT );
3018 event.p1.mInt = state;
3019 event.p2.mFloat = x;
3020 event.p3.mFloat = y;
3021 mImpl->mEventData->mEventQueue.push_back( event );
3022 mImpl->RequestRelayout();
3024 mImpl->mEventData->mIsLeftHandleSelected = true;
3025 mImpl->mEventData->mIsRightHandleSelected = true;
3030 void Controller::SelectEvent( float x, float y, bool selectAll )
3032 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
3034 if( NULL != mImpl->mEventData )
3038 Event event( Event::SELECT_ALL );
3039 mImpl->mEventData->mEventQueue.push_back( event );
3043 Event event( Event::SELECT );
3044 event.p2.mFloat = x;
3045 event.p3.mFloat = y;
3046 mImpl->mEventData->mEventQueue.push_back( event );
3049 mImpl->mEventData->mCheckScrollAmount = true;
3050 mImpl->mEventData->mIsLeftHandleSelected = true;
3051 mImpl->mEventData->mIsRightHandleSelected = true;
3052 mImpl->RequestRelayout();
3056 InputMethodContext::CallbackData Controller::OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
3058 // Whether the text needs to be relaid-out.
3059 bool requestRelayout = false;
3061 // Whether to retrieve the text and cursor position to be sent to the InputMethodContext.
3062 bool retrieveText = false;
3063 bool retrieveCursor = false;
3065 switch( inputMethodContextEvent.eventName )
3067 case InputMethodContext::COMMIT:
3069 InsertText( inputMethodContextEvent.predictiveString, Text::Controller::COMMIT );
3070 requestRelayout = true;
3071 retrieveCursor = true;
3074 case InputMethodContext::PRE_EDIT:
3076 InsertText( inputMethodContextEvent.predictiveString, Text::Controller::PRE_EDIT );
3077 requestRelayout = true;
3078 retrieveCursor = true;
3081 case InputMethodContext::DELETE_SURROUNDING:
3083 const bool textDeleted = RemoveText( inputMethodContextEvent.cursorOffset,
3084 inputMethodContextEvent.numberOfChars,
3085 DONT_UPDATE_INPUT_STYLE );
3089 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3090 !mImpl->IsPlaceholderAvailable() )
3092 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3096 ShowPlaceholderText();
3098 mImpl->mEventData->mUpdateCursorPosition = true;
3099 mImpl->mEventData->mScrollAfterDelete = true;
3101 requestRelayout = true;
3105 case InputMethodContext::GET_SURROUNDING:
3107 retrieveText = true;
3108 retrieveCursor = true;
3111 case InputMethodContext::PRIVATE_COMMAND:
3113 // PRIVATECOMMAND event is just for getting the private command message
3114 retrieveText = true;
3115 retrieveCursor = true;
3118 case InputMethodContext::VOID:
3125 if( requestRelayout )
3127 mImpl->mOperationsPending = ALL_OPERATIONS;
3128 mImpl->RequestRelayout();
3132 CharacterIndex cursorPosition = 0u;
3133 Length numberOfWhiteSpaces = 0u;
3135 if( retrieveCursor )
3137 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
3139 cursorPosition = mImpl->GetLogicalCursorPosition();
3141 if( cursorPosition < numberOfWhiteSpaces )
3143 cursorPosition = 0u;
3147 cursorPosition -= numberOfWhiteSpaces;
3153 if( !mImpl->IsShowingPlaceholderText() )
3155 // Retrieves the normal text string.
3156 mImpl->GetText( numberOfWhiteSpaces, text );
3160 // When the current text is Placeholder Text, the surrounding text should be empty string.
3161 // It means DALi should send empty string ("") to IME.
3166 InputMethodContext::CallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
3168 if( requestRelayout &&
3169 ( NULL != mImpl->mEditableControlInterface ) )
3171 // Do this last since it provides callbacks into application code
3172 mImpl->mEditableControlInterface->TextChanged();
3175 return callbackData;
3178 void Controller::PasteClipboardItemEvent()
3180 // Retrieve the clipboard contents first
3181 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
3182 std::string stringToPaste( notifier.GetContent() );
3184 // Commit the current pre-edit text; the contents of the clipboard should be appended
3185 mImpl->ResetInputMethodContext();
3187 // Temporary disable hiding clipboard
3188 mImpl->SetClipboardHideEnable( false );
3191 PasteText( stringToPaste );
3193 mImpl->SetClipboardHideEnable( true );
3196 // protected : Inherit from Text::Decorator::ControllerInterface.
3198 void Controller::GetTargetSize( Vector2& targetSize )
3200 targetSize = mImpl->mModel->mVisualModel->mControlSize;
3203 void Controller::AddDecoration( Actor& actor, bool needsClipping )
3205 if( NULL != mImpl->mEditableControlInterface )
3207 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
3211 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
3213 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
3215 if( NULL != mImpl->mEventData )
3217 switch( handleType )
3221 Event event( Event::GRAB_HANDLE_EVENT );
3222 event.p1.mUint = state;
3223 event.p2.mFloat = x;
3224 event.p3.mFloat = y;
3226 mImpl->mEventData->mEventQueue.push_back( event );
3229 case LEFT_SELECTION_HANDLE:
3231 Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
3232 event.p1.mUint = state;
3233 event.p2.mFloat = x;
3234 event.p3.mFloat = y;
3236 mImpl->mEventData->mEventQueue.push_back( event );
3239 case RIGHT_SELECTION_HANDLE:
3241 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
3242 event.p1.mUint = state;
3243 event.p2.mFloat = x;
3244 event.p3.mFloat = y;
3246 mImpl->mEventData->mEventQueue.push_back( event );
3249 case LEFT_SELECTION_HANDLE_MARKER:
3250 case RIGHT_SELECTION_HANDLE_MARKER:
3252 // Markers do not move the handles.
3255 case HANDLE_TYPE_COUNT:
3257 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
3261 mImpl->RequestRelayout();
3265 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
3267 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
3269 if( NULL == mImpl->mEventData )
3276 case Toolkit::TextSelectionPopup::CUT:
3278 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
3279 mImpl->mOperationsPending = ALL_OPERATIONS;
3281 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3282 !mImpl->IsPlaceholderAvailable() )
3284 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3288 ShowPlaceholderText();
3291 mImpl->mEventData->mUpdateCursorPosition = true;
3292 mImpl->mEventData->mScrollAfterDelete = true;
3294 mImpl->RequestRelayout();
3296 if( NULL != mImpl->mEditableControlInterface )
3298 mImpl->mEditableControlInterface->TextChanged();
3302 case Toolkit::TextSelectionPopup::COPY:
3304 mImpl->SendSelectionToClipboard( false ); // Text not modified
3306 mImpl->mEventData->mUpdateCursorPosition = true;
3308 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
3311 case Toolkit::TextSelectionPopup::PASTE:
3313 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
3316 case Toolkit::TextSelectionPopup::SELECT:
3318 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
3320 if( mImpl->mEventData->mSelectionEnabled )
3322 // Creates a SELECT event.
3323 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
3327 case Toolkit::TextSelectionPopup::SELECT_ALL:
3329 // Creates a SELECT_ALL event
3330 SelectEvent( 0.f, 0.f, true );
3333 case Toolkit::TextSelectionPopup::CLIPBOARD:
3335 mImpl->ShowClipboard();
3338 case Toolkit::TextSelectionPopup::NONE:
3346 void Controller::DisplayTimeExpired()
3348 mImpl->mEventData->mUpdateCursorPosition = true;
3349 // Apply modifications to the model
3350 mImpl->mOperationsPending = ALL_OPERATIONS;
3352 mImpl->RequestRelayout();
3355 // private : Update.
3357 void Controller::InsertText( const std::string& text, Controller::InsertType type )
3359 bool removedPrevious = false;
3360 bool removedSelected = false;
3361 bool maxLengthReached = false;
3363 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
3365 if( NULL == mImpl->mEventData )
3370 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
3371 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
3372 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3374 // TODO: At the moment the underline runs are only for pre-edit.
3375 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
3377 // Remove the previous InputMethodContext pre-edit.
3378 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
3380 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
3381 mImpl->mEventData->mPreEditLength,
3382 DONT_UPDATE_INPUT_STYLE );
3384 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
3385 mImpl->mEventData->mPreEditLength = 0u;
3389 // Remove the previous Selection.
3390 removedSelected = RemoveSelectedText();
3394 Vector<Character> utf32Characters;
3395 Length characterCount = 0u;
3399 // Convert text into UTF-32
3400 utf32Characters.Resize( text.size() );
3402 // This is a bit horrible but std::string returns a (signed) char*
3403 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
3405 // Transform a text array encoded in utf8 into an array encoded in utf32.
3406 // It returns the actual number of characters.
3407 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
3408 utf32Characters.Resize( characterCount );
3410 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
3411 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
3414 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
3416 // The placeholder text is no longer needed
3417 if( mImpl->IsShowingPlaceholderText() )
3422 mImpl->ChangeState( EventData::EDITING );
3424 // Handle the InputMethodContext (predicitive text) state changes
3425 if( COMMIT == type )
3427 // InputMethodContext is no longer handling key-events
3428 mImpl->ClearPreEditFlag();
3432 if( !mImpl->mEventData->mPreEditFlag )
3434 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
3436 // Record the start of the pre-edit text
3437 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
3440 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
3441 mImpl->mEventData->mPreEditFlag = true;
3443 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3446 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
3448 // Restrict new text to fit within Maximum characters setting.
3449 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
3450 maxLengthReached = ( characterCount > maxSizeOfNewText );
3452 // The cursor position.
3453 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3455 // Update the text's style.
3457 // Updates the text style runs by adding characters.
3458 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
3460 // Get the character index from the cursor index.
3461 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
3463 // Retrieve the text's style for the given index.
3465 mImpl->RetrieveDefaultInputStyle( style );
3466 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
3468 // Whether to add a new text color run.
3469 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor ) && !mImpl->mEventData->mInputStyle.isDefaultColor;
3471 // Whether to add a new font run.
3472 const bool addFontNameRun = ( style.familyName != mImpl->mEventData->mInputStyle.familyName ) && mImpl->mEventData->mInputStyle.isFamilyDefined;
3473 const bool addFontWeightRun = ( style.weight != mImpl->mEventData->mInputStyle.weight ) && mImpl->mEventData->mInputStyle.isWeightDefined;
3474 const bool addFontWidthRun = ( style.width != mImpl->mEventData->mInputStyle.width ) && mImpl->mEventData->mInputStyle.isWidthDefined;
3475 const bool addFontSlantRun = ( style.slant != mImpl->mEventData->mInputStyle.slant ) && mImpl->mEventData->mInputStyle.isSlantDefined;
3476 const bool addFontSizeRun = ( style.size != mImpl->mEventData->mInputStyle.size ) && mImpl->mEventData->mInputStyle.isSizeDefined ;
3481 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
3482 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
3484 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
3485 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
3486 colorRun.characterRun.characterIndex = cursorIndex;
3487 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3490 if( addFontNameRun ||
3496 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
3497 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
3499 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
3501 if( addFontNameRun )
3503 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
3504 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
3505 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
3506 fontDescriptionRun.familyDefined = true;
3508 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
3511 if( addFontWeightRun )
3513 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
3514 fontDescriptionRun.weightDefined = true;
3517 if( addFontWidthRun )
3519 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
3520 fontDescriptionRun.widthDefined = true;
3523 if( addFontSlantRun )
3525 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
3526 fontDescriptionRun.slantDefined = true;
3529 if( addFontSizeRun )
3531 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
3532 fontDescriptionRun.sizeDefined = true;
3535 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
3536 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3539 // Insert at current cursor position.
3540 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
3542 if( cursorIndex < numberOfCharactersInModel )
3544 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3548 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3551 // Mark the first paragraph to be updated.
3552 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3554 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3555 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3556 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
3557 mImpl->mTextUpdateInfo.mClearAll = true;
3561 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3562 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
3565 // Update the cursor index.
3566 cursorIndex += maxSizeOfNewText;
3568 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 );
3571 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
3572 mImpl->IsPlaceholderAvailable() )
3574 // Show place-holder if empty after removing the pre-edit text
3575 ShowPlaceholderText();
3576 mImpl->mEventData->mUpdateCursorPosition = true;
3577 mImpl->ClearPreEditFlag();
3579 else if( removedPrevious ||
3581 ( 0 != utf32Characters.Count() ) )
3583 // Queue an inserted event
3584 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
3586 mImpl->mEventData->mUpdateCursorPosition = true;
3587 if( removedSelected )
3589 mImpl->mEventData->mScrollAfterDelete = true;
3593 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3597 if( maxLengthReached )
3599 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
3601 mImpl->ResetInputMethodContext();
3603 if( NULL != mImpl->mEditableControlInterface )
3605 // Do this last since it provides callbacks into application code
3606 mImpl->mEditableControlInterface->MaxLengthReached();
3611 void Controller::PasteText( const std::string& stringToPaste )
3613 InsertText( stringToPaste, Text::Controller::COMMIT );
3614 mImpl->ChangeState( EventData::EDITING );
3615 mImpl->RequestRelayout();
3617 if( NULL != mImpl->mEditableControlInterface )
3619 // Do this last since it provides callbacks into application code
3620 mImpl->mEditableControlInterface->TextChanged();
3624 bool Controller::RemoveText( int cursorOffset,
3625 int numberOfCharacters,
3626 UpdateInputStyleType type )
3628 bool removed = false;
3630 if( NULL == mImpl->mEventData )
3635 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
3636 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
3638 if( !mImpl->IsShowingPlaceholderText() )
3640 // Delete at current cursor position
3641 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
3642 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3644 CharacterIndex cursorIndex = 0;
3646 // Validate the cursor position & number of characters
3647 if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
3649 cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
3652 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
3654 numberOfCharacters = currentText.Count() - cursorIndex;
3657 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.
3658 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
3660 // Mark the paragraphs to be updated.
3661 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3663 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3664 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3665 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
3666 mImpl->mTextUpdateInfo.mClearAll = true;
3670 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3671 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
3674 // Update the input style and remove the text's style before removing the text.
3676 if( UPDATE_INPUT_STYLE == type )
3678 // Keep a copy of the current input style.
3679 InputStyle currentInputStyle;
3680 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
3682 // Set first the default input style.
3683 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
3685 // Update the input style.
3686 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
3688 // Compare if the input style has changed.
3689 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
3691 if( hasInputStyleChanged )
3693 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
3694 // Queue the input style changed signal.
3695 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
3699 // Updates the text style runs by removing characters. Runs with no characters are removed.
3700 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
3702 // Remove the characters.
3703 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
3704 Vector<Character>::Iterator last = first + numberOfCharacters;
3706 currentText.Erase( first, last );
3708 // Cursor position retreat
3709 oldCursorIndex = cursorIndex;
3711 mImpl->mEventData->mScrollAfterDelete = true;
3713 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
3721 bool Controller::RemoveSelectedText()
3723 bool textRemoved( false );
3725 if( EventData::SELECTING == mImpl->mEventData->mState )
3727 std::string removedString;
3728 mImpl->RetrieveSelection( removedString, true );
3730 if( !removedString.empty() )
3733 mImpl->ChangeState( EventData::EDITING );
3740 // private : Relayout.
3742 bool Controller::DoRelayout( const Size& size,
3743 OperationsMask operationsRequired,
3746 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
3747 bool viewUpdated( false );
3749 // Calculate the operations to be done.
3750 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
3752 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
3753 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
3755 // Get the current layout size.
3756 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3758 if( NO_OPERATION != ( LAYOUT & operations ) )
3760 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
3762 // Some vectors with data needed to layout and reorder may be void
3763 // after the first time the text has been laid out.
3764 // Fill the vectors again.
3766 // Calculate the number of glyphs to layout.
3767 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
3768 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
3769 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
3770 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
3772 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
3773 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
3775 // Make sure the index is not out of bound
3776 if ( charactersToGlyph.Count() != glyphsPerCharacter.Count() ||
3777 requestedNumberOfCharacters > charactersToGlyph.Count() ||
3778 ( lastIndex >= charactersToGlyph.Count() && charactersToGlyph.Count() > 0u ) )
3780 std::string currentText;
3781 GetText( currentText );
3783 DALI_LOG_ERROR( "Controller::DoRelayout: Attempting to access invalid buffer\n" );
3784 DALI_LOG_ERROR( "Current text is: %s\n", currentText.c_str() );
3785 DALI_LOG_ERROR( "startIndex: %u, lastIndex: %u, requestedNumberOfCharacters: %u, charactersToGlyph.Count = %lu, glyphsPerCharacter.Count = %lu\n", startIndex, lastIndex, requestedNumberOfCharacters, charactersToGlyph.Count(), glyphsPerCharacter.Count());
3790 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
3791 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
3793 if( 0u == totalNumberOfGlyphs )
3795 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3797 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
3800 // Nothing else to do if there is no glyphs.
3801 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
3805 const Vector<LineBreakInfo>& lineBreakInfo = mImpl->mModel->mLogicalModel->mLineBreakInfo;
3806 const Vector<WordBreakInfo>& wordBreakInfo = mImpl->mModel->mLogicalModel->mWordBreakInfo;
3807 const Vector<CharacterDirection>& characterDirection = mImpl->mModel->mLogicalModel->mCharacterDirections;
3808 const Vector<GlyphInfo>& glyphs = mImpl->mModel->mVisualModel->mGlyphs;
3809 const Vector<CharacterIndex>& glyphsToCharactersMap = mImpl->mModel->mVisualModel->mGlyphsToCharacters;
3810 const Vector<Length>& charactersPerGlyph = mImpl->mModel->mVisualModel->mCharactersPerGlyph;
3811 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
3812 const float outlineWidth = static_cast<float>( mImpl->mModel->GetOutlineWidth() );
3814 // Set the layout parameters.
3815 Layout::Parameters layoutParameters( size,
3817 lineBreakInfo.Begin(),
3818 wordBreakInfo.Begin(),
3819 ( 0u != characterDirection.Count() ) ? characterDirection.Begin() : NULL,
3821 glyphsToCharactersMap.Begin(),
3822 charactersPerGlyph.Begin(),
3823 charactersToGlyphBuffer,
3824 glyphsPerCharacterBuffer,
3825 totalNumberOfGlyphs,
3826 mImpl->mModel->mHorizontalAlignment,
3827 mImpl->mModel->mLineWrapMode,
3829 mImpl->mModel->mIgnoreSpacesAfterText,
3830 mImpl->mModel->mMatchSystemLanguageDirection );
3832 // Resize the vector of positions to have the same size than the vector of glyphs.
3833 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
3834 glyphPositions.Resize( totalNumberOfGlyphs );
3836 // Whether the last character is a new paragraph character.
3837 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
3838 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
3840 // The initial glyph and the number of glyphs to layout.
3841 layoutParameters.startGlyphIndex = startGlyphIndex;
3842 layoutParameters.numberOfGlyphs = numberOfGlyphs;
3843 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
3844 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
3846 // Update the ellipsis
3847 bool elideTextEnabled = mImpl->mModel->mElideEnabled;
3849 if( NULL != mImpl->mEventData )
3851 if( mImpl->mEventData->mPlaceholderEllipsisFlag && mImpl->IsShowingPlaceholderText() )
3853 elideTextEnabled = mImpl->mEventData->mIsPlaceholderElideEnabled;
3855 else if( EventData::INACTIVE != mImpl->mEventData->mState )
3857 // Disable ellipsis when editing
3858 elideTextEnabled = false;
3861 // Reset the scroll position in inactive state
3862 if( elideTextEnabled && ( mImpl->mEventData->mState == EventData::INACTIVE ) )
3864 ResetScrollPosition();
3868 // Update the visual model.
3869 bool isAutoScrollEnabled = mImpl->mIsAutoScrollEnabled;
3871 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
3873 mImpl->mModel->mVisualModel->mLines,
3876 isAutoScrollEnabled );
3877 mImpl->mIsAutoScrollEnabled = isAutoScrollEnabled;
3879 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
3883 layoutSize = newLayoutSize;
3885 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
3887 mImpl->mIsTextDirectionRTL = false;
3890 // Reorder the lines
3891 if( NO_OPERATION != ( REORDER & operations ) )
3893 Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = mImpl->mModel->mLogicalModel->mBidirectionalParagraphInfo;
3894 Vector<BidirectionalLineInfoRun>& bidirectionalLineInfo = mImpl->mModel->mLogicalModel->mBidirectionalLineInfo;
3896 // Check first if there are paragraphs with bidirectional info.
3897 if( 0u != bidirectionalInfo.Count() )
3900 const Length numberOfLines = mImpl->mModel->mVisualModel->mLines.Count();
3902 // Reorder the lines.
3903 bidirectionalLineInfo.Reserve( numberOfLines ); // Reserve because is not known yet how many lines have right to left characters.
3904 ReorderLines( bidirectionalInfo,
3906 requestedNumberOfCharacters,
3907 mImpl->mModel->mVisualModel->mLines,
3908 bidirectionalLineInfo );
3910 // Set the bidirectional info per line into the layout parameters.
3911 layoutParameters.lineBidirectionalInfoRunsBuffer = bidirectionalLineInfo.Begin();
3912 layoutParameters.numberOfBidirectionalInfoRuns = bidirectionalLineInfo.Count();
3914 // Re-layout the text. Reorder those lines with right to left characters.
3915 mImpl->mLayoutEngine.ReLayoutRightToLeftLines( layoutParameters,
3917 requestedNumberOfCharacters,
3920 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && ( numberOfLines > 0 ) )
3922 const LineRun* const firstline = mImpl->mModel->mVisualModel->mLines.Begin();
3925 mImpl->mIsTextDirectionRTL = firstline->direction;
3931 // Sets the layout size.
3932 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3934 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
3939 if( NO_OPERATION != ( ALIGN & operations ) )
3941 // The laid-out lines.
3942 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
3944 // Need to align with the control's size as the text may contain lines
3945 // starting either with left to right text or right to left.
3946 mImpl->mLayoutEngine.Align( size,
3948 requestedNumberOfCharacters,
3949 mImpl->mModel->mHorizontalAlignment,
3951 mImpl->mModel->mAlignmentOffset,
3952 mImpl->mLayoutDirection,
3953 mImpl->mModel->mMatchSystemLanguageDirection );
3957 #if defined(DEBUG_ENABLED)
3958 std::string currentText;
3959 GetText( currentText );
3960 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mIsTextDirectionRTL[%s] [%s]\n", this, (mImpl->mIsTextDirectionRTL)?"true":"false", currentText.c_str() );
3962 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
3966 void Controller::CalculateVerticalOffset( const Size& controlSize )
3968 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3970 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
3972 // Get the line height of the default font.
3973 layoutSize.height = mImpl->GetDefaultFontLineHeight();
3976 switch( mImpl->mModel->mVerticalAlignment )
3978 case VerticalAlignment::TOP:
3980 mImpl->mModel->mScrollPosition.y = 0.f;
3983 case VerticalAlignment::CENTER:
3985 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
3988 case VerticalAlignment::BOTTOM:
3990 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
3996 // private : Events.
3998 void Controller::ProcessModifyEvents()
4000 Vector<ModifyEvent>& events = mImpl->mModifyEvents;
4002 if( 0u == events.Count() )
4008 for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
4009 endIt = events.End();
4013 const ModifyEvent& event = *it;
4015 if( ModifyEvent::TEXT_REPLACED == event.type )
4017 // A (single) replace event should come first, otherwise we wasted time processing NOOP events
4018 DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
4020 TextReplacedEvent();
4022 else if( ModifyEvent::TEXT_INSERTED == event.type )
4024 TextInsertedEvent();
4026 else if( ModifyEvent::TEXT_DELETED == event.type )
4028 // Placeholder-text cannot be deleted
4029 if( !mImpl->IsShowingPlaceholderText() )
4036 if( NULL != mImpl->mEventData )
4038 // When the text is being modified, delay cursor blinking
4039 mImpl->mEventData->mDecorator->DelayCursorBlink();
4041 // Update selection position after modifying the text
4042 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
4043 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
4046 // Discard temporary text
4050 void Controller::TextReplacedEvent()
4052 // The natural size needs to be re-calculated.
4053 mImpl->mRecalculateNaturalSize = true;
4055 // The text direction needs to be updated.
4056 mImpl->mUpdateTextDirection = true;
4058 // Apply modifications to the model
4059 mImpl->mOperationsPending = ALL_OPERATIONS;
4062 void Controller::TextInsertedEvent()
4064 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
4066 if( NULL == mImpl->mEventData )
4071 mImpl->mEventData->mCheckScrollAmount = true;
4073 // The natural size needs to be re-calculated.
4074 mImpl->mRecalculateNaturalSize = true;
4076 // The text direction needs to be updated.
4077 mImpl->mUpdateTextDirection = true;
4079 // Apply modifications to the model; TODO - Optimize this
4080 mImpl->mOperationsPending = ALL_OPERATIONS;
4083 void Controller::TextDeletedEvent()
4085 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
4087 if( NULL == mImpl->mEventData )
4092 mImpl->mEventData->mCheckScrollAmount = true;
4094 // The natural size needs to be re-calculated.
4095 mImpl->mRecalculateNaturalSize = true;
4097 // The text direction needs to be updated.
4098 mImpl->mUpdateTextDirection = true;
4100 // Apply modifications to the model; TODO - Optimize this
4101 mImpl->mOperationsPending = ALL_OPERATIONS;
4104 bool Controller::DeleteEvent( int keyCode )
4106 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p KeyCode : %d \n", this, keyCode );
4108 bool removed = false;
4110 if( NULL == mImpl->mEventData )
4115 // InputMethodContext is no longer handling key-events
4116 mImpl->ClearPreEditFlag();
4118 if( EventData::SELECTING == mImpl->mEventData->mState )
4120 removed = RemoveSelectedText();
4122 else if( ( mImpl->mEventData->mPrimaryCursorPosition > 0 ) && ( keyCode == Dali::DALI_KEY_BACKSPACE) )
4124 // Remove the character before the current cursor position
4125 removed = RemoveText( -1,
4127 UPDATE_INPUT_STYLE );
4129 else if( keyCode == Dali::DevelKey::DALI_KEY_DELETE )
4131 // Remove the character after the current cursor position
4132 removed = RemoveText( 0,
4134 UPDATE_INPUT_STYLE );
4139 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
4140 !mImpl->IsPlaceholderAvailable() )
4142 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
4146 ShowPlaceholderText();
4148 mImpl->mEventData->mUpdateCursorPosition = true;
4149 mImpl->mEventData->mScrollAfterDelete = true;
4155 // private : Helpers.
4157 void Controller::ResetText()
4160 mImpl->mModel->mLogicalModel->mText.Clear();
4162 // Reset the embedded images buffer.
4163 mImpl->mModel->mLogicalModel->ClearEmbeddedImages();
4165 // We have cleared everything including the placeholder-text
4166 mImpl->PlaceholderCleared();
4168 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4169 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4170 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
4172 // Clear any previous text.
4173 mImpl->mTextUpdateInfo.mClearAll = true;
4175 // The natural size needs to be re-calculated.
4176 mImpl->mRecalculateNaturalSize = true;
4178 // The text direction needs to be updated.
4179 mImpl->mUpdateTextDirection = true;
4181 // Apply modifications to the model
4182 mImpl->mOperationsPending = ALL_OPERATIONS;
4185 void Controller::ShowPlaceholderText()
4187 if( mImpl->IsPlaceholderAvailable() )
4189 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
4191 if( NULL == mImpl->mEventData )
4196 mImpl->mEventData->mIsShowingPlaceholderText = true;
4198 // Disable handles when showing place-holder text
4199 mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
4200 mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
4201 mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
4203 const char* text( NULL );
4206 // TODO - Switch Placeholder text when changing state
4207 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
4208 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
4210 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
4211 size = mImpl->mEventData->mPlaceholderTextActive.size();
4215 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
4216 size = mImpl->mEventData->mPlaceholderTextInactive.size();
4219 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4220 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4222 // Reset model for showing placeholder.
4223 mImpl->mModel->mLogicalModel->mText.Clear();
4224 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
4226 // Convert text into UTF-32
4227 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
4228 utf32Characters.Resize( size );
4230 // This is a bit horrible but std::string returns a (signed) char*
4231 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
4233 // Transform a text array encoded in utf8 into an array encoded in utf32.
4234 // It returns the actual number of characters.
4235 const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
4236 utf32Characters.Resize( characterCount );
4238 // The characters to be added.
4239 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
4241 // Reset the cursor position
4242 mImpl->mEventData->mPrimaryCursorPosition = 0;
4244 // The natural size needs to be re-calculated.
4245 mImpl->mRecalculateNaturalSize = true;
4247 // The text direction needs to be updated.
4248 mImpl->mUpdateTextDirection = true;
4250 // Apply modifications to the model
4251 mImpl->mOperationsPending = ALL_OPERATIONS;
4253 // Update the rest of the model during size negotiation
4254 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
4258 void Controller::ClearFontData()
4260 if( mImpl->mFontDefaults )
4262 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
4265 // Set flags to update the model.
4266 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4267 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4268 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
4270 mImpl->mTextUpdateInfo.mClearAll = true;
4271 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
4272 mImpl->mRecalculateNaturalSize = true;
4274 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
4280 UPDATE_LAYOUT_SIZE |
4285 void Controller::ClearStyleData()
4287 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
4288 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
4291 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
4293 // Reset the cursor position
4294 if( NULL != mImpl->mEventData )
4296 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
4298 // Update the cursor if it's in editing mode.
4299 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
4301 mImpl->mEventData->mUpdateCursorPosition = true;
4306 void Controller::ResetScrollPosition()
4308 if( NULL != mImpl->mEventData )
4310 // Reset the scroll position.
4311 mImpl->mModel->mScrollPosition = Vector2::ZERO;
4312 mImpl->mEventData->mScrollAfterUpdatePosition = true;
4316 void Controller::SetControlInterface( ControlInterface* controlInterface )
4318 mImpl->mControlInterface = controlInterface;
4321 bool Controller::ShouldClearFocusOnEscape() const
4323 return mImpl->mShouldClearFocusOnEscape;
4326 // private : Private contructors & copy operator.
4328 Controller::Controller()
4331 mImpl = new Controller::Impl( NULL, NULL );
4334 Controller::Controller( ControlInterface* controlInterface )
4336 mImpl = new Controller::Impl( controlInterface, NULL );
4339 Controller::Controller( ControlInterface* controlInterface,
4340 EditableControlInterface* editableControlInterface )
4342 mImpl = new Controller::Impl( controlInterface,
4343 editableControlInterface );
4346 // The copy constructor and operator are left unimplemented.
4348 // protected : Destructor.
4350 Controller::~Controller()
4357 } // namespace Toolkit