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->mModel->mLogicalModel->mColorRuns.Clear();
1248 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1250 mImpl->RequestRelayout();
1254 const Vector4& Controller::GetDefaultColor() const
1256 return mImpl->mTextColor;
1259 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
1261 if( NULL != mImpl->mEventData )
1263 mImpl->mEventData->mPlaceholderTextColor = textColor;
1266 if( mImpl->IsShowingPlaceholderText() )
1268 mImpl->mModel->mVisualModel->SetTextColor( textColor );
1269 mImpl->RequestRelayout();
1273 const Vector4& Controller::GetPlaceholderTextColor() const
1275 if( NULL != mImpl->mEventData )
1277 return mImpl->mEventData->mPlaceholderTextColor;
1280 return Color::BLACK;
1283 void Controller::SetShadowOffset( const Vector2& shadowOffset )
1285 mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
1287 mImpl->RequestRelayout();
1290 const Vector2& Controller::GetShadowOffset() const
1292 return mImpl->mModel->mVisualModel->GetShadowOffset();
1295 void Controller::SetShadowColor( const Vector4& shadowColor )
1297 mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
1299 mImpl->RequestRelayout();
1302 const Vector4& Controller::GetShadowColor() const
1304 return mImpl->mModel->mVisualModel->GetShadowColor();
1307 void Controller::SetShadowBlurRadius( const float& shadowBlurRadius )
1309 if ( fabsf( GetShadowBlurRadius() - shadowBlurRadius ) > Math::MACHINE_EPSILON_1 )
1311 mImpl->mModel->mVisualModel->SetShadowBlurRadius( shadowBlurRadius );
1313 mImpl->RequestRelayout();
1317 const float& Controller::GetShadowBlurRadius() const
1319 return mImpl->mModel->mVisualModel->GetShadowBlurRadius();
1322 void Controller::SetUnderlineColor( const Vector4& color )
1324 mImpl->mModel->mVisualModel->SetUnderlineColor( color );
1326 mImpl->RequestRelayout();
1329 const Vector4& Controller::GetUnderlineColor() const
1331 return mImpl->mModel->mVisualModel->GetUnderlineColor();
1334 void Controller::SetUnderlineEnabled( bool enabled )
1336 mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
1338 mImpl->RequestRelayout();
1341 bool Controller::IsUnderlineEnabled() const
1343 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
1346 void Controller::SetUnderlineHeight( float height )
1348 mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
1350 mImpl->RequestRelayout();
1353 float Controller::GetUnderlineHeight() const
1355 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
1358 void Controller::SetOutlineColor( const Vector4& color )
1360 mImpl->mModel->mVisualModel->SetOutlineColor( color );
1362 mImpl->RequestRelayout();
1365 const Vector4& Controller::GetOutlineColor() const
1367 return mImpl->mModel->mVisualModel->GetOutlineColor();
1370 void Controller::SetOutlineWidth( uint16_t width )
1372 mImpl->mModel->mVisualModel->SetOutlineWidth( width );
1374 mImpl->RequestRelayout();
1377 uint16_t Controller::GetOutlineWidth() const
1379 return mImpl->mModel->mVisualModel->GetOutlineWidth();
1382 void Controller::SetBackgroundColor( const Vector4& color )
1384 mImpl->mModel->mVisualModel->SetBackgroundColor( color );
1386 mImpl->RequestRelayout();
1389 const Vector4& Controller::GetBackgroundColor() const
1391 return mImpl->mModel->mVisualModel->GetBackgroundColor();
1394 void Controller::SetBackgroundEnabled( bool enabled )
1396 mImpl->mModel->mVisualModel->SetBackgroundEnabled( enabled );
1398 mImpl->RequestRelayout();
1401 bool Controller::IsBackgroundEnabled() const
1403 return mImpl->mModel->mVisualModel->IsBackgroundEnabled();
1406 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
1408 if( NULL == mImpl->mEmbossDefaults )
1410 mImpl->mEmbossDefaults = new EmbossDefaults();
1413 mImpl->mEmbossDefaults->properties = embossProperties;
1416 const std::string& Controller::GetDefaultEmbossProperties() const
1418 if( NULL != mImpl->mEmbossDefaults )
1420 return mImpl->mEmbossDefaults->properties;
1423 return EMPTY_STRING;
1426 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
1428 if( NULL == mImpl->mOutlineDefaults )
1430 mImpl->mOutlineDefaults = new OutlineDefaults();
1433 mImpl->mOutlineDefaults->properties = outlineProperties;
1436 const std::string& Controller::GetDefaultOutlineProperties() const
1438 if( NULL != mImpl->mOutlineDefaults )
1440 return mImpl->mOutlineDefaults->properties;
1443 return EMPTY_STRING;
1446 bool Controller::SetDefaultLineSpacing( float lineSpacing )
1448 if( std::fabs( lineSpacing - mImpl->mLayoutEngine.GetDefaultLineSpacing() ) > Math::MACHINE_EPSILON_1000 )
1450 mImpl->mLayoutEngine.SetDefaultLineSpacing(lineSpacing);
1451 mImpl->mRecalculateNaturalSize = true;
1457 float Controller::GetDefaultLineSpacing() const
1459 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
1462 void Controller::SetInputColor( const Vector4& color )
1464 if( NULL != mImpl->mEventData )
1466 mImpl->mEventData->mInputStyle.textColor = color;
1467 mImpl->mEventData->mInputStyle.isDefaultColor = false;
1469 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1471 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
1473 // Get start and end position of selection
1474 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
1475 const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
1477 // Add the color run.
1478 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1479 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
1481 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
1482 colorRun.color = color;
1483 colorRun.characterRun.characterIndex = startOfSelectedText;
1484 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1486 // Request to relayout.
1487 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1488 mImpl->RequestRelayout();
1490 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1491 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1492 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1497 const Vector4& Controller::GetInputColor() const
1499 if( NULL != mImpl->mEventData )
1501 return mImpl->mEventData->mInputStyle.textColor;
1504 // Return the default text's color if there is no EventData.
1505 return mImpl->mTextColor;
1509 void Controller::SetInputFontFamily( const std::string& fontFamily )
1511 if( NULL != mImpl->mEventData )
1513 mImpl->mEventData->mInputStyle.familyName = fontFamily;
1514 mImpl->mEventData->mInputStyle.isFamilyDefined = true;
1516 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1518 CharacterIndex startOfSelectedText = 0u;
1519 Length lengthOfSelectedText = 0u;
1520 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1521 mImpl->mModel->mLogicalModel,
1522 startOfSelectedText,
1523 lengthOfSelectedText );
1525 fontDescriptionRun.familyLength = fontFamily.size();
1526 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
1527 memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength );
1528 fontDescriptionRun.familyDefined = true;
1530 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
1532 // Request to relayout.
1533 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1538 UPDATE_LAYOUT_SIZE |
1541 mImpl->mRecalculateNaturalSize = true;
1542 mImpl->RequestRelayout();
1544 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1545 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1546 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1548 // As the font changes, recalculate the handle positions is needed.
1549 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1550 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1551 mImpl->mEventData->mUpdateHighlightBox = true;
1552 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1557 const std::string& Controller::GetInputFontFamily() const
1559 if( NULL != mImpl->mEventData )
1561 return mImpl->mEventData->mInputStyle.familyName;
1564 // Return the default font's family if there is no EventData.
1565 return GetDefaultFontFamily();
1568 void Controller::SetInputFontWeight( FontWeight weight )
1570 if( NULL != mImpl->mEventData )
1572 mImpl->mEventData->mInputStyle.weight = weight;
1573 mImpl->mEventData->mInputStyle.isWeightDefined = true;
1575 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1577 CharacterIndex startOfSelectedText = 0u;
1578 Length lengthOfSelectedText = 0u;
1579 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1580 mImpl->mModel->mLogicalModel,
1581 startOfSelectedText,
1582 lengthOfSelectedText );
1584 fontDescriptionRun.weight = weight;
1585 fontDescriptionRun.weightDefined = true;
1587 // Request to relayout.
1588 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1593 UPDATE_LAYOUT_SIZE |
1596 mImpl->mRecalculateNaturalSize = true;
1597 mImpl->RequestRelayout();
1599 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1600 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1601 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1603 // As the font might change, recalculate the handle positions is needed.
1604 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1605 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1606 mImpl->mEventData->mUpdateHighlightBox = true;
1607 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1612 bool Controller::IsInputFontWeightDefined() const
1614 bool defined = false;
1616 if( NULL != mImpl->mEventData )
1618 defined = mImpl->mEventData->mInputStyle.isWeightDefined;
1624 FontWeight Controller::GetInputFontWeight() const
1626 if( NULL != mImpl->mEventData )
1628 return mImpl->mEventData->mInputStyle.weight;
1631 return GetDefaultFontWeight();
1634 void Controller::SetInputFontWidth( FontWidth width )
1636 if( NULL != mImpl->mEventData )
1638 mImpl->mEventData->mInputStyle.width = width;
1639 mImpl->mEventData->mInputStyle.isWidthDefined = true;
1641 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1643 CharacterIndex startOfSelectedText = 0u;
1644 Length lengthOfSelectedText = 0u;
1645 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1646 mImpl->mModel->mLogicalModel,
1647 startOfSelectedText,
1648 lengthOfSelectedText );
1650 fontDescriptionRun.width = width;
1651 fontDescriptionRun.widthDefined = true;
1653 // Request to relayout.
1654 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1659 UPDATE_LAYOUT_SIZE |
1662 mImpl->mRecalculateNaturalSize = true;
1663 mImpl->RequestRelayout();
1665 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1666 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1667 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1669 // As the font might change, recalculate the handle positions is needed.
1670 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1671 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1672 mImpl->mEventData->mUpdateHighlightBox = true;
1673 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1678 bool Controller::IsInputFontWidthDefined() const
1680 bool defined = false;
1682 if( NULL != mImpl->mEventData )
1684 defined = mImpl->mEventData->mInputStyle.isWidthDefined;
1690 FontWidth Controller::GetInputFontWidth() const
1692 if( NULL != mImpl->mEventData )
1694 return mImpl->mEventData->mInputStyle.width;
1697 return GetDefaultFontWidth();
1700 void Controller::SetInputFontSlant( FontSlant slant )
1702 if( NULL != mImpl->mEventData )
1704 mImpl->mEventData->mInputStyle.slant = slant;
1705 mImpl->mEventData->mInputStyle.isSlantDefined = true;
1707 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1709 CharacterIndex startOfSelectedText = 0u;
1710 Length lengthOfSelectedText = 0u;
1711 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1712 mImpl->mModel->mLogicalModel,
1713 startOfSelectedText,
1714 lengthOfSelectedText );
1716 fontDescriptionRun.slant = slant;
1717 fontDescriptionRun.slantDefined = true;
1719 // Request to relayout.
1720 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1725 UPDATE_LAYOUT_SIZE |
1728 mImpl->mRecalculateNaturalSize = true;
1729 mImpl->RequestRelayout();
1731 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1732 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1733 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1735 // As the font might change, recalculate the handle positions is needed.
1736 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1737 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1738 mImpl->mEventData->mUpdateHighlightBox = true;
1739 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1744 bool Controller::IsInputFontSlantDefined() const
1746 bool defined = false;
1748 if( NULL != mImpl->mEventData )
1750 defined = mImpl->mEventData->mInputStyle.isSlantDefined;
1756 FontSlant Controller::GetInputFontSlant() const
1758 if( NULL != mImpl->mEventData )
1760 return mImpl->mEventData->mInputStyle.slant;
1763 return GetDefaultFontSlant();
1766 void Controller::SetInputFontPointSize( float size )
1768 if( NULL != mImpl->mEventData )
1770 mImpl->mEventData->mInputStyle.size = size;
1771 mImpl->mEventData->mInputStyle.isSizeDefined = true;
1773 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1775 CharacterIndex startOfSelectedText = 0u;
1776 Length lengthOfSelectedText = 0u;
1777 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1778 mImpl->mModel->mLogicalModel,
1779 startOfSelectedText,
1780 lengthOfSelectedText );
1782 fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
1783 fontDescriptionRun.sizeDefined = true;
1785 // Request to relayout.
1786 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1791 UPDATE_LAYOUT_SIZE |
1794 mImpl->mRecalculateNaturalSize = true;
1795 mImpl->RequestRelayout();
1797 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1798 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1799 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1801 // As the font might change, recalculate the handle positions is needed.
1802 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1803 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1804 mImpl->mEventData->mUpdateHighlightBox = true;
1805 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1810 float Controller::GetInputFontPointSize() const
1812 if( NULL != mImpl->mEventData )
1814 return mImpl->mEventData->mInputStyle.size;
1817 // Return the default font's point size if there is no EventData.
1818 return GetDefaultFontSize( Text::Controller::POINT_SIZE );
1821 void Controller::SetInputLineSpacing( float lineSpacing )
1823 if( NULL != mImpl->mEventData )
1825 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1826 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1830 float Controller::GetInputLineSpacing() const
1832 if( NULL != mImpl->mEventData )
1834 return mImpl->mEventData->mInputStyle.lineSpacing;
1840 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1842 if( NULL != mImpl->mEventData )
1844 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1848 const std::string& Controller::GetInputShadowProperties() const
1850 if( NULL != mImpl->mEventData )
1852 return mImpl->mEventData->mInputStyle.shadowProperties;
1855 return EMPTY_STRING;
1858 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1860 if( NULL != mImpl->mEventData )
1862 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1866 const std::string& Controller::GetInputUnderlineProperties() const
1868 if( NULL != mImpl->mEventData )
1870 return mImpl->mEventData->mInputStyle.underlineProperties;
1873 return EMPTY_STRING;
1876 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
1878 if( NULL != mImpl->mEventData )
1880 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1884 const std::string& Controller::GetInputEmbossProperties() const
1886 if( NULL != mImpl->mEventData )
1888 return mImpl->mEventData->mInputStyle.embossProperties;
1891 return GetDefaultEmbossProperties();
1894 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
1896 if( NULL != mImpl->mEventData )
1898 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1902 const std::string& Controller::GetInputOutlineProperties() const
1904 if( NULL != mImpl->mEventData )
1906 return mImpl->mEventData->mInputStyle.outlineProperties;
1909 return GetDefaultOutlineProperties();
1912 void Controller::SetInputModePassword( bool passwordInput )
1914 if( NULL != mImpl->mEventData )
1916 mImpl->mEventData->mPasswordInput = passwordInput;
1920 bool Controller::IsInputModePassword()
1922 if( NULL != mImpl->mEventData )
1924 return mImpl->mEventData->mPasswordInput;
1929 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
1931 if( NULL != mImpl->mEventData )
1933 mImpl->mEventData->mDoubleTapAction = action;
1937 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1939 NoTextTap::Action action = NoTextTap::NO_ACTION;
1941 if( NULL != mImpl->mEventData )
1943 action = mImpl->mEventData->mDoubleTapAction;
1949 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
1951 if( NULL != mImpl->mEventData )
1953 mImpl->mEventData->mLongPressAction = action;
1957 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1959 NoTextTap::Action action = NoTextTap::NO_ACTION;
1961 if( NULL != mImpl->mEventData )
1963 action = mImpl->mEventData->mLongPressAction;
1969 bool Controller::IsUnderlineSetByString()
1971 return mImpl->mUnderlineSetByString;
1974 void Controller::UnderlineSetByString( bool setByString )
1976 mImpl->mUnderlineSetByString = setByString;
1979 bool Controller::IsShadowSetByString()
1981 return mImpl->mShadowSetByString;
1984 void Controller::ShadowSetByString( bool setByString )
1986 mImpl->mShadowSetByString = setByString;
1989 bool Controller::IsOutlineSetByString()
1991 return mImpl->mOutlineSetByString;
1994 void Controller::OutlineSetByString( bool setByString )
1996 mImpl->mOutlineSetByString = setByString;
1999 bool Controller::IsFontStyleSetByString()
2001 return mImpl->mFontStyleSetByString;
2004 void Controller::FontStyleSetByString( bool setByString )
2006 mImpl->mFontStyleSetByString = setByString;
2009 // public : Queries & retrieves.
2011 Layout::Engine& Controller::GetLayoutEngine()
2013 return mImpl->mLayoutEngine;
2016 View& Controller::GetView()
2018 return mImpl->mView;
2021 Vector3 Controller::GetNaturalSize()
2023 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
2024 Vector3 naturalSize;
2026 // Make sure the model is up-to-date before layouting
2027 ProcessModifyEvents();
2029 if( mImpl->mRecalculateNaturalSize )
2031 // Operations that can be done only once until the text changes.
2032 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2039 GET_GLYPH_METRICS );
2041 // Set the update info to relayout the whole text.
2042 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2043 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2045 // Make sure the model is up-to-date before layouting
2046 mImpl->UpdateModel( onlyOnceOperations );
2048 // Layout the text for the new width.
2049 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT | REORDER );
2051 // Store the actual control's size to restore later.
2052 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
2054 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
2055 static_cast<OperationsMask>( onlyOnceOperations |
2057 naturalSize.GetVectorXY() );
2059 // Do not do again the only once operations.
2060 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2062 // Do the size related operations again.
2063 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
2066 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
2068 // Stores the natural size to avoid recalculate it again
2069 // unless the text/style changes.
2070 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
2072 mImpl->mRecalculateNaturalSize = false;
2074 // Clear the update info. This info will be set the next time the text is updated.
2075 mImpl->mTextUpdateInfo.Clear();
2076 mImpl->mTextUpdateInfo.mClearAll = true;
2078 // Restore the actual control's size.
2079 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
2081 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
2085 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
2087 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
2090 naturalSize.x = ConvertToEven( naturalSize.x );
2091 naturalSize.y = ConvertToEven( naturalSize.y );
2096 bool Controller::CheckForTextFit( float pointSize, Size& layoutSize )
2099 mImpl->mFontDefaults->mFitPointSize = pointSize;
2100 mImpl->mFontDefaults->sizeDefined = true;
2103 // Operations that can be done only once until the text changes.
2104 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2111 GET_GLYPH_METRICS );
2113 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2114 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2116 // Make sure the model is up-to-date before layouting
2117 mImpl->UpdateModel( onlyOnceOperations );
2119 DoRelayout( Size( layoutSize.width, MAX_FLOAT ),
2120 static_cast<OperationsMask>( onlyOnceOperations | LAYOUT),
2123 // Clear the update info. This info will be set the next time the text is updated.
2124 mImpl->mTextUpdateInfo.Clear();
2125 mImpl->mTextUpdateInfo.mClearAll = true;
2127 if( textSize.width > layoutSize.width || textSize.height > layoutSize.height )
2134 void Controller::FitPointSizeforLayout( Size layoutSize )
2136 const OperationsMask operations = mImpl->mOperationsPending;
2137 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
2139 bool actualellipsis = mImpl->mModel->mElideEnabled;
2140 float minPointSize = mImpl->mTextFitMinSize;
2141 float maxPointSize = mImpl->mTextFitMaxSize;
2142 float pointInterval = mImpl->mTextFitStepSize;
2144 mImpl->mModel->mElideEnabled = false;
2145 Vector<float> pointSizeArray;
2148 if( pointInterval < 1.f )
2150 mImpl->mTextFitStepSize = pointInterval = 1.0f;
2153 pointSizeArray.Reserve( static_cast< unsigned int >( ceil( ( maxPointSize - minPointSize ) / pointInterval ) ) );
2155 for( float i = minPointSize; i < maxPointSize; i += pointInterval )
2157 pointSizeArray.PushBack( i );
2160 pointSizeArray.PushBack( maxPointSize );
2162 int bestSizeIndex = 0;
2163 int min = bestSizeIndex + 1;
2164 int max = pointSizeArray.Size() - 1;
2167 int destI = ( min + max ) / 2;
2169 if( CheckForTextFit( pointSizeArray[destI], layoutSize ) )
2171 bestSizeIndex = min;
2177 bestSizeIndex = max;
2181 mImpl->mModel->mElideEnabled = actualellipsis;
2182 mImpl->mFontDefaults->mFitPointSize = pointSizeArray[bestSizeIndex];
2183 mImpl->mFontDefaults->sizeDefined = true;
2188 float Controller::GetHeightForWidth( float width )
2190 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
2191 // Make sure the model is up-to-date before layouting
2192 ProcessModifyEvents();
2195 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ||
2196 mImpl->mTextUpdateInfo.mFullRelayoutNeeded ||
2197 mImpl->mTextUpdateInfo.mClearAll )
2199 // Operations that can be done only once until the text changes.
2200 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2207 GET_GLYPH_METRICS );
2209 // Set the update info to relayout the whole text.
2210 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2211 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2213 // Make sure the model is up-to-date before layouting
2214 mImpl->UpdateModel( onlyOnceOperations );
2217 // Layout the text for the new width.
2218 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
2220 // Store the actual control's width.
2221 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
2223 DoRelayout( Size( width, MAX_FLOAT ),
2224 static_cast<OperationsMask>( onlyOnceOperations |
2228 // Do not do again the only once operations.
2229 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2231 // Do the size related operations again.
2232 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
2236 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
2238 // Clear the update info. This info will be set the next time the text is updated.
2239 mImpl->mTextUpdateInfo.Clear();
2240 mImpl->mTextUpdateInfo.mClearAll = true;
2242 // Restore the actual control's width.
2243 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
2245 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
2249 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
2250 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
2253 return layoutSize.height;
2256 int Controller::GetLineCount( float width )
2258 GetHeightForWidth( width );
2259 int numberofLines = mImpl->mModel->GetNumberOfLines();
2260 return numberofLines;
2263 const ModelInterface* const Controller::GetTextModel() const
2265 return mImpl->mModel.Get();
2268 float Controller::GetScrollAmountByUserInput()
2270 float scrollAmount = 0.0f;
2272 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
2274 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
2275 mImpl->mEventData->mCheckScrollAmount = false;
2277 return scrollAmount;
2280 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
2282 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
2285 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
2286 layoutHeight = layout.height;
2287 scrollPosition = mImpl->mModel->mScrollPosition.y;
2288 isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
2292 void Controller::SetHiddenInputOption(const Property::Map& options )
2294 if( NULL == mImpl->mHiddenInput )
2296 mImpl->mHiddenInput = new HiddenText( this );
2298 mImpl->mHiddenInput->SetProperties(options);
2301 void Controller::GetHiddenInputOption(Property::Map& options )
2303 if( NULL != mImpl->mHiddenInput )
2305 mImpl->mHiddenInput->GetProperties(options);
2309 void Controller::SetPlaceholderProperty( const Property::Map& map )
2311 const Property::Map::SizeType count = map.Count();
2313 for( Property::Map::SizeType position = 0; position < count; ++position )
2315 KeyValuePair keyValue = map.GetKeyValue( position );
2316 Property::Key& key = keyValue.first;
2317 Property::Value& value = keyValue.second;
2319 if( key == Toolkit::Text::PlaceHolder::Property::TEXT || key == PLACEHOLDER_TEXT )
2321 std::string text = "";
2323 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
2325 else if( key == Toolkit::Text::PlaceHolder::Property::TEXT_FOCUSED || key == PLACEHOLDER_TEXT_FOCUSED )
2327 std::string text = "";
2329 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
2331 else if( key == Toolkit::Text::PlaceHolder::Property::COLOR || key == PLACEHOLDER_COLOR )
2334 value.Get( textColor );
2335 if( GetPlaceholderTextColor() != textColor )
2337 SetPlaceholderTextColor( textColor );
2340 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_FAMILY || key == PLACEHOLDER_FONT_FAMILY )
2342 std::string fontFamily = "";
2343 value.Get( fontFamily );
2344 SetPlaceholderFontFamily( fontFamily );
2346 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_STYLE || key == PLACEHOLDER_FONT_STYLE )
2348 SetFontStyleProperty( this, value, Text::FontStyle::PLACEHOLDER );
2350 else if( key == Toolkit::Text::PlaceHolder::Property::POINT_SIZE || key == PLACEHOLDER_POINT_SIZE )
2353 value.Get( pointSize );
2354 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
2356 SetPlaceholderTextFontSize( pointSize, Text::Controller::POINT_SIZE );
2359 else if( key == Toolkit::Text::PlaceHolder::Property::PIXEL_SIZE || key == PLACEHOLDER_PIXEL_SIZE )
2362 value.Get( pixelSize );
2363 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
2365 SetPlaceholderTextFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
2368 else if( key == Toolkit::Text::PlaceHolder::Property::ELLIPSIS || key == PLACEHOLDER_ELLIPSIS )
2371 value.Get( ellipsis );
2372 SetPlaceholderTextElideEnabled( ellipsis );
2377 void Controller::GetPlaceholderProperty( Property::Map& map )
2379 if( NULL != mImpl->mEventData )
2381 if( !mImpl->mEventData->mPlaceholderTextActive.empty() )
2383 map[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = mImpl->mEventData->mPlaceholderTextActive;
2385 if( !mImpl->mEventData->mPlaceholderTextInactive.empty() )
2387 map[ Text::PlaceHolder::Property::TEXT ] = mImpl->mEventData->mPlaceholderTextInactive;
2390 map[ Text::PlaceHolder::Property::COLOR ] = mImpl->mEventData->mPlaceholderTextColor;
2391 map[ Text::PlaceHolder::Property::FONT_FAMILY ] = GetPlaceholderFontFamily();
2393 Property::Value fontStyleMapGet;
2394 GetFontStyleProperty( this, fontStyleMapGet, Text::FontStyle::PLACEHOLDER );
2395 map[ Text::PlaceHolder::Property::FONT_STYLE ] = fontStyleMapGet;
2397 // Choose font size : POINT_SIZE or PIXEL_SIZE
2398 if( !mImpl->mEventData->mIsPlaceholderPixelSize )
2400 map[ Text::PlaceHolder::Property::POINT_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE );
2404 map[ Text::PlaceHolder::Property::PIXEL_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE );
2407 if( mImpl->mEventData->mPlaceholderEllipsisFlag )
2409 map[ Text::PlaceHolder::Property::ELLIPSIS ] = IsPlaceholderTextElideEnabled();
2414 Toolkit::DevelText::TextDirection::Type Controller::GetTextDirection()
2416 // Make sure the model is up-to-date before layouting
2417 ProcessModifyEvents();
2419 if ( mImpl->mUpdateTextDirection )
2421 // Operations that can be done only once until the text changes.
2422 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2429 GET_GLYPH_METRICS );
2431 // Set the update info to relayout the whole text.
2432 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2433 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2435 // Make sure the model is up-to-date before layouting
2436 mImpl->UpdateModel( onlyOnceOperations );
2438 Vector3 naturalSize;
2439 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
2440 static_cast<OperationsMask>( onlyOnceOperations |
2441 LAYOUT | REORDER | UPDATE_DIRECTION ),
2442 naturalSize.GetVectorXY() );
2444 // Do not do again the only once operations.
2445 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2447 // Clear the update info. This info will be set the next time the text is updated.
2448 mImpl->mTextUpdateInfo.Clear();
2450 mImpl->mUpdateTextDirection = false;
2453 return mImpl->mIsTextDirectionRTL ? Toolkit::DevelText::TextDirection::RIGHT_TO_LEFT : Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT;
2456 Toolkit::DevelText::VerticalLineAlignment::Type Controller::GetVerticalLineAlignment() const
2458 return mImpl->mModel->GetVerticalLineAlignment();
2461 void Controller::SetVerticalLineAlignment( Toolkit::DevelText::VerticalLineAlignment::Type alignment )
2463 mImpl->mModel->mVerticalLineAlignment = alignment;
2466 // public : Relayout.
2468 Controller::UpdateTextType Controller::Relayout( const Size& size, Dali::LayoutDirection::Type layoutDirection )
2470 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
2472 UpdateTextType updateTextType = NONE_UPDATED;
2474 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
2476 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
2478 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
2479 updateTextType = MODEL_UPDATED;
2482 // Clear the update info. This info will be set the next time the text is updated.
2483 mImpl->mTextUpdateInfo.Clear();
2485 // Not worth to relayout if width or height is equal to zero.
2486 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
2488 return updateTextType;
2491 // Whether a new size has been set.
2492 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
2496 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
2498 if( ( 0 == mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd ) &&
2499 ( 0 == mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) &&
2500 ( ( mImpl->mModel->mVisualModel->mControlSize.width < Math::MACHINE_EPSILON_1000 ) || ( mImpl->mModel->mVisualModel->mControlSize.height < Math::MACHINE_EPSILON_1000 ) ) )
2502 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
2505 // Layout operations that need to be done if the size changes.
2506 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2509 UPDATE_LAYOUT_SIZE |
2511 // Set the update info to relayout the whole text.
2512 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2513 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2515 // Store the size used to layout the text.
2516 mImpl->mModel->mVisualModel->mControlSize = size;
2519 // Whether there are modify events.
2520 if( 0u != mImpl->mModifyEvents.Count() )
2522 // Style operations that need to be done if the text is modified.
2523 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2527 // Set the update info to elide the text.
2528 if( mImpl->mModel->mElideEnabled ||
2529 ( ( NULL != mImpl->mEventData ) && mImpl->mEventData->mIsPlaceholderElideEnabled ) )
2531 // Update Text layout for applying elided
2532 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2535 UPDATE_LAYOUT_SIZE |
2537 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2538 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2541 if( mImpl->mModel->mMatchSystemLanguageDirection && mImpl->mLayoutDirection != layoutDirection )
2543 // Clear the update info. This info will be set the next time the text is updated.
2544 mImpl->mTextUpdateInfo.mClearAll = true;
2545 // Apply modifications to the model
2546 // Shape the text again is needed because characters like '()[]{}' have to be mirrored and the glyphs generated again.
2547 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2554 mImpl->mLayoutDirection = layoutDirection;
2557 // Make sure the model is up-to-date before layouting.
2558 ProcessModifyEvents();
2559 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
2563 updated = DoRelayout( size,
2564 mImpl->mOperationsPending,
2565 layoutSize ) || updated;
2570 updateTextType = MODEL_UPDATED;
2573 // Do not re-do any operation until something changes.
2574 mImpl->mOperationsPending = NO_OPERATION;
2575 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
2577 // Whether the text control is editable
2578 const bool isEditable = NULL != mImpl->mEventData;
2580 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
2582 if( newSize && isEditable )
2584 offset = mImpl->mModel->mScrollPosition;
2587 if( !isEditable || !IsMultiLineEnabled() )
2589 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
2590 CalculateVerticalOffset( size );
2597 // If there is a new size, the scroll position needs to be clamped.
2598 mImpl->ClampHorizontalScroll( layoutSize );
2600 // Update the decorator's positions is needed if there is a new size.
2601 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
2604 // Move the cursor, grab handle etc.
2605 if( mImpl->ProcessInputEvents() )
2607 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
2611 // Clear the update info. This info will be set the next time the text is updated.
2612 mImpl->mTextUpdateInfo.Clear();
2613 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
2615 return updateTextType;
2618 void Controller::RequestRelayout()
2620 mImpl->RequestRelayout();
2623 // public : Input style change signals.
2625 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
2627 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
2630 void Controller::ProcessInputStyleChangedSignals()
2632 if( NULL == mImpl->mEventData )
2638 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
2639 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
2643 const InputStyle::Mask mask = *it;
2645 if( NULL != mImpl->mEditableControlInterface )
2647 // Emit the input style changed signal.
2648 mImpl->mEditableControlInterface->InputStyleChanged( mask );
2652 mImpl->mEventData->mInputStyleChangedQueue.Clear();
2655 // public : Text-input Event Queuing.
2657 void Controller::KeyboardFocusGainEvent()
2659 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
2661 if( NULL != mImpl->mEventData )
2663 if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
2664 ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
2666 mImpl->ChangeState( EventData::EDITING );
2667 mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
2668 mImpl->mEventData->mUpdateInputStyle = true;
2669 mImpl->mEventData->mScrollAfterUpdatePosition = true;
2671 mImpl->NotifyInputMethodContextMultiLineStatus();
2672 if( mImpl->IsShowingPlaceholderText() )
2674 // Show alternative placeholder-text when editing
2675 ShowPlaceholderText();
2678 mImpl->RequestRelayout();
2682 void Controller::KeyboardFocusLostEvent()
2684 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
2686 if( NULL != mImpl->mEventData )
2688 if( EventData::INTERRUPTED != mImpl->mEventData->mState )
2690 mImpl->ChangeState( EventData::INACTIVE );
2692 if( !mImpl->IsShowingRealText() )
2694 // Revert to regular placeholder-text when not editing
2695 ShowPlaceholderText();
2699 mImpl->RequestRelayout();
2702 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
2704 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
2706 bool textChanged = false;
2707 bool relayoutNeeded = false;
2709 if( ( NULL != mImpl->mEventData ) &&
2710 ( keyEvent.state == KeyEvent::Down ) )
2712 int keyCode = keyEvent.keyCode;
2713 const std::string& keyString = keyEvent.keyPressed;
2714 const std::string keyName = keyEvent.keyPressedName;
2716 const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
2718 // Pre-process to separate modifying events from non-modifying input events.
2721 // In some platforms arrive key events with no key code.
2725 else if( Dali::DALI_KEY_ESCAPE == keyCode || Dali::DALI_KEY_BACK == keyCode || Dali::DALI_KEY_SEARCH == keyCode )
2730 else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) ||
2731 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
2732 ( Dali::DALI_KEY_CURSOR_UP == keyCode ) ||
2733 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) )
2735 // If don't have any text, do nothing.
2736 if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
2741 uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition;
2742 uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2743 uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition );
2744 uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines();
2746 // Logic to determine whether this text control will lose focus or not.
2747 if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2748 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2749 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) ||
2750 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) ||
2751 ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) ||
2752 ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) )
2754 // Release the active highlight.
2755 if( mImpl->mEventData->mState == EventData::SELECTING )
2757 mImpl->ChangeState( EventData::EDITING );
2759 // Update selection position.
2760 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2761 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2762 mImpl->mEventData->mUpdateCursorPosition = true;
2763 mImpl->RequestRelayout();
2768 mImpl->mEventData->mCheckScrollAmount = true;
2769 Event event( Event::CURSOR_KEY_EVENT );
2770 event.p1.mInt = keyCode;
2771 event.p2.mBool = keyEvent.IsShiftModifier();
2772 mImpl->mEventData->mEventQueue.push_back( event );
2774 // Will request for relayout.
2775 relayoutNeeded = true;
2777 else if ( Dali::DevelKey::DALI_KEY_CONTROL_LEFT == keyCode || Dali::DevelKey::DALI_KEY_CONTROL_RIGHT == keyCode )
2779 // Left or Right Control key event is received before Ctrl-C/V/X key event is received
2780 // If not handle it here, any selected text will be deleted
2785 else if ( keyEvent.IsCtrlModifier() )
2787 bool consumed = false;
2788 if (keyName == KEY_C_NAME)
2790 // Ctrl-C to copy the selected text
2791 TextPopupButtonTouched( Toolkit::TextSelectionPopup::COPY );
2794 else if (keyName == KEY_V_NAME)
2796 // Ctrl-V to paste the copied text
2797 TextPopupButtonTouched( Toolkit::TextSelectionPopup::PASTE );
2800 else if (keyName == KEY_X_NAME)
2802 // Ctrl-X to cut the selected text
2803 TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
2808 else if( ( Dali::DALI_KEY_BACKSPACE == keyCode ) ||
2809 ( Dali::DevelKey::DALI_KEY_DELETE == keyCode ) )
2811 textChanged = DeleteEvent( keyCode );
2813 // Will request for relayout.
2814 relayoutNeeded = true;
2816 else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
2817 IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
2818 IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
2820 // Power key/Menu/Home key behaviour does not allow edit mode to resume.
2821 mImpl->ChangeState( EventData::INACTIVE );
2823 // Will request for relayout.
2824 relayoutNeeded = true;
2826 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2828 else if( ( Dali::DALI_KEY_SHIFT_LEFT == keyCode ) || ( Dali::DALI_KEY_SHIFT_RIGHT == keyCode ) )
2830 // 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
2831 // and a character is typed after the type of a upper case latin character.
2836 else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
2838 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2844 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
2846 if( !keyString.empty() )
2848 // InputMethodContext is no longer handling key-events
2849 mImpl->ClearPreEditFlag();
2851 InsertText( keyString, COMMIT );
2855 // Will request for relayout.
2856 relayoutNeeded = true;
2861 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
2862 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
2864 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
2865 ( Dali::DALI_KEY_SHIFT_RIGHT != keyCode ) &&
2866 ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
2867 ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
2869 // Should not change the state if the key is the shift send by the InputMethodContext.
2870 // Otherwise, when the state is SELECTING the text controller can't send the right
2871 // surrounding info to the InputMethodContext.
2872 mImpl->ChangeState( EventData::EDITING );
2874 // Will request for relayout.
2875 relayoutNeeded = true;
2878 if( relayoutNeeded )
2880 mImpl->RequestRelayout();
2885 ( NULL != mImpl->mEditableControlInterface ) )
2887 // Do this last since it provides callbacks into application code
2888 mImpl->mEditableControlInterface->TextChanged();
2894 void Controller::TapEvent( unsigned int tapCount, float x, float y )
2896 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
2898 if( NULL != mImpl->mEventData )
2900 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
2901 EventData::State state( mImpl->mEventData->mState );
2902 bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
2904 if( mImpl->IsClipboardVisible() )
2906 if( EventData::INACTIVE == state || EventData::EDITING == state)
2908 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2910 relayoutNeeded = true;
2912 else if( 1u == tapCount )
2914 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
2916 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
2919 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
2921 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2922 relayoutNeeded = true;
2926 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
2928 // Hide placeholder text
2932 if( EventData::INACTIVE == state )
2934 mImpl->ChangeState( EventData::EDITING );
2936 else if( !mImpl->IsClipboardEmpty() )
2938 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
2940 relayoutNeeded = true;
2943 else if( 2u == tapCount )
2945 if( mImpl->mEventData->mSelectionEnabled &&
2946 mImpl->IsShowingRealText() )
2948 relayoutNeeded = true;
2949 mImpl->mEventData->mIsLeftHandleSelected = true;
2950 mImpl->mEventData->mIsRightHandleSelected = true;
2954 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
2955 if( relayoutNeeded )
2957 Event event( Event::TAP_EVENT );
2958 event.p1.mUint = tapCount;
2959 event.p2.mFloat = x;
2960 event.p3.mFloat = y;
2961 mImpl->mEventData->mEventQueue.push_back( event );
2963 mImpl->RequestRelayout();
2967 // Reset keyboard as tap event has occurred.
2968 mImpl->ResetInputMethodContext();
2971 void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
2973 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
2975 if( NULL != mImpl->mEventData )
2977 Event event( Event::PAN_EVENT );
2978 event.p1.mInt = state;
2979 event.p2.mFloat = displacement.x;
2980 event.p3.mFloat = displacement.y;
2981 mImpl->mEventData->mEventQueue.push_back( event );
2983 mImpl->RequestRelayout();
2987 void Controller::LongPressEvent( Gesture::State state, float x, float y )
2989 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
2991 if( ( state == Gesture::Started ) &&
2992 ( NULL != mImpl->mEventData ) )
2994 // The 1st long-press on inactive text-field is treated as tap
2995 if( EventData::INACTIVE == mImpl->mEventData->mState )
2997 mImpl->ChangeState( EventData::EDITING );
2999 Event event( Event::TAP_EVENT );
3001 event.p2.mFloat = x;
3002 event.p3.mFloat = y;
3003 mImpl->mEventData->mEventQueue.push_back( event );
3005 mImpl->RequestRelayout();
3007 else if( !mImpl->IsShowingRealText() )
3009 Event event( Event::LONG_PRESS_EVENT );
3010 event.p1.mInt = state;
3011 event.p2.mFloat = x;
3012 event.p3.mFloat = y;
3013 mImpl->mEventData->mEventQueue.push_back( event );
3014 mImpl->RequestRelayout();
3016 else if( !mImpl->IsClipboardVisible() )
3018 // Reset the InputMethodContext to commit the pre-edit before selecting the text.
3019 mImpl->ResetInputMethodContext();
3021 Event event( Event::LONG_PRESS_EVENT );
3022 event.p1.mInt = state;
3023 event.p2.mFloat = x;
3024 event.p3.mFloat = y;
3025 mImpl->mEventData->mEventQueue.push_back( event );
3026 mImpl->RequestRelayout();
3028 mImpl->mEventData->mIsLeftHandleSelected = true;
3029 mImpl->mEventData->mIsRightHandleSelected = true;
3034 void Controller::SelectEvent( float x, float y, bool selectAll )
3036 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
3038 if( NULL != mImpl->mEventData )
3042 Event event( Event::SELECT_ALL );
3043 mImpl->mEventData->mEventQueue.push_back( event );
3047 Event event( Event::SELECT );
3048 event.p2.mFloat = x;
3049 event.p3.mFloat = y;
3050 mImpl->mEventData->mEventQueue.push_back( event );
3053 mImpl->mEventData->mCheckScrollAmount = true;
3054 mImpl->mEventData->mIsLeftHandleSelected = true;
3055 mImpl->mEventData->mIsRightHandleSelected = true;
3056 mImpl->RequestRelayout();
3060 InputMethodContext::CallbackData Controller::OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
3062 // Whether the text needs to be relaid-out.
3063 bool requestRelayout = false;
3065 // Whether to retrieve the text and cursor position to be sent to the InputMethodContext.
3066 bool retrieveText = false;
3067 bool retrieveCursor = false;
3069 switch( inputMethodContextEvent.eventName )
3071 case InputMethodContext::COMMIT:
3073 InsertText( inputMethodContextEvent.predictiveString, Text::Controller::COMMIT );
3074 requestRelayout = true;
3075 retrieveCursor = true;
3078 case InputMethodContext::PRE_EDIT:
3080 InsertText( inputMethodContextEvent.predictiveString, Text::Controller::PRE_EDIT );
3081 requestRelayout = true;
3082 retrieveCursor = true;
3085 case InputMethodContext::DELETE_SURROUNDING:
3087 const bool textDeleted = RemoveText( inputMethodContextEvent.cursorOffset,
3088 inputMethodContextEvent.numberOfChars,
3089 DONT_UPDATE_INPUT_STYLE );
3093 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3094 !mImpl->IsPlaceholderAvailable() )
3096 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3100 ShowPlaceholderText();
3102 mImpl->mEventData->mUpdateCursorPosition = true;
3103 mImpl->mEventData->mScrollAfterDelete = true;
3105 requestRelayout = true;
3109 case InputMethodContext::GET_SURROUNDING:
3111 retrieveText = true;
3112 retrieveCursor = true;
3115 case InputMethodContext::PRIVATE_COMMAND:
3117 // PRIVATECOMMAND event is just for getting the private command message
3118 retrieveText = true;
3119 retrieveCursor = true;
3122 case InputMethodContext::VOID:
3129 if( requestRelayout )
3131 mImpl->mOperationsPending = ALL_OPERATIONS;
3132 mImpl->RequestRelayout();
3136 CharacterIndex cursorPosition = 0u;
3137 Length numberOfWhiteSpaces = 0u;
3139 if( retrieveCursor )
3141 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
3143 cursorPosition = mImpl->GetLogicalCursorPosition();
3145 if( cursorPosition < numberOfWhiteSpaces )
3147 cursorPosition = 0u;
3151 cursorPosition -= numberOfWhiteSpaces;
3157 if( !mImpl->IsShowingPlaceholderText() )
3159 // Retrieves the normal text string.
3160 mImpl->GetText( numberOfWhiteSpaces, text );
3164 // When the current text is Placeholder Text, the surrounding text should be empty string.
3165 // It means DALi should send empty string ("") to IME.
3170 InputMethodContext::CallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
3172 if( requestRelayout &&
3173 ( NULL != mImpl->mEditableControlInterface ) )
3175 // Do this last since it provides callbacks into application code
3176 mImpl->mEditableControlInterface->TextChanged();
3179 return callbackData;
3182 void Controller::PasteClipboardItemEvent()
3184 // Retrieve the clipboard contents first
3185 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
3186 std::string stringToPaste( notifier.GetContent() );
3188 // Commit the current pre-edit text; the contents of the clipboard should be appended
3189 mImpl->ResetInputMethodContext();
3191 // Temporary disable hiding clipboard
3192 mImpl->SetClipboardHideEnable( false );
3195 PasteText( stringToPaste );
3197 mImpl->SetClipboardHideEnable( true );
3200 // protected : Inherit from Text::Decorator::ControllerInterface.
3202 void Controller::GetTargetSize( Vector2& targetSize )
3204 targetSize = mImpl->mModel->mVisualModel->mControlSize;
3207 void Controller::AddDecoration( Actor& actor, bool needsClipping )
3209 if( NULL != mImpl->mEditableControlInterface )
3211 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
3215 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
3217 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
3219 if( NULL != mImpl->mEventData )
3221 switch( handleType )
3225 Event event( Event::GRAB_HANDLE_EVENT );
3226 event.p1.mUint = state;
3227 event.p2.mFloat = x;
3228 event.p3.mFloat = y;
3230 mImpl->mEventData->mEventQueue.push_back( event );
3233 case LEFT_SELECTION_HANDLE:
3235 Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
3236 event.p1.mUint = state;
3237 event.p2.mFloat = x;
3238 event.p3.mFloat = y;
3240 mImpl->mEventData->mEventQueue.push_back( event );
3243 case RIGHT_SELECTION_HANDLE:
3245 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
3246 event.p1.mUint = state;
3247 event.p2.mFloat = x;
3248 event.p3.mFloat = y;
3250 mImpl->mEventData->mEventQueue.push_back( event );
3253 case LEFT_SELECTION_HANDLE_MARKER:
3254 case RIGHT_SELECTION_HANDLE_MARKER:
3256 // Markers do not move the handles.
3259 case HANDLE_TYPE_COUNT:
3261 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
3265 mImpl->RequestRelayout();
3269 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
3271 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
3273 if( NULL == mImpl->mEventData )
3280 case Toolkit::TextSelectionPopup::CUT:
3282 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
3283 mImpl->mOperationsPending = ALL_OPERATIONS;
3285 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3286 !mImpl->IsPlaceholderAvailable() )
3288 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3292 ShowPlaceholderText();
3295 mImpl->mEventData->mUpdateCursorPosition = true;
3296 mImpl->mEventData->mScrollAfterDelete = true;
3298 mImpl->RequestRelayout();
3300 if( NULL != mImpl->mEditableControlInterface )
3302 mImpl->mEditableControlInterface->TextChanged();
3306 case Toolkit::TextSelectionPopup::COPY:
3308 mImpl->SendSelectionToClipboard( false ); // Text not modified
3310 mImpl->mEventData->mUpdateCursorPosition = true;
3312 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
3315 case Toolkit::TextSelectionPopup::PASTE:
3317 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
3320 case Toolkit::TextSelectionPopup::SELECT:
3322 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
3324 if( mImpl->mEventData->mSelectionEnabled )
3326 // Creates a SELECT event.
3327 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
3331 case Toolkit::TextSelectionPopup::SELECT_ALL:
3333 // Creates a SELECT_ALL event
3334 SelectEvent( 0.f, 0.f, true );
3337 case Toolkit::TextSelectionPopup::CLIPBOARD:
3339 mImpl->ShowClipboard();
3342 case Toolkit::TextSelectionPopup::NONE:
3350 void Controller::DisplayTimeExpired()
3352 mImpl->mEventData->mUpdateCursorPosition = true;
3353 // Apply modifications to the model
3354 mImpl->mOperationsPending = ALL_OPERATIONS;
3356 mImpl->RequestRelayout();
3359 // private : Update.
3361 void Controller::InsertText( const std::string& text, Controller::InsertType type )
3363 bool removedPrevious = false;
3364 bool removedSelected = false;
3365 bool maxLengthReached = false;
3367 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
3369 if( NULL == mImpl->mEventData )
3374 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
3375 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
3376 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3378 // TODO: At the moment the underline runs are only for pre-edit.
3379 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
3381 // Remove the previous InputMethodContext pre-edit.
3382 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
3384 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
3385 mImpl->mEventData->mPreEditLength,
3386 DONT_UPDATE_INPUT_STYLE );
3388 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
3389 mImpl->mEventData->mPreEditLength = 0u;
3393 // Remove the previous Selection.
3394 removedSelected = RemoveSelectedText();
3398 Vector<Character> utf32Characters;
3399 Length characterCount = 0u;
3403 // Convert text into UTF-32
3404 utf32Characters.Resize( text.size() );
3406 // This is a bit horrible but std::string returns a (signed) char*
3407 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
3409 // Transform a text array encoded in utf8 into an array encoded in utf32.
3410 // It returns the actual number of characters.
3411 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
3412 utf32Characters.Resize( characterCount );
3414 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
3415 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
3418 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
3420 // The placeholder text is no longer needed
3421 if( mImpl->IsShowingPlaceholderText() )
3426 mImpl->ChangeState( EventData::EDITING );
3428 // Handle the InputMethodContext (predicitive text) state changes
3429 if( COMMIT == type )
3431 // InputMethodContext is no longer handling key-events
3432 mImpl->ClearPreEditFlag();
3436 if( !mImpl->mEventData->mPreEditFlag )
3438 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
3440 // Record the start of the pre-edit text
3441 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
3444 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
3445 mImpl->mEventData->mPreEditFlag = true;
3447 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3450 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
3452 // Restrict new text to fit within Maximum characters setting.
3453 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
3454 maxLengthReached = ( characterCount > maxSizeOfNewText );
3456 // The cursor position.
3457 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3459 // Update the text's style.
3461 // Updates the text style runs by adding characters.
3462 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
3464 // Get the character index from the cursor index.
3465 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
3467 // Retrieve the text's style for the given index.
3469 mImpl->RetrieveDefaultInputStyle( style );
3470 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
3472 // Whether to add a new text color run.
3473 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor ) && !mImpl->mEventData->mInputStyle.isDefaultColor;
3475 // Whether to add a new font run.
3476 const bool addFontNameRun = ( style.familyName != mImpl->mEventData->mInputStyle.familyName ) && mImpl->mEventData->mInputStyle.isFamilyDefined;
3477 const bool addFontWeightRun = ( style.weight != mImpl->mEventData->mInputStyle.weight ) && mImpl->mEventData->mInputStyle.isWeightDefined;
3478 const bool addFontWidthRun = ( style.width != mImpl->mEventData->mInputStyle.width ) && mImpl->mEventData->mInputStyle.isWidthDefined;
3479 const bool addFontSlantRun = ( style.slant != mImpl->mEventData->mInputStyle.slant ) && mImpl->mEventData->mInputStyle.isSlantDefined;
3480 const bool addFontSizeRun = ( style.size != mImpl->mEventData->mInputStyle.size ) && mImpl->mEventData->mInputStyle.isSizeDefined ;
3485 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
3486 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
3488 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
3489 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
3490 colorRun.characterRun.characterIndex = cursorIndex;
3491 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3494 if( addFontNameRun ||
3500 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
3501 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
3503 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
3505 if( addFontNameRun )
3507 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
3508 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
3509 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
3510 fontDescriptionRun.familyDefined = true;
3512 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
3515 if( addFontWeightRun )
3517 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
3518 fontDescriptionRun.weightDefined = true;
3521 if( addFontWidthRun )
3523 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
3524 fontDescriptionRun.widthDefined = true;
3527 if( addFontSlantRun )
3529 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
3530 fontDescriptionRun.slantDefined = true;
3533 if( addFontSizeRun )
3535 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
3536 fontDescriptionRun.sizeDefined = true;
3539 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
3540 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3543 // Insert at current cursor position.
3544 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
3546 if( cursorIndex < numberOfCharactersInModel )
3548 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3552 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3555 // Mark the first paragraph to be updated.
3556 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3558 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3559 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3560 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
3561 mImpl->mTextUpdateInfo.mClearAll = true;
3565 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3566 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
3569 // Update the cursor index.
3570 cursorIndex += maxSizeOfNewText;
3572 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 );
3575 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
3576 mImpl->IsPlaceholderAvailable() )
3578 // Show place-holder if empty after removing the pre-edit text
3579 ShowPlaceholderText();
3580 mImpl->mEventData->mUpdateCursorPosition = true;
3581 mImpl->ClearPreEditFlag();
3583 else if( removedPrevious ||
3585 ( 0 != utf32Characters.Count() ) )
3587 // Queue an inserted event
3588 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
3590 mImpl->mEventData->mUpdateCursorPosition = true;
3591 if( removedSelected )
3593 mImpl->mEventData->mScrollAfterDelete = true;
3597 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3601 if( maxLengthReached )
3603 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
3605 mImpl->ResetInputMethodContext();
3607 if( NULL != mImpl->mEditableControlInterface )
3609 // Do this last since it provides callbacks into application code
3610 mImpl->mEditableControlInterface->MaxLengthReached();
3615 void Controller::PasteText( const std::string& stringToPaste )
3617 InsertText( stringToPaste, Text::Controller::COMMIT );
3618 mImpl->ChangeState( EventData::EDITING );
3619 mImpl->RequestRelayout();
3621 if( NULL != mImpl->mEditableControlInterface )
3623 // Do this last since it provides callbacks into application code
3624 mImpl->mEditableControlInterface->TextChanged();
3628 bool Controller::RemoveText( int cursorOffset,
3629 int numberOfCharacters,
3630 UpdateInputStyleType type )
3632 bool removed = false;
3634 if( NULL == mImpl->mEventData )
3639 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
3640 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
3642 if( !mImpl->IsShowingPlaceholderText() )
3644 // Delete at current cursor position
3645 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
3646 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3648 CharacterIndex cursorIndex = 0;
3650 // Validate the cursor position & number of characters
3651 if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
3653 cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
3656 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
3658 numberOfCharacters = currentText.Count() - cursorIndex;
3661 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.
3662 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
3664 // Mark the paragraphs to be updated.
3665 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3667 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3668 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3669 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
3670 mImpl->mTextUpdateInfo.mClearAll = true;
3674 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3675 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
3678 // Update the input style and remove the text's style before removing the text.
3680 if( UPDATE_INPUT_STYLE == type )
3682 // Keep a copy of the current input style.
3683 InputStyle currentInputStyle;
3684 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
3686 // Set first the default input style.
3687 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
3689 // Update the input style.
3690 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
3692 // Compare if the input style has changed.
3693 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
3695 if( hasInputStyleChanged )
3697 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
3698 // Queue the input style changed signal.
3699 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
3703 // Updates the text style runs by removing characters. Runs with no characters are removed.
3704 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
3706 // Remove the characters.
3707 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
3708 Vector<Character>::Iterator last = first + numberOfCharacters;
3710 currentText.Erase( first, last );
3712 // Cursor position retreat
3713 oldCursorIndex = cursorIndex;
3715 mImpl->mEventData->mScrollAfterDelete = true;
3717 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
3725 bool Controller::RemoveSelectedText()
3727 bool textRemoved( false );
3729 if( EventData::SELECTING == mImpl->mEventData->mState )
3731 std::string removedString;
3732 mImpl->RetrieveSelection( removedString, true );
3734 if( !removedString.empty() )
3737 mImpl->ChangeState( EventData::EDITING );
3744 // private : Relayout.
3746 bool Controller::DoRelayout( const Size& size,
3747 OperationsMask operationsRequired,
3750 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
3751 bool viewUpdated( false );
3753 // Calculate the operations to be done.
3754 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
3756 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
3757 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
3759 // Get the current layout size.
3760 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3762 if( NO_OPERATION != ( LAYOUT & operations ) )
3764 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
3766 // Some vectors with data needed to layout and reorder may be void
3767 // after the first time the text has been laid out.
3768 // Fill the vectors again.
3770 // Calculate the number of glyphs to layout.
3771 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
3772 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
3773 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
3774 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
3776 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
3777 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
3779 // Make sure the index is not out of bound
3780 if ( charactersToGlyph.Count() != glyphsPerCharacter.Count() ||
3781 requestedNumberOfCharacters > charactersToGlyph.Count() ||
3782 ( lastIndex > charactersToGlyph.Count() && charactersToGlyph.Count() > 0u ) )
3784 std::string currentText;
3785 GetText( currentText );
3787 DALI_LOG_ERROR( "Controller::DoRelayout: Attempting to access invalid buffer\n" );
3788 DALI_LOG_ERROR( "Current text is: %s\n", currentText.c_str() );
3789 DALI_LOG_ERROR( "startIndex: %u, lastIndex: %u, requestedNumberOfCharacters: %u, charactersToGlyph.Count = %lu, glyphsPerCharacter.Count = %lu\n", startIndex, lastIndex, requestedNumberOfCharacters, charactersToGlyph.Count(), glyphsPerCharacter.Count());
3794 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
3795 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
3797 if( 0u == totalNumberOfGlyphs )
3799 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3801 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
3804 // Nothing else to do if there is no glyphs.
3805 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
3809 const Vector<LineBreakInfo>& lineBreakInfo = mImpl->mModel->mLogicalModel->mLineBreakInfo;
3810 const Vector<WordBreakInfo>& wordBreakInfo = mImpl->mModel->mLogicalModel->mWordBreakInfo;
3811 const Vector<CharacterDirection>& characterDirection = mImpl->mModel->mLogicalModel->mCharacterDirections;
3812 const Vector<GlyphInfo>& glyphs = mImpl->mModel->mVisualModel->mGlyphs;
3813 const Vector<CharacterIndex>& glyphsToCharactersMap = mImpl->mModel->mVisualModel->mGlyphsToCharacters;
3814 const Vector<Length>& charactersPerGlyph = mImpl->mModel->mVisualModel->mCharactersPerGlyph;
3815 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
3816 const float outlineWidth = static_cast<float>( mImpl->mModel->GetOutlineWidth() );
3818 // Set the layout parameters.
3819 Layout::Parameters layoutParameters( size,
3821 lineBreakInfo.Begin(),
3822 wordBreakInfo.Begin(),
3823 ( 0u != characterDirection.Count() ) ? characterDirection.Begin() : NULL,
3825 glyphsToCharactersMap.Begin(),
3826 charactersPerGlyph.Begin(),
3827 charactersToGlyphBuffer,
3828 glyphsPerCharacterBuffer,
3829 totalNumberOfGlyphs,
3830 mImpl->mModel->mHorizontalAlignment,
3831 mImpl->mModel->mLineWrapMode,
3833 mImpl->mModel->mIgnoreSpacesAfterText,
3834 mImpl->mModel->mMatchSystemLanguageDirection );
3836 // Resize the vector of positions to have the same size than the vector of glyphs.
3837 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
3838 glyphPositions.Resize( totalNumberOfGlyphs );
3840 // Whether the last character is a new paragraph character.
3841 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
3842 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
3844 // The initial glyph and the number of glyphs to layout.
3845 layoutParameters.startGlyphIndex = startGlyphIndex;
3846 layoutParameters.numberOfGlyphs = numberOfGlyphs;
3847 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
3848 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
3850 // Update the ellipsis
3851 bool elideTextEnabled = mImpl->mModel->mElideEnabled;
3853 if( NULL != mImpl->mEventData )
3855 if( mImpl->mEventData->mPlaceholderEllipsisFlag && mImpl->IsShowingPlaceholderText() )
3857 elideTextEnabled = mImpl->mEventData->mIsPlaceholderElideEnabled;
3859 else if( EventData::INACTIVE != mImpl->mEventData->mState )
3861 // Disable ellipsis when editing
3862 elideTextEnabled = false;
3865 // Reset the scroll position in inactive state
3866 if( elideTextEnabled && ( mImpl->mEventData->mState == EventData::INACTIVE ) )
3868 ResetScrollPosition();
3872 // Update the visual model.
3873 bool isAutoScrollEnabled = mImpl->mIsAutoScrollEnabled;
3875 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
3877 mImpl->mModel->mVisualModel->mLines,
3880 isAutoScrollEnabled );
3881 mImpl->mIsAutoScrollEnabled = isAutoScrollEnabled;
3883 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
3887 layoutSize = newLayoutSize;
3889 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
3891 mImpl->mIsTextDirectionRTL = false;
3894 // Reorder the lines
3895 if( NO_OPERATION != ( REORDER & operations ) )
3897 Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = mImpl->mModel->mLogicalModel->mBidirectionalParagraphInfo;
3898 Vector<BidirectionalLineInfoRun>& bidirectionalLineInfo = mImpl->mModel->mLogicalModel->mBidirectionalLineInfo;
3900 // Check first if there are paragraphs with bidirectional info.
3901 if( 0u != bidirectionalInfo.Count() )
3904 const Length numberOfLines = mImpl->mModel->mVisualModel->mLines.Count();
3906 // Reorder the lines.
3907 bidirectionalLineInfo.Reserve( numberOfLines ); // Reserve because is not known yet how many lines have right to left characters.
3908 ReorderLines( bidirectionalInfo,
3910 requestedNumberOfCharacters,
3911 mImpl->mModel->mVisualModel->mLines,
3912 bidirectionalLineInfo );
3914 // Set the bidirectional info per line into the layout parameters.
3915 layoutParameters.lineBidirectionalInfoRunsBuffer = bidirectionalLineInfo.Begin();
3916 layoutParameters.numberOfBidirectionalInfoRuns = bidirectionalLineInfo.Count();
3918 // Re-layout the text. Reorder those lines with right to left characters.
3919 mImpl->mLayoutEngine.ReLayoutRightToLeftLines( layoutParameters,
3921 requestedNumberOfCharacters,
3924 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && ( numberOfLines > 0 ) )
3926 const LineRun* const firstline = mImpl->mModel->mVisualModel->mLines.Begin();
3929 mImpl->mIsTextDirectionRTL = firstline->direction;
3935 // Sets the layout size.
3936 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3938 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
3943 if( NO_OPERATION != ( ALIGN & operations ) )
3945 // The laid-out lines.
3946 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
3948 // Need to align with the control's size as the text may contain lines
3949 // starting either with left to right text or right to left.
3950 mImpl->mLayoutEngine.Align( size,
3952 requestedNumberOfCharacters,
3953 mImpl->mModel->mHorizontalAlignment,
3955 mImpl->mModel->mAlignmentOffset,
3956 mImpl->mLayoutDirection,
3957 mImpl->mModel->mMatchSystemLanguageDirection );
3961 #if defined(DEBUG_ENABLED)
3962 std::string currentText;
3963 GetText( currentText );
3964 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mIsTextDirectionRTL[%s] [%s]\n", this, (mImpl->mIsTextDirectionRTL)?"true":"false", currentText.c_str() );
3966 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
3970 void Controller::CalculateVerticalOffset( const Size& controlSize )
3972 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3974 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
3976 // Get the line height of the default font.
3977 layoutSize.height = mImpl->GetDefaultFontLineHeight();
3980 switch( mImpl->mModel->mVerticalAlignment )
3982 case VerticalAlignment::TOP:
3984 mImpl->mModel->mScrollPosition.y = 0.f;
3987 case VerticalAlignment::CENTER:
3989 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
3992 case VerticalAlignment::BOTTOM:
3994 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
4000 // private : Events.
4002 void Controller::ProcessModifyEvents()
4004 Vector<ModifyEvent>& events = mImpl->mModifyEvents;
4006 if( 0u == events.Count() )
4012 for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
4013 endIt = events.End();
4017 const ModifyEvent& event = *it;
4019 if( ModifyEvent::TEXT_REPLACED == event.type )
4021 // A (single) replace event should come first, otherwise we wasted time processing NOOP events
4022 DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
4024 TextReplacedEvent();
4026 else if( ModifyEvent::TEXT_INSERTED == event.type )
4028 TextInsertedEvent();
4030 else if( ModifyEvent::TEXT_DELETED == event.type )
4032 // Placeholder-text cannot be deleted
4033 if( !mImpl->IsShowingPlaceholderText() )
4040 if( NULL != mImpl->mEventData )
4042 // When the text is being modified, delay cursor blinking
4043 mImpl->mEventData->mDecorator->DelayCursorBlink();
4045 // Update selection position after modifying the text
4046 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
4047 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
4050 // Discard temporary text
4054 void Controller::TextReplacedEvent()
4056 // The natural size needs to be re-calculated.
4057 mImpl->mRecalculateNaturalSize = true;
4059 // The text direction needs to be updated.
4060 mImpl->mUpdateTextDirection = true;
4062 // Apply modifications to the model
4063 mImpl->mOperationsPending = ALL_OPERATIONS;
4066 void Controller::TextInsertedEvent()
4068 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
4070 if( NULL == mImpl->mEventData )
4075 mImpl->mEventData->mCheckScrollAmount = true;
4077 // The natural size needs to be re-calculated.
4078 mImpl->mRecalculateNaturalSize = true;
4080 // The text direction needs to be updated.
4081 mImpl->mUpdateTextDirection = true;
4083 // Apply modifications to the model; TODO - Optimize this
4084 mImpl->mOperationsPending = ALL_OPERATIONS;
4087 void Controller::TextDeletedEvent()
4089 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
4091 if( NULL == mImpl->mEventData )
4096 mImpl->mEventData->mCheckScrollAmount = true;
4098 // The natural size needs to be re-calculated.
4099 mImpl->mRecalculateNaturalSize = true;
4101 // The text direction needs to be updated.
4102 mImpl->mUpdateTextDirection = true;
4104 // Apply modifications to the model; TODO - Optimize this
4105 mImpl->mOperationsPending = ALL_OPERATIONS;
4108 bool Controller::DeleteEvent( int keyCode )
4110 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p KeyCode : %d \n", this, keyCode );
4112 bool removed = false;
4114 if( NULL == mImpl->mEventData )
4119 // InputMethodContext is no longer handling key-events
4120 mImpl->ClearPreEditFlag();
4122 if( EventData::SELECTING == mImpl->mEventData->mState )
4124 removed = RemoveSelectedText();
4126 else if( ( mImpl->mEventData->mPrimaryCursorPosition > 0 ) && ( keyCode == Dali::DALI_KEY_BACKSPACE) )
4128 // Remove the character before the current cursor position
4129 removed = RemoveText( -1,
4131 UPDATE_INPUT_STYLE );
4133 else if( keyCode == Dali::DevelKey::DALI_KEY_DELETE )
4135 // Remove the character after the current cursor position
4136 removed = RemoveText( 0,
4138 UPDATE_INPUT_STYLE );
4143 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
4144 !mImpl->IsPlaceholderAvailable() )
4146 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
4150 ShowPlaceholderText();
4152 mImpl->mEventData->mUpdateCursorPosition = true;
4153 mImpl->mEventData->mScrollAfterDelete = true;
4159 // private : Helpers.
4161 void Controller::ResetText()
4164 mImpl->mModel->mLogicalModel->mText.Clear();
4166 // Reset the embedded images buffer.
4167 mImpl->mModel->mLogicalModel->ClearEmbeddedImages();
4169 // We have cleared everything including the placeholder-text
4170 mImpl->PlaceholderCleared();
4172 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4173 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4174 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
4176 // Clear any previous text.
4177 mImpl->mTextUpdateInfo.mClearAll = true;
4179 // The natural size needs to be re-calculated.
4180 mImpl->mRecalculateNaturalSize = true;
4182 // The text direction needs to be updated.
4183 mImpl->mUpdateTextDirection = true;
4185 // Apply modifications to the model
4186 mImpl->mOperationsPending = ALL_OPERATIONS;
4189 void Controller::ShowPlaceholderText()
4191 if( mImpl->IsPlaceholderAvailable() )
4193 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
4195 if( NULL == mImpl->mEventData )
4200 mImpl->mEventData->mIsShowingPlaceholderText = true;
4202 // Disable handles when showing place-holder text
4203 mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
4204 mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
4205 mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
4207 const char* text( NULL );
4210 // TODO - Switch Placeholder text when changing state
4211 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
4212 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
4214 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
4215 size = mImpl->mEventData->mPlaceholderTextActive.size();
4219 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
4220 size = mImpl->mEventData->mPlaceholderTextInactive.size();
4223 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4224 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4226 // Reset model for showing placeholder.
4227 mImpl->mModel->mLogicalModel->mText.Clear();
4228 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
4230 // Convert text into UTF-32
4231 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
4232 utf32Characters.Resize( size );
4234 // This is a bit horrible but std::string returns a (signed) char*
4235 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
4237 // Transform a text array encoded in utf8 into an array encoded in utf32.
4238 // It returns the actual number of characters.
4239 const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
4240 utf32Characters.Resize( characterCount );
4242 // The characters to be added.
4243 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
4245 // Reset the cursor position
4246 mImpl->mEventData->mPrimaryCursorPosition = 0;
4248 // The natural size needs to be re-calculated.
4249 mImpl->mRecalculateNaturalSize = true;
4251 // The text direction needs to be updated.
4252 mImpl->mUpdateTextDirection = true;
4254 // Apply modifications to the model
4255 mImpl->mOperationsPending = ALL_OPERATIONS;
4257 // Update the rest of the model during size negotiation
4258 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
4262 void Controller::ClearFontData()
4264 if( mImpl->mFontDefaults )
4266 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
4269 // Set flags to update the model.
4270 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4271 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4272 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
4274 mImpl->mTextUpdateInfo.mClearAll = true;
4275 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
4276 mImpl->mRecalculateNaturalSize = true;
4278 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
4284 UPDATE_LAYOUT_SIZE |
4289 void Controller::ClearStyleData()
4291 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
4292 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
4295 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
4297 // Reset the cursor position
4298 if( NULL != mImpl->mEventData )
4300 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
4302 // Update the cursor if it's in editing mode.
4303 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
4305 mImpl->mEventData->mUpdateCursorPosition = true;
4310 void Controller::ResetScrollPosition()
4312 if( NULL != mImpl->mEventData )
4314 // Reset the scroll position.
4315 mImpl->mModel->mScrollPosition = Vector2::ZERO;
4316 mImpl->mEventData->mScrollAfterUpdatePosition = true;
4320 void Controller::SetControlInterface( ControlInterface* controlInterface )
4322 mImpl->mControlInterface = controlInterface;
4325 bool Controller::ShouldClearFocusOnEscape() const
4327 return mImpl->mShouldClearFocusOnEscape;
4330 // private : Private contructors & copy operator.
4332 Controller::Controller()
4335 mImpl = new Controller::Impl( NULL, NULL );
4338 Controller::Controller( ControlInterface* controlInterface )
4340 mImpl = new Controller::Impl( controlInterface, NULL );
4343 Controller::Controller( ControlInterface* controlInterface,
4344 EditableControlInterface* editableControlInterface )
4346 mImpl = new Controller::Impl( controlInterface,
4347 editableControlInterface );
4350 // The copy constructor and operator are left unimplemented.
4352 // protected : Destructor.
4354 Controller::~Controller()
4361 } // namespace Toolkit