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";
66 float ConvertToEven( float value )
68 int intValue(static_cast<int>( value ));
69 return static_cast<float>( intValue + ( intValue & 1 ) );
72 int ConvertPixelToPint( float pixel )
74 unsigned int horizontalDpi = 0u;
75 unsigned int verticalDpi = 0u;
76 Dali::TextAbstraction::FontClient fontClient = Dali::TextAbstraction::FontClient::Get();
77 fontClient.GetDpi( horizontalDpi, verticalDpi );
79 return ( pixel * 72.f ) / static_cast< float >( horizontalDpi );
94 * @brief Adds a new font description run for the selected text.
96 * The new font parameters are added after the call to this method.
98 * @param[in] eventData The event data pointer.
99 * @param[in] logicalModel The logical model where to add the new font description run.
100 * @param[out] startOfSelectedText Index to the first selected character.
101 * @param[out] lengthOfSelectedText Number of selected characters.
103 FontDescriptionRun& UpdateSelectionFontStyleRun( EventData* eventData,
104 LogicalModelPtr logicalModel,
105 CharacterIndex& startOfSelectedText,
106 Length& lengthOfSelectedText )
108 const bool handlesCrossed = eventData->mLeftSelectionPosition > eventData->mRightSelectionPosition;
110 // Get start and end position of selection
111 startOfSelectedText = handlesCrossed ? eventData->mRightSelectionPosition : eventData->mLeftSelectionPosition;
112 lengthOfSelectedText = ( handlesCrossed ? eventData->mLeftSelectionPosition : eventData->mRightSelectionPosition ) - startOfSelectedText;
115 const VectorBase::SizeType numberOfRuns = logicalModel->mFontDescriptionRuns.Count();
116 logicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
118 FontDescriptionRun& fontDescriptionRun = *( logicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
120 fontDescriptionRun.characterRun.characterIndex = startOfSelectedText;
121 fontDescriptionRun.characterRun.numberOfCharacters = lengthOfSelectedText;
123 // Recalculate the selection highlight as the metrics may have changed.
124 eventData->mUpdateLeftSelectionPosition = true;
125 eventData->mUpdateRightSelectionPosition = true;
126 eventData->mUpdateHighlightBox = true;
128 return fontDescriptionRun;
131 // public : Constructor.
133 ControllerPtr Controller::New()
135 return ControllerPtr( new Controller() );
138 ControllerPtr Controller::New( ControlInterface* controlInterface )
140 return ControllerPtr( new Controller( controlInterface ) );
143 ControllerPtr Controller::New( ControlInterface* controlInterface,
144 EditableControlInterface* editableControlInterface )
146 return ControllerPtr( new Controller( controlInterface,
147 editableControlInterface ) );
150 // public : Configure the text controller.
152 void Controller::EnableTextInput( DecoratorPtr decorator, InputMethodContext& inputMethodContext )
156 delete mImpl->mEventData;
157 mImpl->mEventData = NULL;
159 // Nothing else to do.
163 if( NULL == mImpl->mEventData )
165 mImpl->mEventData = new EventData( decorator, inputMethodContext );
169 void Controller::SetGlyphType( TextAbstraction::GlyphType glyphType )
171 // Metrics for bitmap & vector based glyphs are different
172 mImpl->mMetrics->SetGlyphType( glyphType );
174 // Clear the font-specific data
177 mImpl->RequestRelayout();
180 void Controller::SetMarkupProcessorEnabled( bool enable )
182 if( enable != mImpl->mMarkupProcessorEnabled )
184 //If Text was already set, call the SetText again for enabling or disabling markup
185 mImpl->mMarkupProcessorEnabled = enable;
192 bool Controller::IsMarkupProcessorEnabled() const
194 return mImpl->mMarkupProcessorEnabled;
197 void Controller::SetAutoScrollEnabled( bool enable )
199 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 );
201 if( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX )
205 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled for SINGLE_LINE_BOX\n" );
206 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
216 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled Disabling autoscroll\n");
217 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
224 mImpl->mIsAutoScrollEnabled = enable;
225 mImpl->RequestRelayout();
229 DALI_LOG_WARNING( "Attempted AutoScrolling on a non SINGLE_LINE_BOX, request ignored\n" );
230 mImpl->mIsAutoScrollEnabled = false;
234 bool Controller::IsAutoScrollEnabled() const
236 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::IsAutoScrollEnabled[%s]\n", mImpl->mIsAutoScrollEnabled?"true":"false" );
238 return mImpl->mIsAutoScrollEnabled;
241 CharacterDirection Controller::GetAutoScrollDirection() const
243 return mImpl->mIsTextDirectionRTL;
246 float Controller::GetAutoScrollLineAlignment() const
250 if( mImpl->mModel->mVisualModel &&
251 ( 0u != mImpl->mModel->mVisualModel->mLines.Count() ) )
253 offset = ( *mImpl->mModel->mVisualModel->mLines.Begin() ).alignmentOffset;
259 void Controller::SetHorizontalScrollEnabled( bool enable )
261 if( ( NULL != mImpl->mEventData ) &&
262 mImpl->mEventData->mDecorator )
264 mImpl->mEventData->mDecorator->SetHorizontalScrollEnabled( enable );
267 bool Controller::IsHorizontalScrollEnabled() const
269 if( ( NULL != mImpl->mEventData ) &&
270 mImpl->mEventData->mDecorator )
272 return mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
278 void Controller::SetVerticalScrollEnabled( bool enable )
280 if( ( NULL != mImpl->mEventData ) &&
281 mImpl->mEventData->mDecorator )
283 if( mImpl->mEventData->mDecorator )
285 mImpl->mEventData->mDecorator->SetVerticalScrollEnabled( enable );
290 bool Controller::IsVerticalScrollEnabled() const
292 if( ( NULL != mImpl->mEventData ) &&
293 mImpl->mEventData->mDecorator )
295 return mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
301 void Controller::SetSmoothHandlePanEnabled( bool enable )
303 if( ( NULL != mImpl->mEventData ) &&
304 mImpl->mEventData->mDecorator )
306 mImpl->mEventData->mDecorator->SetSmoothHandlePanEnabled( enable );
310 bool Controller::IsSmoothHandlePanEnabled() const
312 if( ( NULL != mImpl->mEventData ) &&
313 mImpl->mEventData->mDecorator )
315 return mImpl->mEventData->mDecorator->IsSmoothHandlePanEnabled();
321 void Controller::SetMaximumNumberOfCharacters( Length maxCharacters )
323 mImpl->mMaximumNumberOfCharacters = maxCharacters;
326 int Controller::GetMaximumNumberOfCharacters()
328 return mImpl->mMaximumNumberOfCharacters;
331 void Controller::SetEnableCursorBlink( bool enable )
333 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "TextInput disabled" );
335 if( NULL != mImpl->mEventData )
337 mImpl->mEventData->mCursorBlinkEnabled = enable;
340 mImpl->mEventData->mDecorator )
342 mImpl->mEventData->mDecorator->StopCursorBlink();
347 bool Controller::GetEnableCursorBlink() const
349 if( NULL != mImpl->mEventData )
351 return mImpl->mEventData->mCursorBlinkEnabled;
357 void Controller::SetMultiLineEnabled( bool enable )
359 const Layout::Engine::Type layout = enable ? Layout::Engine::MULTI_LINE_BOX : Layout::Engine::SINGLE_LINE_BOX;
361 if( layout != mImpl->mLayoutEngine.GetLayout() )
363 // Set the layout type.
364 mImpl->mLayoutEngine.SetLayout( layout );
366 // Set the flags to redo the layout operations
367 const OperationsMask layoutOperations = static_cast<OperationsMask>( LAYOUT |
372 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
373 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | layoutOperations );
375 // Need to recalculate natural size
376 mImpl->mRecalculateNaturalSize = true;
378 mImpl->RequestRelayout();
382 bool Controller::IsMultiLineEnabled() const
384 return Layout::Engine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
387 void Controller::SetHorizontalAlignment( Text::HorizontalAlignment::Type alignment )
389 if( alignment != mImpl->mModel->mHorizontalAlignment )
391 // Set the alignment.
392 mImpl->mModel->mHorizontalAlignment = alignment;
394 // Set the flag to redo the alignment operation.
395 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
397 if( mImpl->mEventData )
399 mImpl->mEventData->mUpdateAlignment = true;
401 // Update the cursor if it's in editing mode
402 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
404 mImpl->ChangeState( EventData::EDITING );
405 mImpl->mEventData->mUpdateCursorPosition = true;
409 mImpl->RequestRelayout();
413 Text::HorizontalAlignment::Type Controller::GetHorizontalAlignment() const
415 return mImpl->mModel->mHorizontalAlignment;
418 void Controller::SetVerticalAlignment( VerticalAlignment::Type alignment )
420 if( alignment != mImpl->mModel->mVerticalAlignment )
422 // Set the alignment.
423 mImpl->mModel->mVerticalAlignment = alignment;
425 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
427 mImpl->RequestRelayout();
431 VerticalAlignment::Type Controller::GetVerticalAlignment() const
433 return mImpl->mModel->mVerticalAlignment;
436 bool Controller::IsIgnoreSpacesAfterText() const
438 return mImpl->mModel->mIgnoreSpacesAfterText;
441 void Controller::SetIgnoreSpacesAfterText( bool ignore )
443 mImpl->mModel->mIgnoreSpacesAfterText = ignore;
446 bool Controller::IsMatchSystemLanguageDirection() const
448 return mImpl->mModel->mMatchSystemLanguageDirection;
451 void Controller::SetMatchSystemLanguageDirection( bool match )
453 mImpl->mModel->mMatchSystemLanguageDirection = match;
456 void Controller::SetLayoutDirection( Dali::LayoutDirection::Type layoutDirection )
458 mImpl->mLayoutDirection = layoutDirection;
461 bool Controller::IsShowingRealText() const
463 return mImpl->IsShowingRealText();
467 void Controller::SetLineWrapMode( Text::LineWrap::Mode lineWrapMode )
469 if( lineWrapMode != mImpl->mModel->mLineWrapMode )
471 // Set the text wrap mode.
472 mImpl->mModel->mLineWrapMode = lineWrapMode;
475 // Update Text layout for applying wrap mode
476 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
481 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
482 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
483 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
486 mImpl->RequestRelayout();
490 Text::LineWrap::Mode Controller::GetLineWrapMode() const
492 return mImpl->mModel->mLineWrapMode;
495 void Controller::SetTextElideEnabled( bool enabled )
497 mImpl->mModel->mElideEnabled = enabled;
500 bool Controller::IsTextElideEnabled() const
502 return mImpl->mModel->mElideEnabled;
505 void Controller::SetTextFitEnabled(bool enabled)
507 mImpl->mTextFitEnabled = enabled;
510 bool Controller::IsTextFitEnabled() const
512 return mImpl->mTextFitEnabled;
515 void Controller::SetTextFitMinSize( float minSize, FontSizeType type )
521 mImpl->mTextFitMinSize = minSize;
526 mImpl->mTextFitMinSize = ConvertPixelToPint( minSize );
532 float Controller::GetTextFitMinSize() const
534 return mImpl->mTextFitMinSize;
537 void Controller::SetTextFitMaxSize( float maxSize, FontSizeType type )
543 mImpl->mTextFitMaxSize = maxSize;
548 mImpl->mTextFitMaxSize = ConvertPixelToPint( maxSize );
554 float Controller::GetTextFitMaxSize() const
556 return mImpl->mTextFitMaxSize;
559 void Controller::SetTextFitStepSize( float step, FontSizeType type )
565 mImpl->mTextFitStepSize = step;
570 mImpl->mTextFitStepSize = ConvertPixelToPint( step );
576 float Controller::GetTextFitStepSize() const
578 return mImpl->mTextFitStepSize;
581 void Controller::SetTextFitContentSize(Vector2 size)
583 mImpl->mTextFitContentSize = size;
586 Vector2 Controller::GetTextFitContentSize() const
588 return mImpl->mTextFitContentSize;
591 void Controller::SetPlaceholderTextElideEnabled( bool enabled )
593 mImpl->mEventData->mIsPlaceholderElideEnabled = enabled;
594 mImpl->mEventData->mPlaceholderEllipsisFlag = true;
596 // Update placeholder if there is no text
597 if( mImpl->IsShowingPlaceholderText() ||
598 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
600 ShowPlaceholderText();
604 bool Controller::IsPlaceholderTextElideEnabled() const
606 return mImpl->mEventData->mIsPlaceholderElideEnabled;
609 void Controller::SetSelectionEnabled( bool enabled )
611 mImpl->mEventData->mSelectionEnabled = enabled;
614 bool Controller::IsSelectionEnabled() const
616 return mImpl->mEventData->mSelectionEnabled;
619 void Controller::SetShiftSelectionEnabled( bool enabled )
621 mImpl->mEventData->mShiftSelectionFlag = enabled;
624 bool Controller::IsShiftSelectionEnabled() const
626 return mImpl->mEventData->mShiftSelectionFlag;
629 void Controller::SetGrabHandleEnabled( bool enabled )
631 mImpl->mEventData->mGrabHandleEnabled = enabled;
634 bool Controller::IsGrabHandleEnabled() const
636 return mImpl->mEventData->mGrabHandleEnabled;
639 void Controller::SetGrabHandlePopupEnabled(bool enabled)
641 mImpl->mEventData->mGrabHandlePopupEnabled = enabled;
644 bool Controller::IsGrabHandlePopupEnabled() const
646 return mImpl->mEventData->mGrabHandlePopupEnabled;
651 void Controller::SetText( const std::string& text )
653 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" );
655 // Reset keyboard as text changed
656 mImpl->ResetInputMethodContext();
658 // Remove the previously set text and style.
664 CharacterIndex lastCursorIndex = 0u;
666 if( NULL != mImpl->mEventData )
668 // If popup shown then hide it by switching to Editing state
669 if( ( EventData::SELECTING == mImpl->mEventData->mState ) ||
670 ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
671 ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) ||
672 ( EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState ) )
674 mImpl->ChangeState( EventData::EDITING );
680 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mTextColor );
682 MarkupProcessData markupProcessData( mImpl->mModel->mLogicalModel->mColorRuns,
683 mImpl->mModel->mLogicalModel->mFontDescriptionRuns,
684 mImpl->mModel->mLogicalModel->mEmbeddedItems );
686 Length textSize = 0u;
687 const uint8_t* utf8 = NULL;
688 if( mImpl->mMarkupProcessorEnabled )
690 ProcessMarkupString( text, markupProcessData );
691 textSize = markupProcessData.markupProcessedText.size();
693 // This is a bit horrible but std::string returns a (signed) char*
694 utf8 = reinterpret_cast<const uint8_t*>( markupProcessData.markupProcessedText.c_str() );
698 textSize = text.size();
700 // This is a bit horrible but std::string returns a (signed) char*
701 utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
704 // Convert text into UTF-32
705 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
706 utf32Characters.Resize( textSize );
708 // Transform a text array encoded in utf8 into an array encoded in utf32.
709 // It returns the actual number of characters.
710 Length characterCount = Utf8ToUtf32( utf8, textSize, utf32Characters.Begin() );
711 utf32Characters.Resize( characterCount );
713 DALI_ASSERT_DEBUG( textSize >= characterCount && "Invalid UTF32 conversion length" );
714 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", this, textSize, mImpl->mModel->mLogicalModel->mText.Count() );
716 // The characters to be added.
717 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
719 // To reset the cursor position
720 lastCursorIndex = characterCount;
722 // Update the rest of the model during size negotiation
723 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
725 // The natural size needs to be re-calculated.
726 mImpl->mRecalculateNaturalSize = true;
728 // The text direction needs to be updated.
729 mImpl->mUpdateTextDirection = true;
731 // Apply modifications to the model
732 mImpl->mOperationsPending = ALL_OPERATIONS;
736 ShowPlaceholderText();
739 // Resets the cursor position.
740 ResetCursorPosition( lastCursorIndex );
742 // Scrolls the text to make the cursor visible.
743 ResetScrollPosition();
745 mImpl->RequestRelayout();
747 if( NULL != mImpl->mEventData )
749 // Cancel previously queued events
750 mImpl->mEventData->mEventQueue.clear();
753 // Do this last since it provides callbacks into application code.
754 if( NULL != mImpl->mEditableControlInterface )
756 mImpl->mEditableControlInterface->TextChanged();
760 void Controller::GetText( std::string& text ) const
762 if( !mImpl->IsShowingPlaceholderText() )
764 // Retrieves the text string.
765 mImpl->GetText( 0u, text );
769 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this );
773 void Controller::SetPlaceholderText( PlaceholderType type, const std::string& text )
775 if( NULL != mImpl->mEventData )
777 if( PLACEHOLDER_TYPE_INACTIVE == type )
779 mImpl->mEventData->mPlaceholderTextInactive = text;
783 mImpl->mEventData->mPlaceholderTextActive = text;
786 // Update placeholder if there is no text
787 if( mImpl->IsShowingPlaceholderText() ||
788 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
790 ShowPlaceholderText();
795 void Controller::GetPlaceholderText( PlaceholderType type, std::string& text ) const
797 if( NULL != mImpl->mEventData )
799 if( PLACEHOLDER_TYPE_INACTIVE == type )
801 text = mImpl->mEventData->mPlaceholderTextInactive;
805 text = mImpl->mEventData->mPlaceholderTextActive;
810 void Controller::UpdateAfterFontChange( const std::string& newDefaultFont )
812 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
814 if( !mImpl->mFontDefaults->familyDefined ) // If user defined font then should not update when system font changes
816 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
817 mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
821 mImpl->RequestRelayout();
825 // public : Default style & Input style
827 void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
829 if( NULL == mImpl->mFontDefaults )
831 mImpl->mFontDefaults = new FontDefaults();
834 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
835 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
836 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
838 // Clear the font-specific data
841 mImpl->RequestRelayout();
844 const std::string& Controller::GetDefaultFontFamily() const
846 if( NULL != mImpl->mFontDefaults )
848 return mImpl->mFontDefaults->mFontDescription.family;
854 void Controller::SetPlaceholderFontFamily( const std::string& placeholderTextFontFamily )
856 if( NULL != mImpl->mEventData )
858 if( NULL == mImpl->mEventData->mPlaceholderFont )
860 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
863 mImpl->mEventData->mPlaceholderFont->mFontDescription.family = placeholderTextFontFamily;
864 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetPlaceholderFontFamily %s\n", placeholderTextFontFamily.c_str());
865 mImpl->mEventData->mPlaceholderFont->familyDefined = !placeholderTextFontFamily.empty();
867 mImpl->RequestRelayout();
871 const std::string& Controller::GetPlaceholderFontFamily() const
873 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
875 return mImpl->mEventData->mPlaceholderFont->mFontDescription.family;
881 void Controller::SetDefaultFontWeight( FontWeight weight )
883 if( NULL == mImpl->mFontDefaults )
885 mImpl->mFontDefaults = new FontDefaults();
888 mImpl->mFontDefaults->mFontDescription.weight = weight;
889 mImpl->mFontDefaults->weightDefined = true;
891 // Clear the font-specific data
894 mImpl->RequestRelayout();
897 bool Controller::IsDefaultFontWeightDefined() const
899 if( NULL != mImpl->mFontDefaults )
901 return mImpl->mFontDefaults->weightDefined;
907 FontWeight Controller::GetDefaultFontWeight() const
909 if( NULL != mImpl->mFontDefaults )
911 return mImpl->mFontDefaults->mFontDescription.weight;
914 return TextAbstraction::FontWeight::NORMAL;
917 void Controller::SetPlaceholderTextFontWeight( FontWeight weight )
919 if( NULL != mImpl->mEventData )
921 if( NULL == mImpl->mEventData->mPlaceholderFont )
923 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
926 mImpl->mEventData->mPlaceholderFont->mFontDescription.weight = weight;
927 mImpl->mEventData->mPlaceholderFont->weightDefined = true;
929 mImpl->RequestRelayout();
933 bool Controller::IsPlaceholderTextFontWeightDefined() const
935 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
937 return mImpl->mEventData->mPlaceholderFont->weightDefined;
942 FontWeight Controller::GetPlaceholderTextFontWeight() const
944 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
946 return mImpl->mEventData->mPlaceholderFont->mFontDescription.weight;
949 return TextAbstraction::FontWeight::NORMAL;
952 void Controller::SetDefaultFontWidth( FontWidth width )
954 if( NULL == mImpl->mFontDefaults )
956 mImpl->mFontDefaults = new FontDefaults();
959 mImpl->mFontDefaults->mFontDescription.width = width;
960 mImpl->mFontDefaults->widthDefined = true;
962 // Clear the font-specific data
965 mImpl->RequestRelayout();
968 bool Controller::IsDefaultFontWidthDefined() const
970 if( NULL != mImpl->mFontDefaults )
972 return mImpl->mFontDefaults->widthDefined;
978 FontWidth Controller::GetDefaultFontWidth() const
980 if( NULL != mImpl->mFontDefaults )
982 return mImpl->mFontDefaults->mFontDescription.width;
985 return TextAbstraction::FontWidth::NORMAL;
988 void Controller::SetPlaceholderTextFontWidth( FontWidth width )
990 if( NULL != mImpl->mEventData )
992 if( NULL == mImpl->mEventData->mPlaceholderFont )
994 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
997 mImpl->mEventData->mPlaceholderFont->mFontDescription.width = width;
998 mImpl->mEventData->mPlaceholderFont->widthDefined = true;
1000 mImpl->RequestRelayout();
1004 bool Controller::IsPlaceholderTextFontWidthDefined() const
1006 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1008 return mImpl->mEventData->mPlaceholderFont->widthDefined;
1013 FontWidth Controller::GetPlaceholderTextFontWidth() const
1015 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1017 return mImpl->mEventData->mPlaceholderFont->mFontDescription.width;
1020 return TextAbstraction::FontWidth::NORMAL;
1023 void Controller::SetDefaultFontSlant( FontSlant slant )
1025 if( NULL == mImpl->mFontDefaults )
1027 mImpl->mFontDefaults = new FontDefaults();
1030 mImpl->mFontDefaults->mFontDescription.slant = slant;
1031 mImpl->mFontDefaults->slantDefined = true;
1033 // Clear the font-specific data
1036 mImpl->RequestRelayout();
1039 bool Controller::IsDefaultFontSlantDefined() const
1041 if( NULL != mImpl->mFontDefaults )
1043 return mImpl->mFontDefaults->slantDefined;
1048 FontSlant Controller::GetDefaultFontSlant() const
1050 if( NULL != mImpl->mFontDefaults )
1052 return mImpl->mFontDefaults->mFontDescription.slant;
1055 return TextAbstraction::FontSlant::NORMAL;
1058 void Controller::SetPlaceholderTextFontSlant( FontSlant slant )
1060 if( NULL != mImpl->mEventData )
1062 if( NULL == mImpl->mEventData->mPlaceholderFont )
1064 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
1067 mImpl->mEventData->mPlaceholderFont->mFontDescription.slant = slant;
1068 mImpl->mEventData->mPlaceholderFont->slantDefined = true;
1070 mImpl->RequestRelayout();
1074 bool Controller::IsPlaceholderTextFontSlantDefined() const
1076 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1078 return mImpl->mEventData->mPlaceholderFont->slantDefined;
1083 FontSlant Controller::GetPlaceholderTextFontSlant() const
1085 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1087 return mImpl->mEventData->mPlaceholderFont->mFontDescription.slant;
1090 return TextAbstraction::FontSlant::NORMAL;
1093 void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
1095 if( NULL == mImpl->mFontDefaults )
1097 mImpl->mFontDefaults = new FontDefaults();
1104 mImpl->mFontDefaults->mDefaultPointSize = fontSize;
1105 mImpl->mFontDefaults->sizeDefined = true;
1110 // Point size = Pixel size * 72.f / DPI
1111 unsigned int horizontalDpi = 0u;
1112 unsigned int verticalDpi = 0u;
1113 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1114 fontClient.GetDpi( horizontalDpi, verticalDpi );
1116 mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
1117 mImpl->mFontDefaults->sizeDefined = true;
1122 // Clear the font-specific data
1125 mImpl->RequestRelayout();
1128 float Controller::GetDefaultFontSize( FontSizeType type ) const
1131 if( NULL != mImpl->mFontDefaults )
1137 value = mImpl->mFontDefaults->mDefaultPointSize;
1142 // Pixel size = Point size * DPI / 72.f
1143 unsigned int horizontalDpi = 0u;
1144 unsigned int verticalDpi = 0u;
1145 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1146 fontClient.GetDpi( horizontalDpi, verticalDpi );
1148 value = mImpl->mFontDefaults->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1158 void Controller::SetPlaceholderTextFontSize( float fontSize, FontSizeType type )
1160 if( NULL != mImpl->mEventData )
1162 if( NULL == mImpl->mEventData->mPlaceholderFont )
1164 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
1171 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = fontSize;
1172 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1173 mImpl->mEventData->mIsPlaceholderPixelSize = false; // Font size flag
1178 // Point size = Pixel size * 72.f / DPI
1179 unsigned int horizontalDpi = 0u;
1180 unsigned int verticalDpi = 0u;
1181 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1182 fontClient.GetDpi( horizontalDpi, verticalDpi );
1184 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
1185 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1186 mImpl->mEventData->mIsPlaceholderPixelSize = true; // Font size flag
1191 mImpl->RequestRelayout();
1195 float Controller::GetPlaceholderTextFontSize( FontSizeType type ) const
1198 if( NULL != mImpl->mEventData )
1204 if( NULL != mImpl->mEventData->mPlaceholderFont )
1206 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize;
1210 // If the placeholder text font size is not set, then return the default font size.
1211 value = GetDefaultFontSize( POINT_SIZE );
1217 if( NULL != mImpl->mEventData->mPlaceholderFont )
1219 // Pixel size = Point size * DPI / 72.f
1220 unsigned int horizontalDpi = 0u;
1221 unsigned int verticalDpi = 0u;
1222 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1223 fontClient.GetDpi( horizontalDpi, verticalDpi );
1225 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1229 // If the placeholder text font size is not set, then return the default font size.
1230 value = GetDefaultFontSize( PIXEL_SIZE );
1241 void Controller::SetDefaultColor( const Vector4& color )
1243 mImpl->mTextColor = color;
1245 if( !mImpl->IsShowingPlaceholderText() )
1247 mImpl->mModel->mVisualModel->SetTextColor( color );
1249 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
1251 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1253 mImpl->RequestRelayout();
1257 const Vector4& Controller::GetDefaultColor() const
1259 return mImpl->mTextColor;
1262 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
1264 if( NULL != mImpl->mEventData )
1266 mImpl->mEventData->mPlaceholderTextColor = textColor;
1269 if( mImpl->IsShowingPlaceholderText() )
1271 mImpl->mModel->mVisualModel->SetTextColor( textColor );
1272 mImpl->RequestRelayout();
1276 const Vector4& Controller::GetPlaceholderTextColor() const
1278 if( NULL != mImpl->mEventData )
1280 return mImpl->mEventData->mPlaceholderTextColor;
1283 return Color::BLACK;
1286 void Controller::SetShadowOffset( const Vector2& shadowOffset )
1288 mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
1290 mImpl->RequestRelayout();
1293 const Vector2& Controller::GetShadowOffset() const
1295 return mImpl->mModel->mVisualModel->GetShadowOffset();
1298 void Controller::SetShadowColor( const Vector4& shadowColor )
1300 mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
1302 mImpl->RequestRelayout();
1305 const Vector4& Controller::GetShadowColor() const
1307 return mImpl->mModel->mVisualModel->GetShadowColor();
1310 void Controller::SetShadowBlurRadius( const float& shadowBlurRadius )
1312 if ( fabsf( GetShadowBlurRadius() - shadowBlurRadius ) > Math::MACHINE_EPSILON_1 )
1314 mImpl->mModel->mVisualModel->SetShadowBlurRadius( shadowBlurRadius );
1316 mImpl->RequestRelayout();
1320 const float& Controller::GetShadowBlurRadius() const
1322 return mImpl->mModel->mVisualModel->GetShadowBlurRadius();
1325 void Controller::SetUnderlineColor( const Vector4& color )
1327 mImpl->mModel->mVisualModel->SetUnderlineColor( color );
1329 mImpl->RequestRelayout();
1332 const Vector4& Controller::GetUnderlineColor() const
1334 return mImpl->mModel->mVisualModel->GetUnderlineColor();
1337 void Controller::SetUnderlineEnabled( bool enabled )
1339 mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
1341 mImpl->RequestRelayout();
1344 bool Controller::IsUnderlineEnabled() const
1346 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
1349 void Controller::SetUnderlineHeight( float height )
1351 mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
1353 mImpl->RequestRelayout();
1356 float Controller::GetUnderlineHeight() const
1358 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
1361 void Controller::SetOutlineColor( const Vector4& color )
1363 mImpl->mModel->mVisualModel->SetOutlineColor( color );
1365 mImpl->RequestRelayout();
1368 const Vector4& Controller::GetOutlineColor() const
1370 return mImpl->mModel->mVisualModel->GetOutlineColor();
1373 void Controller::SetOutlineWidth( uint16_t width )
1375 mImpl->mModel->mVisualModel->SetOutlineWidth( width );
1377 mImpl->RequestRelayout();
1380 uint16_t Controller::GetOutlineWidth() const
1382 return mImpl->mModel->mVisualModel->GetOutlineWidth();
1385 void Controller::SetBackgroundColor( const Vector4& color )
1387 mImpl->mModel->mVisualModel->SetBackgroundColor( color );
1389 mImpl->RequestRelayout();
1392 const Vector4& Controller::GetBackgroundColor() const
1394 return mImpl->mModel->mVisualModel->GetBackgroundColor();
1397 void Controller::SetBackgroundEnabled( bool enabled )
1399 mImpl->mModel->mVisualModel->SetBackgroundEnabled( enabled );
1401 mImpl->RequestRelayout();
1404 bool Controller::IsBackgroundEnabled() const
1406 return mImpl->mModel->mVisualModel->IsBackgroundEnabled();
1409 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
1411 if( NULL == mImpl->mEmbossDefaults )
1413 mImpl->mEmbossDefaults = new EmbossDefaults();
1416 mImpl->mEmbossDefaults->properties = embossProperties;
1419 const std::string& Controller::GetDefaultEmbossProperties() const
1421 if( NULL != mImpl->mEmbossDefaults )
1423 return mImpl->mEmbossDefaults->properties;
1426 return EMPTY_STRING;
1429 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
1431 if( NULL == mImpl->mOutlineDefaults )
1433 mImpl->mOutlineDefaults = new OutlineDefaults();
1436 mImpl->mOutlineDefaults->properties = outlineProperties;
1439 const std::string& Controller::GetDefaultOutlineProperties() const
1441 if( NULL != mImpl->mOutlineDefaults )
1443 return mImpl->mOutlineDefaults->properties;
1446 return EMPTY_STRING;
1449 bool Controller::SetDefaultLineSpacing( float lineSpacing )
1451 if( std::fabs( lineSpacing - mImpl->mLayoutEngine.GetDefaultLineSpacing() ) > Math::MACHINE_EPSILON_1000 )
1453 mImpl->mLayoutEngine.SetDefaultLineSpacing(lineSpacing);
1454 mImpl->mRecalculateNaturalSize = true;
1460 float Controller::GetDefaultLineSpacing() const
1462 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
1465 void Controller::SetInputColor( const Vector4& color )
1467 if( NULL != mImpl->mEventData )
1469 mImpl->mEventData->mInputStyle.textColor = color;
1470 mImpl->mEventData->mInputStyle.isDefaultColor = false;
1472 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1474 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
1476 // Get start and end position of selection
1477 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
1478 const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
1480 // Add the color run.
1481 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1482 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
1484 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
1485 colorRun.color = color;
1486 colorRun.characterRun.characterIndex = startOfSelectedText;
1487 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1489 // Request to relayout.
1490 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1491 mImpl->RequestRelayout();
1493 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1494 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1495 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1500 const Vector4& Controller::GetInputColor() const
1502 if( NULL != mImpl->mEventData )
1504 return mImpl->mEventData->mInputStyle.textColor;
1507 // Return the default text's color if there is no EventData.
1508 return mImpl->mTextColor;
1512 void Controller::SetInputFontFamily( const std::string& fontFamily )
1514 if( NULL != mImpl->mEventData )
1516 mImpl->mEventData->mInputStyle.familyName = fontFamily;
1517 mImpl->mEventData->mInputStyle.isFamilyDefined = true;
1519 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1521 CharacterIndex startOfSelectedText = 0u;
1522 Length lengthOfSelectedText = 0u;
1523 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1524 mImpl->mModel->mLogicalModel,
1525 startOfSelectedText,
1526 lengthOfSelectedText );
1528 fontDescriptionRun.familyLength = fontFamily.size();
1529 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
1530 memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength );
1531 fontDescriptionRun.familyDefined = true;
1533 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
1535 // Request to relayout.
1536 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1541 UPDATE_LAYOUT_SIZE |
1544 mImpl->mRecalculateNaturalSize = true;
1545 mImpl->RequestRelayout();
1547 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1548 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1549 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1551 // As the font changes, recalculate the handle positions is needed.
1552 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1553 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1554 mImpl->mEventData->mUpdateHighlightBox = true;
1555 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1560 const std::string& Controller::GetInputFontFamily() const
1562 if( NULL != mImpl->mEventData )
1564 return mImpl->mEventData->mInputStyle.familyName;
1567 // Return the default font's family if there is no EventData.
1568 return GetDefaultFontFamily();
1571 void Controller::SetInputFontWeight( FontWeight weight )
1573 if( NULL != mImpl->mEventData )
1575 mImpl->mEventData->mInputStyle.weight = weight;
1576 mImpl->mEventData->mInputStyle.isWeightDefined = true;
1578 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1580 CharacterIndex startOfSelectedText = 0u;
1581 Length lengthOfSelectedText = 0u;
1582 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1583 mImpl->mModel->mLogicalModel,
1584 startOfSelectedText,
1585 lengthOfSelectedText );
1587 fontDescriptionRun.weight = weight;
1588 fontDescriptionRun.weightDefined = true;
1590 // Request to relayout.
1591 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1596 UPDATE_LAYOUT_SIZE |
1599 mImpl->mRecalculateNaturalSize = true;
1600 mImpl->RequestRelayout();
1602 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1603 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1604 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1606 // As the font might change, recalculate the handle positions is needed.
1607 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1608 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1609 mImpl->mEventData->mUpdateHighlightBox = true;
1610 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1615 bool Controller::IsInputFontWeightDefined() const
1617 bool defined = false;
1619 if( NULL != mImpl->mEventData )
1621 defined = mImpl->mEventData->mInputStyle.isWeightDefined;
1627 FontWeight Controller::GetInputFontWeight() const
1629 if( NULL != mImpl->mEventData )
1631 return mImpl->mEventData->mInputStyle.weight;
1634 return GetDefaultFontWeight();
1637 void Controller::SetInputFontWidth( FontWidth width )
1639 if( NULL != mImpl->mEventData )
1641 mImpl->mEventData->mInputStyle.width = width;
1642 mImpl->mEventData->mInputStyle.isWidthDefined = true;
1644 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1646 CharacterIndex startOfSelectedText = 0u;
1647 Length lengthOfSelectedText = 0u;
1648 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1649 mImpl->mModel->mLogicalModel,
1650 startOfSelectedText,
1651 lengthOfSelectedText );
1653 fontDescriptionRun.width = width;
1654 fontDescriptionRun.widthDefined = true;
1656 // Request to relayout.
1657 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1662 UPDATE_LAYOUT_SIZE |
1665 mImpl->mRecalculateNaturalSize = true;
1666 mImpl->RequestRelayout();
1668 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1669 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1670 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1672 // As the font might change, recalculate the handle positions is needed.
1673 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1674 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1675 mImpl->mEventData->mUpdateHighlightBox = true;
1676 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1681 bool Controller::IsInputFontWidthDefined() const
1683 bool defined = false;
1685 if( NULL != mImpl->mEventData )
1687 defined = mImpl->mEventData->mInputStyle.isWidthDefined;
1693 FontWidth Controller::GetInputFontWidth() const
1695 if( NULL != mImpl->mEventData )
1697 return mImpl->mEventData->mInputStyle.width;
1700 return GetDefaultFontWidth();
1703 void Controller::SetInputFontSlant( FontSlant slant )
1705 if( NULL != mImpl->mEventData )
1707 mImpl->mEventData->mInputStyle.slant = slant;
1708 mImpl->mEventData->mInputStyle.isSlantDefined = true;
1710 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1712 CharacterIndex startOfSelectedText = 0u;
1713 Length lengthOfSelectedText = 0u;
1714 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1715 mImpl->mModel->mLogicalModel,
1716 startOfSelectedText,
1717 lengthOfSelectedText );
1719 fontDescriptionRun.slant = slant;
1720 fontDescriptionRun.slantDefined = true;
1722 // Request to relayout.
1723 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1728 UPDATE_LAYOUT_SIZE |
1731 mImpl->mRecalculateNaturalSize = true;
1732 mImpl->RequestRelayout();
1734 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1735 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1736 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1738 // As the font might change, recalculate the handle positions is needed.
1739 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1740 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1741 mImpl->mEventData->mUpdateHighlightBox = true;
1742 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1747 bool Controller::IsInputFontSlantDefined() const
1749 bool defined = false;
1751 if( NULL != mImpl->mEventData )
1753 defined = mImpl->mEventData->mInputStyle.isSlantDefined;
1759 FontSlant Controller::GetInputFontSlant() const
1761 if( NULL != mImpl->mEventData )
1763 return mImpl->mEventData->mInputStyle.slant;
1766 return GetDefaultFontSlant();
1769 void Controller::SetInputFontPointSize( float size )
1771 if( NULL != mImpl->mEventData )
1773 mImpl->mEventData->mInputStyle.size = size;
1774 mImpl->mEventData->mInputStyle.isSizeDefined = true;
1776 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1778 CharacterIndex startOfSelectedText = 0u;
1779 Length lengthOfSelectedText = 0u;
1780 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1781 mImpl->mModel->mLogicalModel,
1782 startOfSelectedText,
1783 lengthOfSelectedText );
1785 fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
1786 fontDescriptionRun.sizeDefined = true;
1788 // Request to relayout.
1789 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1794 UPDATE_LAYOUT_SIZE |
1797 mImpl->mRecalculateNaturalSize = true;
1798 mImpl->RequestRelayout();
1800 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1801 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1802 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1804 // As the font might change, recalculate the handle positions is needed.
1805 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1806 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1807 mImpl->mEventData->mUpdateHighlightBox = true;
1808 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1813 float Controller::GetInputFontPointSize() const
1815 if( NULL != mImpl->mEventData )
1817 return mImpl->mEventData->mInputStyle.size;
1820 // Return the default font's point size if there is no EventData.
1821 return GetDefaultFontSize( Text::Controller::POINT_SIZE );
1824 void Controller::SetInputLineSpacing( float lineSpacing )
1826 if( NULL != mImpl->mEventData )
1828 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1829 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1833 float Controller::GetInputLineSpacing() const
1835 if( NULL != mImpl->mEventData )
1837 return mImpl->mEventData->mInputStyle.lineSpacing;
1843 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1845 if( NULL != mImpl->mEventData )
1847 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1851 const std::string& Controller::GetInputShadowProperties() const
1853 if( NULL != mImpl->mEventData )
1855 return mImpl->mEventData->mInputStyle.shadowProperties;
1858 return EMPTY_STRING;
1861 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1863 if( NULL != mImpl->mEventData )
1865 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1869 const std::string& Controller::GetInputUnderlineProperties() const
1871 if( NULL != mImpl->mEventData )
1873 return mImpl->mEventData->mInputStyle.underlineProperties;
1876 return EMPTY_STRING;
1879 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
1881 if( NULL != mImpl->mEventData )
1883 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1887 const std::string& Controller::GetInputEmbossProperties() const
1889 if( NULL != mImpl->mEventData )
1891 return mImpl->mEventData->mInputStyle.embossProperties;
1894 return GetDefaultEmbossProperties();
1897 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
1899 if( NULL != mImpl->mEventData )
1901 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1905 const std::string& Controller::GetInputOutlineProperties() const
1907 if( NULL != mImpl->mEventData )
1909 return mImpl->mEventData->mInputStyle.outlineProperties;
1912 return GetDefaultOutlineProperties();
1915 void Controller::SetInputModePassword( bool passwordInput )
1917 if( NULL != mImpl->mEventData )
1919 mImpl->mEventData->mPasswordInput = passwordInput;
1923 bool Controller::IsInputModePassword()
1925 if( NULL != mImpl->mEventData )
1927 return mImpl->mEventData->mPasswordInput;
1932 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
1934 if( NULL != mImpl->mEventData )
1936 mImpl->mEventData->mDoubleTapAction = action;
1940 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1942 NoTextTap::Action action = NoTextTap::NO_ACTION;
1944 if( NULL != mImpl->mEventData )
1946 action = mImpl->mEventData->mDoubleTapAction;
1952 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
1954 if( NULL != mImpl->mEventData )
1956 mImpl->mEventData->mLongPressAction = action;
1960 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1962 NoTextTap::Action action = NoTextTap::NO_ACTION;
1964 if( NULL != mImpl->mEventData )
1966 action = mImpl->mEventData->mLongPressAction;
1972 bool Controller::IsUnderlineSetByString()
1974 return mImpl->mUnderlineSetByString;
1977 void Controller::UnderlineSetByString( bool setByString )
1979 mImpl->mUnderlineSetByString = setByString;
1982 bool Controller::IsShadowSetByString()
1984 return mImpl->mShadowSetByString;
1987 void Controller::ShadowSetByString( bool setByString )
1989 mImpl->mShadowSetByString = setByString;
1992 bool Controller::IsOutlineSetByString()
1994 return mImpl->mOutlineSetByString;
1997 void Controller::OutlineSetByString( bool setByString )
1999 mImpl->mOutlineSetByString = setByString;
2002 bool Controller::IsFontStyleSetByString()
2004 return mImpl->mFontStyleSetByString;
2007 void Controller::FontStyleSetByString( bool setByString )
2009 mImpl->mFontStyleSetByString = setByString;
2012 // public : Queries & retrieves.
2014 Layout::Engine& Controller::GetLayoutEngine()
2016 return mImpl->mLayoutEngine;
2019 View& Controller::GetView()
2021 return mImpl->mView;
2024 Vector3 Controller::GetNaturalSize()
2026 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
2027 Vector3 naturalSize;
2029 // Make sure the model is up-to-date before layouting
2030 ProcessModifyEvents();
2032 if( mImpl->mRecalculateNaturalSize )
2034 // Operations that can be done only once until the text changes.
2035 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2041 GET_GLYPH_METRICS );
2043 // Set the update info to relayout the whole text.
2044 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2045 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2047 // Make sure the model is up-to-date before layouting
2048 mImpl->UpdateModel( onlyOnceOperations );
2050 // Layout the text for the new width.
2051 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT | REORDER );
2053 // Store the actual control's size to restore later.
2054 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
2056 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
2057 static_cast<OperationsMask>( onlyOnceOperations |
2059 naturalSize.GetVectorXY() );
2061 // Do not do again the only once operations.
2062 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2064 // Do the size related operations again.
2065 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
2068 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
2070 // Stores the natural size to avoid recalculate it again
2071 // unless the text/style changes.
2072 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
2074 mImpl->mRecalculateNaturalSize = false;
2076 // Clear the update info. This info will be set the next time the text is updated.
2077 mImpl->mTextUpdateInfo.Clear();
2078 mImpl->mTextUpdateInfo.mClearAll = true;
2080 // Restore the actual control's size.
2081 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
2083 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
2087 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
2089 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
2092 naturalSize.x = ConvertToEven( naturalSize.x );
2093 naturalSize.y = ConvertToEven( naturalSize.y );
2098 bool Controller::CheckForTextFit( float pointSize, Size& layoutSize )
2101 mImpl->mFontDefaults->mFitPointSize = pointSize;
2102 mImpl->mFontDefaults->sizeDefined = true;
2105 // Operations that can be done only once until the text changes.
2106 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2112 GET_GLYPH_METRICS );
2114 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2115 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2117 // Make sure the model is up-to-date before layouting
2118 mImpl->UpdateModel( onlyOnceOperations );
2120 DoRelayout( Size( layoutSize.width, MAX_FLOAT ),
2121 static_cast<OperationsMask>( onlyOnceOperations | LAYOUT),
2124 // Clear the update info. This info will be set the next time the text is updated.
2125 mImpl->mTextUpdateInfo.Clear();
2126 mImpl->mTextUpdateInfo.mClearAll = true;
2128 if( textSize.width > layoutSize.width || textSize.height > layoutSize.height )
2135 void Controller::FitPointSizeforLayout( Size layoutSize )
2137 const OperationsMask operations = mImpl->mOperationsPending;
2138 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) || mImpl->mTextFitContentSize != layoutSize )
2140 bool actualellipsis = mImpl->mModel->mElideEnabled;
2141 float minPointSize = mImpl->mTextFitMinSize;
2142 float maxPointSize = mImpl->mTextFitMaxSize;
2143 float pointInterval = mImpl->mTextFitStepSize;
2145 mImpl->mModel->mElideEnabled = false;
2146 Vector<float> pointSizeArray;
2149 if( pointInterval < 1.f )
2151 mImpl->mTextFitStepSize = pointInterval = 1.0f;
2154 pointSizeArray.Reserve( static_cast< unsigned int >( ceil( ( maxPointSize - minPointSize ) / pointInterval ) ) );
2156 for( float i = minPointSize; i < maxPointSize; i += pointInterval )
2158 pointSizeArray.PushBack( i );
2161 pointSizeArray.PushBack( maxPointSize );
2163 int bestSizeIndex = 0;
2164 int min = bestSizeIndex + 1;
2165 int max = pointSizeArray.Size() - 1;
2168 int destI = ( min + max ) / 2;
2170 if( CheckForTextFit( pointSizeArray[destI], layoutSize ) )
2172 bestSizeIndex = min;
2178 bestSizeIndex = max;
2182 mImpl->mModel->mElideEnabled = actualellipsis;
2183 mImpl->mFontDefaults->mFitPointSize = pointSizeArray[bestSizeIndex];
2184 mImpl->mFontDefaults->sizeDefined = true;
2189 float Controller::GetHeightForWidth( float width )
2191 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
2192 // Make sure the model is up-to-date before layouting
2193 ProcessModifyEvents();
2196 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ||
2197 mImpl->mTextUpdateInfo.mFullRelayoutNeeded ||
2198 mImpl->mTextUpdateInfo.mClearAll )
2200 // Operations that can be done only once until the text changes.
2201 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 |
2428 GET_GLYPH_METRICS );
2430 // Set the update info to relayout the whole text.
2431 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2432 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2434 // Make sure the model is up-to-date before layouting
2435 mImpl->UpdateModel( onlyOnceOperations );
2437 Vector3 naturalSize;
2438 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
2439 static_cast<OperationsMask>( onlyOnceOperations |
2440 LAYOUT | REORDER | UPDATE_DIRECTION ),
2441 naturalSize.GetVectorXY() );
2443 // Do not do again the only once operations.
2444 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2446 // Clear the update info. This info will be set the next time the text is updated.
2447 mImpl->mTextUpdateInfo.Clear();
2449 // FullRelayoutNeeded should be true because DoRelayout is MAX_FLOAT, MAX_FLOAT.
2450 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2452 mImpl->mUpdateTextDirection = false;
2455 return mImpl->mIsTextDirectionRTL ? Toolkit::DevelText::TextDirection::RIGHT_TO_LEFT : Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT;
2458 Toolkit::DevelText::VerticalLineAlignment::Type Controller::GetVerticalLineAlignment() const
2460 return mImpl->mModel->GetVerticalLineAlignment();
2463 void Controller::SetVerticalLineAlignment( Toolkit::DevelText::VerticalLineAlignment::Type alignment )
2465 mImpl->mModel->mVerticalLineAlignment = alignment;
2468 // public : Relayout.
2470 Controller::UpdateTextType Controller::Relayout( const Size& size, Dali::LayoutDirection::Type layoutDirection )
2472 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
2474 UpdateTextType updateTextType = NONE_UPDATED;
2476 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
2478 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
2480 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
2481 updateTextType = MODEL_UPDATED;
2484 // Clear the update info. This info will be set the next time the text is updated.
2485 mImpl->mTextUpdateInfo.Clear();
2487 // Not worth to relayout if width or height is equal to zero.
2488 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
2490 return updateTextType;
2493 // Whether a new size has been set.
2494 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
2498 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
2500 if( ( 0 == mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd ) &&
2501 ( 0 == mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) &&
2502 ( ( mImpl->mModel->mVisualModel->mControlSize.width < Math::MACHINE_EPSILON_1000 ) || ( mImpl->mModel->mVisualModel->mControlSize.height < Math::MACHINE_EPSILON_1000 ) ) )
2504 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
2507 // Layout operations that need to be done if the size changes.
2508 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2511 UPDATE_LAYOUT_SIZE |
2513 // Set the update info to relayout the whole text.
2514 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2515 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2517 // Store the size used to layout the text.
2518 mImpl->mModel->mVisualModel->mControlSize = size;
2521 // Whether there are modify events.
2522 if( 0u != mImpl->mModifyEvents.Count() )
2524 // Style operations that need to be done if the text is modified.
2525 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2529 // Set the update info to elide the text.
2530 if( mImpl->mModel->mElideEnabled ||
2531 ( ( NULL != mImpl->mEventData ) && mImpl->mEventData->mIsPlaceholderElideEnabled ) )
2533 // Update Text layout for applying elided
2534 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2537 UPDATE_LAYOUT_SIZE |
2539 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2540 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2543 if( mImpl->mModel->mMatchSystemLanguageDirection && mImpl->mLayoutDirection != layoutDirection )
2545 // Clear the update info. This info will be set the next time the text is updated.
2546 mImpl->mTextUpdateInfo.mClearAll = true;
2547 // Apply modifications to the model
2548 // Shape the text again is needed because characters like '()[]{}' have to be mirrored and the glyphs generated again.
2549 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2556 mImpl->mLayoutDirection = layoutDirection;
2559 // Make sure the model is up-to-date before layouting.
2560 ProcessModifyEvents();
2561 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
2565 updated = DoRelayout( size,
2566 mImpl->mOperationsPending,
2567 layoutSize ) || updated;
2572 updateTextType = MODEL_UPDATED;
2575 // Do not re-do any operation until something changes.
2576 mImpl->mOperationsPending = NO_OPERATION;
2577 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
2579 // Whether the text control is editable
2580 const bool isEditable = NULL != mImpl->mEventData;
2582 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
2584 if( newSize && isEditable )
2586 offset = mImpl->mModel->mScrollPosition;
2589 if( !isEditable || !IsMultiLineEnabled() )
2591 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
2592 CalculateVerticalOffset( size );
2599 // If there is a new size, the scroll position needs to be clamped.
2600 mImpl->ClampHorizontalScroll( layoutSize );
2602 // Update the decorator's positions is needed if there is a new size.
2603 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
2606 // Move the cursor, grab handle etc.
2607 if( mImpl->ProcessInputEvents() )
2609 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
2613 // Clear the update info. This info will be set the next time the text is updated.
2614 mImpl->mTextUpdateInfo.Clear();
2615 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
2617 return updateTextType;
2620 void Controller::RequestRelayout()
2622 mImpl->RequestRelayout();
2625 // public : Input style change signals.
2627 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
2629 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
2632 void Controller::ProcessInputStyleChangedSignals()
2634 if( NULL == mImpl->mEventData )
2640 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
2641 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
2645 const InputStyle::Mask mask = *it;
2647 if( NULL != mImpl->mEditableControlInterface )
2649 // Emit the input style changed signal.
2650 mImpl->mEditableControlInterface->InputStyleChanged( mask );
2654 mImpl->mEventData->mInputStyleChangedQueue.Clear();
2657 // public : Text-input Event Queuing.
2659 void Controller::KeyboardFocusGainEvent()
2661 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
2663 if( NULL != mImpl->mEventData )
2665 if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
2666 ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
2668 mImpl->ChangeState( EventData::EDITING );
2669 mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
2670 mImpl->mEventData->mUpdateInputStyle = true;
2671 mImpl->mEventData->mScrollAfterUpdatePosition = true;
2673 mImpl->NotifyInputMethodContextMultiLineStatus();
2674 if( mImpl->IsShowingPlaceholderText() )
2676 // Show alternative placeholder-text when editing
2677 ShowPlaceholderText();
2680 mImpl->RequestRelayout();
2684 void Controller::KeyboardFocusLostEvent()
2686 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
2688 if( NULL != mImpl->mEventData )
2690 if( EventData::INTERRUPTED != mImpl->mEventData->mState )
2692 mImpl->ChangeState( EventData::INACTIVE );
2694 if( !mImpl->IsShowingRealText() )
2696 // Revert to regular placeholder-text when not editing
2697 ShowPlaceholderText();
2701 mImpl->RequestRelayout();
2704 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
2706 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
2708 bool textChanged = false;
2709 bool relayoutNeeded = false;
2711 if( ( NULL != mImpl->mEventData ) &&
2712 ( keyEvent.state == KeyEvent::Down ) )
2714 int keyCode = keyEvent.keyCode;
2715 const std::string& keyString = keyEvent.keyPressed;
2716 const std::string keyName = keyEvent.keyPressedName;
2718 const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
2720 // Pre-process to separate modifying events from non-modifying input events.
2723 // In some platforms arrive key events with no key code.
2727 else if( Dali::DALI_KEY_ESCAPE == keyCode || Dali::DALI_KEY_BACK == keyCode || Dali::DALI_KEY_SEARCH == keyCode )
2732 else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) ||
2733 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
2734 ( Dali::DALI_KEY_CURSOR_UP == keyCode ) ||
2735 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) )
2737 // If don't have any text, do nothing.
2738 if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
2743 uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition;
2744 uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2745 uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition );
2746 uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines();
2748 // Logic to determine whether this text control will lose focus or not.
2749 if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2750 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2751 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) ||
2752 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) ||
2753 ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) ||
2754 ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) )
2756 // Release the active highlight.
2757 if( mImpl->mEventData->mState == EventData::SELECTING )
2759 mImpl->ChangeState( EventData::EDITING );
2761 // Update selection position.
2762 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2763 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2764 mImpl->mEventData->mUpdateCursorPosition = true;
2765 mImpl->RequestRelayout();
2770 mImpl->mEventData->mCheckScrollAmount = true;
2771 Event event( Event::CURSOR_KEY_EVENT );
2772 event.p1.mInt = keyCode;
2773 event.p2.mBool = keyEvent.IsShiftModifier();
2774 mImpl->mEventData->mEventQueue.push_back( event );
2776 // Will request for relayout.
2777 relayoutNeeded = true;
2779 else if ( Dali::DevelKey::DALI_KEY_CONTROL_LEFT == keyCode || Dali::DevelKey::DALI_KEY_CONTROL_RIGHT == keyCode )
2781 // Left or Right Control key event is received before Ctrl-C/V/X key event is received
2782 // If not handle it here, any selected text will be deleted
2787 else if ( keyEvent.IsCtrlModifier() )
2789 bool consumed = false;
2790 if (keyName == KEY_C_NAME)
2792 // Ctrl-C to copy the selected text
2793 TextPopupButtonTouched( Toolkit::TextSelectionPopup::COPY );
2796 else if (keyName == KEY_V_NAME)
2798 // Ctrl-V to paste the copied text
2799 TextPopupButtonTouched( Toolkit::TextSelectionPopup::PASTE );
2802 else if (keyName == KEY_X_NAME)
2804 // Ctrl-X to cut the selected text
2805 TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
2810 else if( ( Dali::DALI_KEY_BACKSPACE == keyCode ) ||
2811 ( Dali::DevelKey::DALI_KEY_DELETE == keyCode ) )
2813 textChanged = DeleteEvent( keyCode );
2815 // Will request for relayout.
2816 relayoutNeeded = true;
2818 else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
2819 IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
2820 IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
2822 // Power key/Menu/Home key behaviour does not allow edit mode to resume.
2823 mImpl->ChangeState( EventData::INACTIVE );
2825 // Will request for relayout.
2826 relayoutNeeded = true;
2828 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2830 else if( ( Dali::DALI_KEY_SHIFT_LEFT == keyCode ) || ( Dali::DALI_KEY_SHIFT_RIGHT == keyCode ) )
2832 // 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
2833 // and a character is typed after the type of a upper case latin character.
2838 else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
2840 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2846 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
2848 if( !keyString.empty() )
2850 // InputMethodContext is no longer handling key-events
2851 mImpl->ClearPreEditFlag();
2853 InsertText( keyString, COMMIT );
2857 // Will request for relayout.
2858 relayoutNeeded = true;
2863 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
2864 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
2866 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
2867 ( Dali::DALI_KEY_SHIFT_RIGHT != keyCode ) &&
2868 ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
2869 ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
2871 // Should not change the state if the key is the shift send by the InputMethodContext.
2872 // Otherwise, when the state is SELECTING the text controller can't send the right
2873 // surrounding info to the InputMethodContext.
2874 mImpl->ChangeState( EventData::EDITING );
2876 // Will request for relayout.
2877 relayoutNeeded = true;
2880 if( relayoutNeeded )
2882 mImpl->RequestRelayout();
2887 ( NULL != mImpl->mEditableControlInterface ) )
2889 // Do this last since it provides callbacks into application code
2890 mImpl->mEditableControlInterface->TextChanged();
2896 void Controller::TapEvent( unsigned int tapCount, float x, float y )
2898 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
2900 if( NULL != mImpl->mEventData )
2902 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
2903 EventData::State state( mImpl->mEventData->mState );
2904 bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
2906 if( mImpl->IsClipboardVisible() )
2908 if( EventData::INACTIVE == state || EventData::EDITING == state)
2910 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2912 relayoutNeeded = true;
2914 else if( 1u == tapCount )
2916 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
2918 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
2921 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
2923 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2924 relayoutNeeded = true;
2928 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
2930 // Hide placeholder text
2934 if( EventData::INACTIVE == state )
2936 mImpl->ChangeState( EventData::EDITING );
2938 else if( !mImpl->IsClipboardEmpty() )
2940 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
2942 relayoutNeeded = true;
2945 else if( 2u == tapCount )
2947 if( mImpl->mEventData->mSelectionEnabled &&
2948 mImpl->IsShowingRealText() )
2950 relayoutNeeded = true;
2951 mImpl->mEventData->mIsLeftHandleSelected = true;
2952 mImpl->mEventData->mIsRightHandleSelected = true;
2956 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
2957 if( relayoutNeeded )
2959 Event event( Event::TAP_EVENT );
2960 event.p1.mUint = tapCount;
2961 event.p2.mFloat = x;
2962 event.p3.mFloat = y;
2963 mImpl->mEventData->mEventQueue.push_back( event );
2965 mImpl->RequestRelayout();
2969 // Reset keyboard as tap event has occurred.
2970 mImpl->ResetInputMethodContext();
2973 void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
2975 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
2977 if( NULL != mImpl->mEventData )
2979 Event event( Event::PAN_EVENT );
2980 event.p1.mInt = state;
2981 event.p2.mFloat = displacement.x;
2982 event.p3.mFloat = displacement.y;
2983 mImpl->mEventData->mEventQueue.push_back( event );
2985 mImpl->RequestRelayout();
2989 void Controller::LongPressEvent( Gesture::State state, float x, float y )
2991 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
2993 if( ( state == Gesture::Started ) &&
2994 ( NULL != mImpl->mEventData ) )
2996 // The 1st long-press on inactive text-field is treated as tap
2997 if( EventData::INACTIVE == mImpl->mEventData->mState )
2999 mImpl->ChangeState( EventData::EDITING );
3001 Event event( Event::TAP_EVENT );
3003 event.p2.mFloat = x;
3004 event.p3.mFloat = y;
3005 mImpl->mEventData->mEventQueue.push_back( event );
3007 mImpl->RequestRelayout();
3009 else if( !mImpl->IsShowingRealText() )
3011 Event event( Event::LONG_PRESS_EVENT );
3012 event.p1.mInt = state;
3013 event.p2.mFloat = x;
3014 event.p3.mFloat = y;
3015 mImpl->mEventData->mEventQueue.push_back( event );
3016 mImpl->RequestRelayout();
3018 else if( !mImpl->IsClipboardVisible() )
3020 // Reset the InputMethodContext to commit the pre-edit before selecting the text.
3021 mImpl->ResetInputMethodContext();
3023 Event event( Event::LONG_PRESS_EVENT );
3024 event.p1.mInt = state;
3025 event.p2.mFloat = x;
3026 event.p3.mFloat = y;
3027 mImpl->mEventData->mEventQueue.push_back( event );
3028 mImpl->RequestRelayout();
3030 mImpl->mEventData->mIsLeftHandleSelected = true;
3031 mImpl->mEventData->mIsRightHandleSelected = true;
3036 void Controller::SelectEvent( float x, float y, SelectionType selectType )
3038 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
3040 if( NULL != mImpl->mEventData )
3042 if( selectType == SelectionType::ALL )
3044 Event event( Event::SELECT_ALL );
3045 mImpl->mEventData->mEventQueue.push_back( event );
3047 else if( selectType == SelectionType::NONE )
3049 Event event( Event::SELECT_NONE );
3050 mImpl->mEventData->mEventQueue.push_back( event );
3054 Event event( Event::SELECT );
3055 event.p2.mFloat = x;
3056 event.p3.mFloat = y;
3057 mImpl->mEventData->mEventQueue.push_back( event );
3060 mImpl->mEventData->mCheckScrollAmount = true;
3061 mImpl->mEventData->mIsLeftHandleSelected = true;
3062 mImpl->mEventData->mIsRightHandleSelected = true;
3063 mImpl->RequestRelayout();
3067 InputMethodContext::CallbackData Controller::OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
3069 // Whether the text needs to be relaid-out.
3070 bool requestRelayout = false;
3072 // Whether to retrieve the text and cursor position to be sent to the InputMethodContext.
3073 bool retrieveText = false;
3074 bool retrieveCursor = false;
3076 switch( inputMethodContextEvent.eventName )
3078 case InputMethodContext::COMMIT:
3080 InsertText( inputMethodContextEvent.predictiveString, Text::Controller::COMMIT );
3081 requestRelayout = true;
3082 retrieveCursor = true;
3085 case InputMethodContext::PRE_EDIT:
3087 InsertText( inputMethodContextEvent.predictiveString, Text::Controller::PRE_EDIT );
3088 requestRelayout = true;
3089 retrieveCursor = true;
3092 case InputMethodContext::DELETE_SURROUNDING:
3094 const bool textDeleted = RemoveText( inputMethodContextEvent.cursorOffset,
3095 inputMethodContextEvent.numberOfChars,
3096 DONT_UPDATE_INPUT_STYLE );
3100 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3101 !mImpl->IsPlaceholderAvailable() )
3103 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3107 ShowPlaceholderText();
3109 mImpl->mEventData->mUpdateCursorPosition = true;
3110 mImpl->mEventData->mScrollAfterDelete = true;
3112 requestRelayout = true;
3116 case InputMethodContext::GET_SURROUNDING:
3118 retrieveText = true;
3119 retrieveCursor = true;
3122 case InputMethodContext::PRIVATE_COMMAND:
3124 // PRIVATECOMMAND event is just for getting the private command message
3125 retrieveText = true;
3126 retrieveCursor = true;
3129 case InputMethodContext::VOID:
3136 if( requestRelayout )
3138 mImpl->mOperationsPending = ALL_OPERATIONS;
3139 mImpl->RequestRelayout();
3143 CharacterIndex cursorPosition = 0u;
3144 Length numberOfWhiteSpaces = 0u;
3146 if( retrieveCursor )
3148 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
3150 cursorPosition = mImpl->GetLogicalCursorPosition();
3152 if( cursorPosition < numberOfWhiteSpaces )
3154 cursorPosition = 0u;
3158 cursorPosition -= numberOfWhiteSpaces;
3164 if( !mImpl->IsShowingPlaceholderText() )
3166 // Retrieves the normal text string.
3167 mImpl->GetText( numberOfWhiteSpaces, text );
3171 // When the current text is Placeholder Text, the surrounding text should be empty string.
3172 // It means DALi should send empty string ("") to IME.
3177 InputMethodContext::CallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
3179 if( requestRelayout &&
3180 ( NULL != mImpl->mEditableControlInterface ) )
3182 // Do this last since it provides callbacks into application code
3183 mImpl->mEditableControlInterface->TextChanged();
3186 return callbackData;
3189 void Controller::PasteClipboardItemEvent()
3191 // Retrieve the clipboard contents first
3192 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
3193 std::string stringToPaste( notifier.GetContent() );
3195 // Commit the current pre-edit text; the contents of the clipboard should be appended
3196 mImpl->ResetInputMethodContext();
3198 // Temporary disable hiding clipboard
3199 mImpl->SetClipboardHideEnable( false );
3202 PasteText( stringToPaste );
3204 mImpl->SetClipboardHideEnable( true );
3207 // protected : Inherit from Text::Decorator::ControllerInterface.
3209 void Controller::GetTargetSize( Vector2& targetSize )
3211 targetSize = mImpl->mModel->mVisualModel->mControlSize;
3214 void Controller::AddDecoration( Actor& actor, bool needsClipping )
3216 if( NULL != mImpl->mEditableControlInterface )
3218 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
3222 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
3224 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
3226 if( NULL != mImpl->mEventData )
3228 switch( handleType )
3232 Event event( Event::GRAB_HANDLE_EVENT );
3233 event.p1.mUint = state;
3234 event.p2.mFloat = x;
3235 event.p3.mFloat = y;
3237 mImpl->mEventData->mEventQueue.push_back( event );
3240 case LEFT_SELECTION_HANDLE:
3242 Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
3243 event.p1.mUint = state;
3244 event.p2.mFloat = x;
3245 event.p3.mFloat = y;
3247 mImpl->mEventData->mEventQueue.push_back( event );
3250 case RIGHT_SELECTION_HANDLE:
3252 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
3253 event.p1.mUint = state;
3254 event.p2.mFloat = x;
3255 event.p3.mFloat = y;
3257 mImpl->mEventData->mEventQueue.push_back( event );
3260 case LEFT_SELECTION_HANDLE_MARKER:
3261 case RIGHT_SELECTION_HANDLE_MARKER:
3263 // Markers do not move the handles.
3266 case HANDLE_TYPE_COUNT:
3268 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
3272 mImpl->RequestRelayout();
3276 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
3278 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
3280 if( NULL == mImpl->mEventData )
3287 case Toolkit::TextSelectionPopup::CUT:
3289 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
3290 mImpl->mOperationsPending = ALL_OPERATIONS;
3292 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3293 !mImpl->IsPlaceholderAvailable() )
3295 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3299 ShowPlaceholderText();
3302 mImpl->mEventData->mUpdateCursorPosition = true;
3303 mImpl->mEventData->mScrollAfterDelete = true;
3305 mImpl->RequestRelayout();
3307 if( NULL != mImpl->mEditableControlInterface )
3309 mImpl->mEditableControlInterface->TextChanged();
3313 case Toolkit::TextSelectionPopup::COPY:
3315 mImpl->SendSelectionToClipboard( false ); // Text not modified
3317 mImpl->mEventData->mUpdateCursorPosition = true;
3319 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
3322 case Toolkit::TextSelectionPopup::PASTE:
3324 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
3327 case Toolkit::TextSelectionPopup::SELECT:
3329 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
3331 if( mImpl->mEventData->mSelectionEnabled )
3333 // Creates a SELECT event.
3334 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, SelectionType::INTERACTIVE );
3338 case Toolkit::TextSelectionPopup::SELECT_ALL:
3340 // Creates a SELECT_ALL event
3341 SelectEvent( 0.f, 0.f, SelectionType::ALL );
3344 case Toolkit::TextSelectionPopup::CLIPBOARD:
3346 mImpl->ShowClipboard();
3349 case Toolkit::TextSelectionPopup::NONE:
3357 void Controller::DisplayTimeExpired()
3359 mImpl->mEventData->mUpdateCursorPosition = true;
3360 // Apply modifications to the model
3361 mImpl->mOperationsPending = ALL_OPERATIONS;
3363 mImpl->RequestRelayout();
3366 // private : Update.
3368 void Controller::InsertText( const std::string& text, Controller::InsertType type )
3370 bool removedPrevious = false;
3371 bool removedSelected = false;
3372 bool maxLengthReached = false;
3374 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
3376 if( NULL == mImpl->mEventData )
3381 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
3382 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
3383 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3385 // TODO: At the moment the underline runs are only for pre-edit.
3386 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
3388 // Remove the previous InputMethodContext pre-edit.
3389 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
3391 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
3392 mImpl->mEventData->mPreEditLength,
3393 DONT_UPDATE_INPUT_STYLE );
3395 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
3396 mImpl->mEventData->mPreEditLength = 0u;
3400 // Remove the previous Selection.
3401 removedSelected = RemoveSelectedText();
3405 Vector<Character> utf32Characters;
3406 Length characterCount = 0u;
3410 // Convert text into UTF-32
3411 utf32Characters.Resize( text.size() );
3413 // This is a bit horrible but std::string returns a (signed) char*
3414 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
3416 // Transform a text array encoded in utf8 into an array encoded in utf32.
3417 // It returns the actual number of characters.
3418 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
3419 utf32Characters.Resize( characterCount );
3421 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
3422 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
3425 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
3427 // The placeholder text is no longer needed
3428 if( mImpl->IsShowingPlaceholderText() )
3433 mImpl->ChangeState( EventData::EDITING );
3435 // Handle the InputMethodContext (predicitive text) state changes
3436 if( COMMIT == type )
3438 // InputMethodContext is no longer handling key-events
3439 mImpl->ClearPreEditFlag();
3443 if( !mImpl->mEventData->mPreEditFlag )
3445 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
3447 // Record the start of the pre-edit text
3448 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
3451 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
3452 mImpl->mEventData->mPreEditFlag = true;
3454 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3457 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
3459 // Restrict new text to fit within Maximum characters setting.
3460 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
3461 maxLengthReached = ( characterCount > maxSizeOfNewText );
3463 // The cursor position.
3464 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3466 // Update the text's style.
3468 // Updates the text style runs by adding characters.
3469 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
3471 // Get the character index from the cursor index.
3472 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
3474 // Retrieve the text's style for the given index.
3476 mImpl->RetrieveDefaultInputStyle( style );
3477 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
3479 // Whether to add a new text color run.
3480 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor ) && !mImpl->mEventData->mInputStyle.isDefaultColor;
3482 // Whether to add a new font run.
3483 const bool addFontNameRun = ( style.familyName != mImpl->mEventData->mInputStyle.familyName ) && mImpl->mEventData->mInputStyle.isFamilyDefined;
3484 const bool addFontWeightRun = ( style.weight != mImpl->mEventData->mInputStyle.weight ) && mImpl->mEventData->mInputStyle.isWeightDefined;
3485 const bool addFontWidthRun = ( style.width != mImpl->mEventData->mInputStyle.width ) && mImpl->mEventData->mInputStyle.isWidthDefined;
3486 const bool addFontSlantRun = ( style.slant != mImpl->mEventData->mInputStyle.slant ) && mImpl->mEventData->mInputStyle.isSlantDefined;
3487 const bool addFontSizeRun = ( style.size != mImpl->mEventData->mInputStyle.size ) && mImpl->mEventData->mInputStyle.isSizeDefined ;
3492 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
3493 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
3495 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
3496 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
3497 colorRun.characterRun.characterIndex = cursorIndex;
3498 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3501 if( addFontNameRun ||
3507 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
3508 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
3510 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
3512 if( addFontNameRun )
3514 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
3515 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
3516 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
3517 fontDescriptionRun.familyDefined = true;
3519 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
3522 if( addFontWeightRun )
3524 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
3525 fontDescriptionRun.weightDefined = true;
3528 if( addFontWidthRun )
3530 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
3531 fontDescriptionRun.widthDefined = true;
3534 if( addFontSlantRun )
3536 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
3537 fontDescriptionRun.slantDefined = true;
3540 if( addFontSizeRun )
3542 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
3543 fontDescriptionRun.sizeDefined = true;
3546 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
3547 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3550 // Insert at current cursor position.
3551 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
3553 if( cursorIndex < numberOfCharactersInModel )
3555 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3559 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3562 // Mark the first paragraph to be updated.
3563 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3565 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3566 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3567 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
3568 mImpl->mTextUpdateInfo.mClearAll = true;
3572 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3573 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
3576 // Update the cursor index.
3577 cursorIndex += maxSizeOfNewText;
3579 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 );
3582 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
3583 mImpl->IsPlaceholderAvailable() )
3585 // Show place-holder if empty after removing the pre-edit text
3586 ShowPlaceholderText();
3587 mImpl->mEventData->mUpdateCursorPosition = true;
3588 mImpl->ClearPreEditFlag();
3590 else if( removedPrevious ||
3592 ( 0 != utf32Characters.Count() ) )
3594 // Queue an inserted event
3595 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
3597 mImpl->mEventData->mUpdateCursorPosition = true;
3598 if( removedSelected )
3600 mImpl->mEventData->mScrollAfterDelete = true;
3604 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3608 if( maxLengthReached )
3610 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
3612 mImpl->ResetInputMethodContext();
3614 if( NULL != mImpl->mEditableControlInterface )
3616 // Do this last since it provides callbacks into application code
3617 mImpl->mEditableControlInterface->MaxLengthReached();
3622 void Controller::PasteText( const std::string& stringToPaste )
3624 InsertText( stringToPaste, Text::Controller::COMMIT );
3625 mImpl->ChangeState( EventData::EDITING );
3626 mImpl->RequestRelayout();
3628 if( NULL != mImpl->mEditableControlInterface )
3630 // Do this last since it provides callbacks into application code
3631 mImpl->mEditableControlInterface->TextChanged();
3635 bool Controller::RemoveText( int cursorOffset,
3636 int numberOfCharacters,
3637 UpdateInputStyleType type )
3639 bool removed = false;
3641 if( NULL == mImpl->mEventData )
3646 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
3647 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
3649 if( !mImpl->IsShowingPlaceholderText() )
3651 // Delete at current cursor position
3652 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
3653 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3655 CharacterIndex cursorIndex = 0;
3657 // Validate the cursor position & number of characters
3658 if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
3660 cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
3663 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
3665 numberOfCharacters = currentText.Count() - cursorIndex;
3668 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.
3669 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
3671 // Mark the paragraphs to be updated.
3672 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3674 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3675 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3676 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
3677 mImpl->mTextUpdateInfo.mClearAll = true;
3681 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3682 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
3685 // Update the input style and remove the text's style before removing the text.
3687 if( UPDATE_INPUT_STYLE == type )
3689 // Keep a copy of the current input style.
3690 InputStyle currentInputStyle;
3691 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
3693 // Set first the default input style.
3694 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
3696 // Update the input style.
3697 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
3699 // Compare if the input style has changed.
3700 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
3702 if( hasInputStyleChanged )
3704 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
3705 // Queue the input style changed signal.
3706 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
3710 // If the number of current text and the number of characters to be deleted are same,
3711 // it means all texts should be removed and all Preedit variables should be initialized.
3712 if( ( currentText.Count() - numberOfCharacters == 0 ) && ( cursorIndex == 0 ) )
3714 mImpl->ClearPreEditFlag();
3717 // Updates the text style runs by removing characters. Runs with no characters are removed.
3718 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
3720 // Remove the characters.
3721 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
3722 Vector<Character>::Iterator last = first + numberOfCharacters;
3724 currentText.Erase( first, last );
3726 // Cursor position retreat
3727 oldCursorIndex = cursorIndex;
3729 mImpl->mEventData->mScrollAfterDelete = true;
3731 if( EventData::INACTIVE == mImpl->mEventData->mState )
3733 mImpl->ChangeState( EventData::EDITING );
3736 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
3744 bool Controller::RemoveSelectedText()
3746 bool textRemoved( false );
3748 if( EventData::SELECTING == mImpl->mEventData->mState )
3750 std::string removedString;
3751 mImpl->RetrieveSelection( removedString, true );
3753 if( !removedString.empty() )
3756 mImpl->ChangeState( EventData::EDITING );
3763 std::string Controller::GetSelectedText()
3766 if( EventData::SELECTING == mImpl->mEventData->mState )
3768 mImpl->RetrieveSelection( text, false );
3773 // private : Relayout.
3775 bool Controller::DoRelayout( const Size& size,
3776 OperationsMask operationsRequired,
3779 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
3780 bool viewUpdated( false );
3782 // Calculate the operations to be done.
3783 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
3785 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
3786 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
3788 // Get the current layout size.
3789 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3791 if( NO_OPERATION != ( LAYOUT & operations ) )
3793 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
3795 // Some vectors with data needed to layout and reorder may be void
3796 // after the first time the text has been laid out.
3797 // Fill the vectors again.
3799 // Calculate the number of glyphs to layout.
3800 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
3801 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
3802 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
3803 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
3805 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
3806 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
3808 // Make sure the index is not out of bound
3809 if ( charactersToGlyph.Count() != glyphsPerCharacter.Count() ||
3810 requestedNumberOfCharacters > charactersToGlyph.Count() ||
3811 ( lastIndex > charactersToGlyph.Count() && charactersToGlyph.Count() > 0u ) )
3813 std::string currentText;
3814 GetText( currentText );
3816 DALI_LOG_ERROR( "Controller::DoRelayout: Attempting to access invalid buffer\n" );
3817 DALI_LOG_ERROR( "Current text is: %s\n", currentText.c_str() );
3818 DALI_LOG_ERROR( "startIndex: %u, lastIndex: %u, requestedNumberOfCharacters: %u, charactersToGlyph.Count = %lu, glyphsPerCharacter.Count = %lu\n", startIndex, lastIndex, requestedNumberOfCharacters, charactersToGlyph.Count(), glyphsPerCharacter.Count());
3823 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
3824 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
3826 if( 0u == totalNumberOfGlyphs )
3828 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3830 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
3833 // Nothing else to do if there is no glyphs.
3834 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
3838 // Set the layout parameters.
3839 Layout::Parameters layoutParameters( size,
3842 // Resize the vector of positions to have the same size than the vector of glyphs.
3843 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
3844 glyphPositions.Resize( totalNumberOfGlyphs );
3846 // Whether the last character is a new paragraph character.
3847 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
3848 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
3849 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
3851 // The initial glyph and the number of glyphs to layout.
3852 layoutParameters.startGlyphIndex = startGlyphIndex;
3853 layoutParameters.numberOfGlyphs = numberOfGlyphs;
3854 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
3855 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
3857 // Update the ellipsis
3858 bool elideTextEnabled = mImpl->mModel->mElideEnabled;
3860 if( NULL != mImpl->mEventData )
3862 if( mImpl->mEventData->mPlaceholderEllipsisFlag && mImpl->IsShowingPlaceholderText() )
3864 elideTextEnabled = mImpl->mEventData->mIsPlaceholderElideEnabled;
3866 else if( EventData::INACTIVE != mImpl->mEventData->mState )
3868 // Disable ellipsis when editing
3869 elideTextEnabled = false;
3872 // Reset the scroll position in inactive state
3873 if( elideTextEnabled && ( mImpl->mEventData->mState == EventData::INACTIVE ) )
3875 ResetScrollPosition();
3879 // Update the visual model.
3880 bool isAutoScrollEnabled = mImpl->mIsAutoScrollEnabled;
3882 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
3885 isAutoScrollEnabled );
3886 mImpl->mIsAutoScrollEnabled = isAutoScrollEnabled;
3888 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
3892 layoutSize = newLayoutSize;
3894 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
3896 mImpl->mIsTextDirectionRTL = false;
3899 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && !mImpl->mModel->mVisualModel->mLines.Empty() )
3901 mImpl->mIsTextDirectionRTL = mImpl->mModel->mVisualModel->mLines[0u].direction;
3904 // Sets the layout size.
3905 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3907 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
3912 if( NO_OPERATION != ( ALIGN & operations ) )
3914 // The laid-out lines.
3915 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
3917 CharacterIndex alignStartIndex = startIndex;
3918 Length alignRequestedNumberOfCharacters = requestedNumberOfCharacters;
3920 // the whole text needs to be full aligned.
3921 // If you do not do a full aligned, only the last line of the multiline input is aligned.
3922 if( mImpl->mEventData && mImpl->mEventData->mUpdateAlignment )
3924 alignStartIndex = 0u;
3925 alignRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
3926 mImpl->mEventData->mUpdateAlignment = false;
3929 // Need to align with the control's size as the text may contain lines
3930 // starting either with left to right text or right to left.
3931 mImpl->mLayoutEngine.Align( size,
3933 alignRequestedNumberOfCharacters,
3934 mImpl->mModel->mHorizontalAlignment,
3936 mImpl->mModel->mAlignmentOffset,
3937 mImpl->mLayoutDirection,
3938 mImpl->mModel->mMatchSystemLanguageDirection );
3942 #if defined(DEBUG_ENABLED)
3943 std::string currentText;
3944 GetText( currentText );
3945 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mIsTextDirectionRTL[%s] [%s]\n", this, (mImpl->mIsTextDirectionRTL)?"true":"false", currentText.c_str() );
3947 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
3951 void Controller::CalculateVerticalOffset( const Size& controlSize )
3953 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3955 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
3957 // Get the line height of the default font.
3958 layoutSize.height = mImpl->GetDefaultFontLineHeight();
3961 switch( mImpl->mModel->mVerticalAlignment )
3963 case VerticalAlignment::TOP:
3965 mImpl->mModel->mScrollPosition.y = 0.f;
3968 case VerticalAlignment::CENTER:
3970 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
3973 case VerticalAlignment::BOTTOM:
3975 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
3981 // private : Events.
3983 void Controller::ProcessModifyEvents()
3985 Vector<ModifyEvent>& events = mImpl->mModifyEvents;
3987 if( 0u == events.Count() )
3993 for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
3994 endIt = events.End();
3998 const ModifyEvent& event = *it;
4000 if( ModifyEvent::TEXT_REPLACED == event.type )
4002 // A (single) replace event should come first, otherwise we wasted time processing NOOP events
4003 DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
4005 TextReplacedEvent();
4007 else if( ModifyEvent::TEXT_INSERTED == event.type )
4009 TextInsertedEvent();
4011 else if( ModifyEvent::TEXT_DELETED == event.type )
4013 // Placeholder-text cannot be deleted
4014 if( !mImpl->IsShowingPlaceholderText() )
4021 if( NULL != mImpl->mEventData )
4023 // When the text is being modified, delay cursor blinking
4024 mImpl->mEventData->mDecorator->DelayCursorBlink();
4026 // Update selection position after modifying the text
4027 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
4028 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
4031 // Discard temporary text
4035 void Controller::TextReplacedEvent()
4037 // The natural size needs to be re-calculated.
4038 mImpl->mRecalculateNaturalSize = true;
4040 // The text direction needs to be updated.
4041 mImpl->mUpdateTextDirection = true;
4043 // Apply modifications to the model
4044 mImpl->mOperationsPending = ALL_OPERATIONS;
4047 void Controller::TextInsertedEvent()
4049 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
4051 if( NULL == mImpl->mEventData )
4056 mImpl->mEventData->mCheckScrollAmount = true;
4058 // The natural size needs to be re-calculated.
4059 mImpl->mRecalculateNaturalSize = true;
4061 // The text direction needs to be updated.
4062 mImpl->mUpdateTextDirection = true;
4064 // Apply modifications to the model; TODO - Optimize this
4065 mImpl->mOperationsPending = ALL_OPERATIONS;
4068 void Controller::TextDeletedEvent()
4070 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
4072 if( NULL == mImpl->mEventData )
4077 mImpl->mEventData->mCheckScrollAmount = true;
4079 // The natural size needs to be re-calculated.
4080 mImpl->mRecalculateNaturalSize = true;
4082 // The text direction needs to be updated.
4083 mImpl->mUpdateTextDirection = true;
4085 // Apply modifications to the model; TODO - Optimize this
4086 mImpl->mOperationsPending = ALL_OPERATIONS;
4089 bool Controller::DeleteEvent( int keyCode )
4091 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p KeyCode : %d \n", this, keyCode );
4093 bool removed = false;
4095 if( NULL == mImpl->mEventData )
4100 // InputMethodContext is no longer handling key-events
4101 mImpl->ClearPreEditFlag();
4103 if( EventData::SELECTING == mImpl->mEventData->mState )
4105 removed = RemoveSelectedText();
4107 else if( ( mImpl->mEventData->mPrimaryCursorPosition > 0 ) && ( keyCode == Dali::DALI_KEY_BACKSPACE) )
4109 // Remove the character before the current cursor position
4110 removed = RemoveText( -1,
4112 UPDATE_INPUT_STYLE );
4114 else if( keyCode == Dali::DevelKey::DALI_KEY_DELETE )
4116 // Remove the character after the current cursor position
4117 removed = RemoveText( 0,
4119 UPDATE_INPUT_STYLE );
4124 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
4125 !mImpl->IsPlaceholderAvailable() )
4127 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
4131 ShowPlaceholderText();
4133 mImpl->mEventData->mUpdateCursorPosition = true;
4134 mImpl->mEventData->mScrollAfterDelete = true;
4140 // private : Helpers.
4142 void Controller::ResetText()
4145 mImpl->mModel->mLogicalModel->mText.Clear();
4147 // Reset the embedded images buffer.
4148 mImpl->mModel->mLogicalModel->ClearEmbeddedImages();
4150 // We have cleared everything including the placeholder-text
4151 mImpl->PlaceholderCleared();
4153 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4154 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4155 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
4157 // Clear any previous text.
4158 mImpl->mTextUpdateInfo.mClearAll = true;
4160 // The natural size needs to be re-calculated.
4161 mImpl->mRecalculateNaturalSize = true;
4163 // The text direction needs to be updated.
4164 mImpl->mUpdateTextDirection = true;
4166 // Apply modifications to the model
4167 mImpl->mOperationsPending = ALL_OPERATIONS;
4170 void Controller::ShowPlaceholderText()
4172 if( mImpl->IsPlaceholderAvailable() )
4174 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
4176 if( NULL == mImpl->mEventData )
4181 mImpl->mEventData->mIsShowingPlaceholderText = true;
4183 // Disable handles when showing place-holder text
4184 mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
4185 mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
4186 mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
4188 const char* text( NULL );
4191 // TODO - Switch Placeholder text when changing state
4192 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
4193 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
4195 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
4196 size = mImpl->mEventData->mPlaceholderTextActive.size();
4200 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
4201 size = mImpl->mEventData->mPlaceholderTextInactive.size();
4204 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4205 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4207 // Reset model for showing placeholder.
4208 mImpl->mModel->mLogicalModel->mText.Clear();
4209 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
4211 // Convert text into UTF-32
4212 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
4213 utf32Characters.Resize( size );
4215 // This is a bit horrible but std::string returns a (signed) char*
4216 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
4218 // Transform a text array encoded in utf8 into an array encoded in utf32.
4219 // It returns the actual number of characters.
4220 const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
4221 utf32Characters.Resize( characterCount );
4223 // The characters to be added.
4224 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
4226 // Reset the cursor position
4227 mImpl->mEventData->mPrimaryCursorPosition = 0;
4229 // The natural size needs to be re-calculated.
4230 mImpl->mRecalculateNaturalSize = true;
4232 // The text direction needs to be updated.
4233 mImpl->mUpdateTextDirection = true;
4235 // Apply modifications to the model
4236 mImpl->mOperationsPending = ALL_OPERATIONS;
4238 // Update the rest of the model during size negotiation
4239 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
4243 void Controller::ClearFontData()
4245 if( mImpl->mFontDefaults )
4247 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
4250 // Set flags to update the model.
4251 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4252 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4253 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
4255 mImpl->mTextUpdateInfo.mClearAll = true;
4256 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
4257 mImpl->mRecalculateNaturalSize = true;
4259 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
4265 UPDATE_LAYOUT_SIZE |
4270 void Controller::ClearStyleData()
4272 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
4273 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
4276 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
4278 // Reset the cursor position
4279 if( NULL != mImpl->mEventData )
4281 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
4283 // Update the cursor if it's in editing mode.
4284 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
4286 mImpl->mEventData->mUpdateCursorPosition = true;
4291 void Controller::ResetScrollPosition()
4293 if( NULL != mImpl->mEventData )
4295 // Reset the scroll position.
4296 mImpl->mModel->mScrollPosition = Vector2::ZERO;
4297 mImpl->mEventData->mScrollAfterUpdatePosition = true;
4301 void Controller::SetControlInterface( ControlInterface* controlInterface )
4303 mImpl->mControlInterface = controlInterface;
4306 bool Controller::ShouldClearFocusOnEscape() const
4308 return mImpl->mShouldClearFocusOnEscape;
4311 Actor Controller::CreateBackgroundActor()
4313 return mImpl->CreateBackgroundActor();
4316 // private : Private contructors & copy operator.
4318 Controller::Controller()
4321 mImpl = new Controller::Impl( NULL, NULL );
4324 Controller::Controller( ControlInterface* controlInterface )
4326 mImpl = new Controller::Impl( controlInterface, NULL );
4329 Controller::Controller( ControlInterface* controlInterface,
4330 EditableControlInterface* editableControlInterface )
4332 mImpl = new Controller::Impl( controlInterface,
4333 editableControlInterface );
4336 // The copy constructor and operator are left unimplemented.
4338 // protected : Destructor.
4340 Controller::~Controller()
4347 } // namespace Toolkit