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/public-api/actors/layer.h>
27 #include <dali/public-api/common/stage.h>
28 #include <dali/integration-api/debug.h>
29 #include <dali/devel-api/adaptor-framework/clipboard-event-notifier.h>
30 #include <dali/devel-api/text-abstraction/font-client.h>
31 #include <dali/devel-api/adaptor-framework/key-devel.h>
34 #include <dali-toolkit/public-api/controls/text-controls/placeholder-properties.h>
35 #include <dali-toolkit/internal/text/bidirectional-support.h>
36 #include <dali-toolkit/internal/text/character-set-conversion.h>
37 #include <dali-toolkit/internal/text/layouts/layout-parameters.h>
38 #include <dali-toolkit/internal/text/markup-processor.h>
39 #include <dali-toolkit/internal/text/multi-language-support.h>
40 #include <dali-toolkit/internal/text/text-controller-impl.h>
41 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
42 #include <dali-toolkit/internal/text/text-font-style.h>
47 #if defined(DEBUG_ENABLED)
48 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
51 const float MAX_FLOAT = std::numeric_limits<float>::max();
53 const std::string EMPTY_STRING("");
55 const std::string KEY_C_NAME = "c";
56 const std::string KEY_V_NAME = "v";
57 const std::string KEY_X_NAME = "x";
59 const char * const PLACEHOLDER_TEXT = "text";
60 const char * const PLACEHOLDER_TEXT_FOCUSED = "textFocused";
61 const char * const PLACEHOLDER_COLOR = "color";
62 const char * const PLACEHOLDER_FONT_FAMILY = "fontFamily";
63 const char * const PLACEHOLDER_FONT_STYLE = "fontStyle";
64 const char * const PLACEHOLDER_POINT_SIZE = "pointSize";
65 const char * const PLACEHOLDER_PIXEL_SIZE = "pixelSize";
66 const char * const PLACEHOLDER_ELLIPSIS = "ellipsis";
67 const unsigned int MAX_TEXT_LENGTH = 1024u * 32u;
69 float ConvertToEven( float value )
71 int intValue(static_cast<int>( value ));
72 return static_cast<float>( intValue + ( intValue & 1 ) );
75 int ConvertPixelToPint( float pixel )
77 unsigned int horizontalDpi = 0u;
78 unsigned int verticalDpi = 0u;
79 Dali::TextAbstraction::FontClient fontClient = Dali::TextAbstraction::FontClient::Get();
80 fontClient.GetDpi( horizontalDpi, verticalDpi );
82 return ( pixel * 72.f ) / static_cast< float >( horizontalDpi );
97 * @brief Adds a new font description run for the selected text.
99 * The new font parameters are added after the call to this method.
101 * @param[in] eventData The event data pointer.
102 * @param[in] logicalModel The logical model where to add the new font description run.
103 * @param[out] startOfSelectedText Index to the first selected character.
104 * @param[out] lengthOfSelectedText Number of selected characters.
106 FontDescriptionRun& UpdateSelectionFontStyleRun( EventData* eventData,
107 LogicalModelPtr logicalModel,
108 CharacterIndex& startOfSelectedText,
109 Length& lengthOfSelectedText )
111 const bool handlesCrossed = eventData->mLeftSelectionPosition > eventData->mRightSelectionPosition;
113 // Get start and end position of selection
114 startOfSelectedText = handlesCrossed ? eventData->mRightSelectionPosition : eventData->mLeftSelectionPosition;
115 lengthOfSelectedText = ( handlesCrossed ? eventData->mLeftSelectionPosition : eventData->mRightSelectionPosition ) - startOfSelectedText;
118 const VectorBase::SizeType numberOfRuns = logicalModel->mFontDescriptionRuns.Count();
119 logicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
121 FontDescriptionRun& fontDescriptionRun = *( logicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
123 fontDescriptionRun.characterRun.characterIndex = startOfSelectedText;
124 fontDescriptionRun.characterRun.numberOfCharacters = lengthOfSelectedText;
126 // Recalculate the selection highlight as the metrics may have changed.
127 eventData->mUpdateLeftSelectionPosition = true;
128 eventData->mUpdateRightSelectionPosition = true;
129 eventData->mUpdateHighlightBox = true;
131 return fontDescriptionRun;
134 // public : Constructor.
136 ControllerPtr Controller::New()
138 return ControllerPtr( new Controller() );
141 ControllerPtr Controller::New( ControlInterface* controlInterface )
143 return ControllerPtr( new Controller( controlInterface ) );
146 ControllerPtr Controller::New( ControlInterface* controlInterface,
147 EditableControlInterface* editableControlInterface )
149 return ControllerPtr( new Controller( controlInterface,
150 editableControlInterface ) );
153 // public : Configure the text controller.
155 void Controller::EnableTextInput( DecoratorPtr decorator, InputMethodContext& inputMethodContext )
159 delete mImpl->mEventData;
160 mImpl->mEventData = NULL;
162 // Nothing else to do.
166 if( NULL == mImpl->mEventData )
168 mImpl->mEventData = new EventData( decorator, inputMethodContext );
172 void Controller::SetGlyphType( TextAbstraction::GlyphType glyphType )
174 // Metrics for bitmap & vector based glyphs are different
175 mImpl->mMetrics->SetGlyphType( glyphType );
177 // Clear the font-specific data
180 mImpl->RequestRelayout();
183 void Controller::SetMarkupProcessorEnabled( bool enable )
185 if( enable != mImpl->mMarkupProcessorEnabled )
187 //If Text was already set, call the SetText again for enabling or disabling markup
188 mImpl->mMarkupProcessorEnabled = enable;
195 bool Controller::IsMarkupProcessorEnabled() const
197 return mImpl->mMarkupProcessorEnabled;
200 void Controller::SetAutoScrollEnabled( bool enable )
202 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 );
204 if( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX )
208 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled for SINGLE_LINE_BOX\n" );
209 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
219 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled Disabling autoscroll\n");
220 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
227 mImpl->mIsAutoScrollEnabled = enable;
228 mImpl->RequestRelayout();
232 DALI_LOG_WARNING( "Attempted AutoScrolling on a non SINGLE_LINE_BOX, request ignored\n" );
233 mImpl->mIsAutoScrollEnabled = false;
237 bool Controller::IsAutoScrollEnabled() const
239 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::IsAutoScrollEnabled[%s]\n", mImpl->mIsAutoScrollEnabled?"true":"false" );
241 return mImpl->mIsAutoScrollEnabled;
244 CharacterDirection Controller::GetAutoScrollDirection() const
246 return mImpl->mIsTextDirectionRTL;
249 float Controller::GetAutoScrollLineAlignment() const
253 if( mImpl->mModel->mVisualModel &&
254 ( 0u != mImpl->mModel->mVisualModel->mLines.Count() ) )
256 offset = ( *mImpl->mModel->mVisualModel->mLines.Begin() ).alignmentOffset;
262 void Controller::SetHorizontalScrollEnabled( bool enable )
264 if( ( NULL != mImpl->mEventData ) &&
265 mImpl->mEventData->mDecorator )
267 mImpl->mEventData->mDecorator->SetHorizontalScrollEnabled( enable );
270 bool Controller::IsHorizontalScrollEnabled() const
272 if( ( NULL != mImpl->mEventData ) &&
273 mImpl->mEventData->mDecorator )
275 return mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
281 void Controller::SetVerticalScrollEnabled( bool enable )
283 if( ( NULL != mImpl->mEventData ) &&
284 mImpl->mEventData->mDecorator )
286 if( mImpl->mEventData->mDecorator )
288 mImpl->mEventData->mDecorator->SetVerticalScrollEnabled( enable );
293 bool Controller::IsVerticalScrollEnabled() const
295 if( ( NULL != mImpl->mEventData ) &&
296 mImpl->mEventData->mDecorator )
298 return mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
304 void Controller::SetSmoothHandlePanEnabled( bool enable )
306 if( ( NULL != mImpl->mEventData ) &&
307 mImpl->mEventData->mDecorator )
309 mImpl->mEventData->mDecorator->SetSmoothHandlePanEnabled( enable );
313 bool Controller::IsSmoothHandlePanEnabled() const
315 if( ( NULL != mImpl->mEventData ) &&
316 mImpl->mEventData->mDecorator )
318 return mImpl->mEventData->mDecorator->IsSmoothHandlePanEnabled();
324 void Controller::SetMaximumNumberOfCharacters( Length maxCharacters )
326 mImpl->mMaximumNumberOfCharacters = std::min( maxCharacters, MAX_TEXT_LENGTH );
329 int Controller::GetMaximumNumberOfCharacters()
331 return mImpl->mMaximumNumberOfCharacters;
334 void Controller::SetEnableCursorBlink( bool enable )
336 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "TextInput disabled" );
338 if( NULL != mImpl->mEventData )
340 mImpl->mEventData->mCursorBlinkEnabled = enable;
343 mImpl->mEventData->mDecorator )
345 mImpl->mEventData->mDecorator->StopCursorBlink();
350 bool Controller::GetEnableCursorBlink() const
352 if( NULL != mImpl->mEventData )
354 return mImpl->mEventData->mCursorBlinkEnabled;
360 void Controller::SetMultiLineEnabled( bool enable )
362 const Layout::Engine::Type layout = enable ? Layout::Engine::MULTI_LINE_BOX : Layout::Engine::SINGLE_LINE_BOX;
364 if( layout != mImpl->mLayoutEngine.GetLayout() )
366 // Set the layout type.
367 mImpl->mLayoutEngine.SetLayout( layout );
369 // Set the flags to redo the layout operations
370 const OperationsMask layoutOperations = static_cast<OperationsMask>( LAYOUT |
375 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
376 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | layoutOperations );
378 // Need to recalculate natural size
379 mImpl->mRecalculateNaturalSize = true;
381 mImpl->RequestRelayout();
385 bool Controller::IsMultiLineEnabled() const
387 return Layout::Engine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
390 void Controller::SetHorizontalAlignment( Text::HorizontalAlignment::Type alignment )
392 if( alignment != mImpl->mModel->mHorizontalAlignment )
394 // Set the alignment.
395 mImpl->mModel->mHorizontalAlignment = alignment;
397 // Set the flag to redo the alignment operation.
398 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
400 if( mImpl->mEventData )
402 mImpl->mEventData->mUpdateAlignment = true;
404 // Update the cursor if it's in editing mode
405 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
407 mImpl->ChangeState( EventData::EDITING );
408 mImpl->mEventData->mUpdateCursorPosition = true;
412 mImpl->RequestRelayout();
416 Text::HorizontalAlignment::Type Controller::GetHorizontalAlignment() const
418 return mImpl->mModel->mHorizontalAlignment;
421 void Controller::SetVerticalAlignment( VerticalAlignment::Type alignment )
423 if( alignment != mImpl->mModel->mVerticalAlignment )
425 // Set the alignment.
426 mImpl->mModel->mVerticalAlignment = alignment;
428 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
430 mImpl->RequestRelayout();
434 VerticalAlignment::Type Controller::GetVerticalAlignment() const
436 return mImpl->mModel->mVerticalAlignment;
439 bool Controller::IsIgnoreSpacesAfterText() const
441 return mImpl->mModel->mIgnoreSpacesAfterText;
444 void Controller::SetIgnoreSpacesAfterText( bool ignore )
446 mImpl->mModel->mIgnoreSpacesAfterText = ignore;
449 bool Controller::IsMatchSystemLanguageDirection() const
451 return mImpl->mModel->mMatchSystemLanguageDirection;
454 void Controller::SetMatchSystemLanguageDirection( bool match )
456 mImpl->mModel->mMatchSystemLanguageDirection = match;
459 void Controller::SetLayoutDirection( Dali::LayoutDirection::Type layoutDirection )
461 mImpl->mLayoutDirection = layoutDirection;
464 bool Controller::IsShowingRealText() const
466 return mImpl->IsShowingRealText();
470 void Controller::SetLineWrapMode( Text::LineWrap::Mode lineWrapMode )
472 if( lineWrapMode != mImpl->mModel->mLineWrapMode )
474 // Set the text wrap mode.
475 mImpl->mModel->mLineWrapMode = lineWrapMode;
478 // Update Text layout for applying wrap mode
479 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
484 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
485 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
486 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
489 mImpl->RequestRelayout();
493 Text::LineWrap::Mode Controller::GetLineWrapMode() const
495 return mImpl->mModel->mLineWrapMode;
498 void Controller::SetTextElideEnabled( bool enabled )
500 mImpl->mModel->mElideEnabled = enabled;
503 bool Controller::IsTextElideEnabled() const
505 return mImpl->mModel->mElideEnabled;
508 void Controller::SetTextFitEnabled(bool enabled)
510 mImpl->mTextFitEnabled = enabled;
513 bool Controller::IsTextFitEnabled() const
515 return mImpl->mTextFitEnabled;
518 void Controller::SetTextFitMinSize( float minSize, FontSizeType type )
524 mImpl->mTextFitMinSize = minSize;
529 mImpl->mTextFitMinSize = ConvertPixelToPint( minSize );
535 float Controller::GetTextFitMinSize() const
537 return mImpl->mTextFitMinSize;
540 void Controller::SetTextFitMaxSize( float maxSize, FontSizeType type )
546 mImpl->mTextFitMaxSize = maxSize;
551 mImpl->mTextFitMaxSize = ConvertPixelToPint( maxSize );
557 float Controller::GetTextFitMaxSize() const
559 return mImpl->mTextFitMaxSize;
562 void Controller::SetTextFitStepSize( float step, FontSizeType type )
568 mImpl->mTextFitStepSize = step;
573 mImpl->mTextFitStepSize = ConvertPixelToPint( step );
579 float Controller::GetTextFitStepSize() const
581 return mImpl->mTextFitStepSize;
584 void Controller::SetTextFitContentSize(Vector2 size)
586 mImpl->mTextFitContentSize = size;
589 Vector2 Controller::GetTextFitContentSize() const
591 return mImpl->mTextFitContentSize;
594 void Controller::SetPlaceholderTextElideEnabled( bool enabled )
596 mImpl->mEventData->mIsPlaceholderElideEnabled = enabled;
597 mImpl->mEventData->mPlaceholderEllipsisFlag = true;
599 // Update placeholder if there is no text
600 if( mImpl->IsShowingPlaceholderText() ||
601 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
603 ShowPlaceholderText();
607 bool Controller::IsPlaceholderTextElideEnabled() const
609 return mImpl->mEventData->mIsPlaceholderElideEnabled;
612 void Controller::SetSelectionEnabled( bool enabled )
614 mImpl->mEventData->mSelectionEnabled = enabled;
617 bool Controller::IsSelectionEnabled() const
619 return mImpl->mEventData->mSelectionEnabled;
622 void Controller::SetShiftSelectionEnabled( bool enabled )
624 mImpl->mEventData->mShiftSelectionFlag = enabled;
627 bool Controller::IsShiftSelectionEnabled() const
629 return mImpl->mEventData->mShiftSelectionFlag;
632 void Controller::SetGrabHandleEnabled( bool enabled )
634 mImpl->mEventData->mGrabHandleEnabled = enabled;
637 bool Controller::IsGrabHandleEnabled() const
639 return mImpl->mEventData->mGrabHandleEnabled;
642 void Controller::SetGrabHandlePopupEnabled(bool enabled)
644 mImpl->mEventData->mGrabHandlePopupEnabled = enabled;
647 bool Controller::IsGrabHandlePopupEnabled() const
649 return mImpl->mEventData->mGrabHandlePopupEnabled;
654 void Controller::SetText( const std::string& text )
656 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" );
658 // Reset keyboard as text changed
659 mImpl->ResetInputMethodContext();
661 // Remove the previously set text and style.
667 CharacterIndex lastCursorIndex = 0u;
669 if( NULL != mImpl->mEventData )
671 // If popup shown then hide it by switching to Editing state
672 if( ( EventData::SELECTING == mImpl->mEventData->mState ) ||
673 ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
674 ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) ||
675 ( EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState ) )
677 mImpl->ChangeState( EventData::EDITING );
683 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mTextColor );
685 MarkupProcessData markupProcessData( mImpl->mModel->mLogicalModel->mColorRuns,
686 mImpl->mModel->mLogicalModel->mFontDescriptionRuns,
687 mImpl->mModel->mLogicalModel->mEmbeddedItems );
689 Length textSize = 0u;
690 const uint8_t* utf8 = NULL;
691 if( mImpl->mMarkupProcessorEnabled )
693 ProcessMarkupString( text, markupProcessData );
694 textSize = markupProcessData.markupProcessedText.size();
696 // This is a bit horrible but std::string returns a (signed) char*
697 utf8 = reinterpret_cast<const uint8_t*>( markupProcessData.markupProcessedText.c_str() );
701 textSize = text.size();
703 // This is a bit horrible but std::string returns a (signed) char*
704 utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
707 // Limit the text size. If the text size is too large, crash or deadlock will occur.
708 if( textSize > MAX_TEXT_LENGTH )
710 DALI_LOG_WARNING( "The text size is too large(%d), limit the length to 32,768u\n", textSize );
711 textSize = MAX_TEXT_LENGTH;
714 // Convert text into UTF-32
715 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
716 utf32Characters.Resize( textSize );
718 // Transform a text array encoded in utf8 into an array encoded in utf32.
719 // It returns the actual number of characters.
720 Length characterCount = Utf8ToUtf32( utf8, textSize, utf32Characters.Begin() );
721 utf32Characters.Resize( characterCount );
723 DALI_ASSERT_DEBUG( textSize >= characterCount && "Invalid UTF32 conversion length" );
724 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", this, textSize, mImpl->mModel->mLogicalModel->mText.Count() );
726 // The characters to be added.
727 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
729 // To reset the cursor position
730 lastCursorIndex = characterCount;
732 // Update the rest of the model during size negotiation
733 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
735 // The natural size needs to be re-calculated.
736 mImpl->mRecalculateNaturalSize = true;
738 // The text direction needs to be updated.
739 mImpl->mUpdateTextDirection = true;
741 // Apply modifications to the model
742 mImpl->mOperationsPending = ALL_OPERATIONS;
746 ShowPlaceholderText();
749 // Resets the cursor position.
750 ResetCursorPosition( lastCursorIndex );
752 // Scrolls the text to make the cursor visible.
753 ResetScrollPosition();
755 mImpl->RequestRelayout();
757 if( NULL != mImpl->mEventData )
759 // Cancel previously queued events
760 mImpl->mEventData->mEventQueue.clear();
763 // Do this last since it provides callbacks into application code.
764 if( NULL != mImpl->mEditableControlInterface )
766 mImpl->mEditableControlInterface->TextChanged();
770 void Controller::GetText( std::string& text ) const
772 if( !mImpl->IsShowingPlaceholderText() )
774 // Retrieves the text string.
775 mImpl->GetText( 0u, text );
779 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this );
783 void Controller::SetPlaceholderText( PlaceholderType type, const std::string& text )
785 if( NULL != mImpl->mEventData )
787 if( PLACEHOLDER_TYPE_INACTIVE == type )
789 mImpl->mEventData->mPlaceholderTextInactive = text;
793 mImpl->mEventData->mPlaceholderTextActive = text;
796 // Update placeholder if there is no text
797 if( mImpl->IsShowingPlaceholderText() ||
798 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
800 ShowPlaceholderText();
805 void Controller::GetPlaceholderText( PlaceholderType type, std::string& text ) const
807 if( NULL != mImpl->mEventData )
809 if( PLACEHOLDER_TYPE_INACTIVE == type )
811 text = mImpl->mEventData->mPlaceholderTextInactive;
815 text = mImpl->mEventData->mPlaceholderTextActive;
820 void Controller::UpdateAfterFontChange( const std::string& newDefaultFont )
822 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
824 if( !mImpl->mFontDefaults->familyDefined ) // If user defined font then should not update when system font changes
826 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
827 mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
831 mImpl->RequestRelayout();
835 // public : Default style & Input style
837 void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
839 if( NULL == mImpl->mFontDefaults )
841 mImpl->mFontDefaults = new FontDefaults();
844 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
845 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
846 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
848 // Clear the font-specific data
851 mImpl->RequestRelayout();
854 const std::string& Controller::GetDefaultFontFamily() const
856 if( NULL != mImpl->mFontDefaults )
858 return mImpl->mFontDefaults->mFontDescription.family;
864 void Controller::SetPlaceholderFontFamily( const std::string& placeholderTextFontFamily )
866 if( NULL != mImpl->mEventData )
868 if( NULL == mImpl->mEventData->mPlaceholderFont )
870 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
873 mImpl->mEventData->mPlaceholderFont->mFontDescription.family = placeholderTextFontFamily;
874 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetPlaceholderFontFamily %s\n", placeholderTextFontFamily.c_str());
875 mImpl->mEventData->mPlaceholderFont->familyDefined = !placeholderTextFontFamily.empty();
877 mImpl->RequestRelayout();
881 const std::string& Controller::GetPlaceholderFontFamily() const
883 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
885 return mImpl->mEventData->mPlaceholderFont->mFontDescription.family;
891 void Controller::SetDefaultFontWeight( FontWeight weight )
893 if( NULL == mImpl->mFontDefaults )
895 mImpl->mFontDefaults = new FontDefaults();
898 mImpl->mFontDefaults->mFontDescription.weight = weight;
899 mImpl->mFontDefaults->weightDefined = true;
901 // Clear the font-specific data
904 mImpl->RequestRelayout();
907 bool Controller::IsDefaultFontWeightDefined() const
909 if( NULL != mImpl->mFontDefaults )
911 return mImpl->mFontDefaults->weightDefined;
917 FontWeight Controller::GetDefaultFontWeight() const
919 if( NULL != mImpl->mFontDefaults )
921 return mImpl->mFontDefaults->mFontDescription.weight;
924 return TextAbstraction::FontWeight::NORMAL;
927 void Controller::SetPlaceholderTextFontWeight( FontWeight weight )
929 if( NULL != mImpl->mEventData )
931 if( NULL == mImpl->mEventData->mPlaceholderFont )
933 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
936 mImpl->mEventData->mPlaceholderFont->mFontDescription.weight = weight;
937 mImpl->mEventData->mPlaceholderFont->weightDefined = true;
939 mImpl->RequestRelayout();
943 bool Controller::IsPlaceholderTextFontWeightDefined() const
945 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
947 return mImpl->mEventData->mPlaceholderFont->weightDefined;
952 FontWeight Controller::GetPlaceholderTextFontWeight() const
954 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
956 return mImpl->mEventData->mPlaceholderFont->mFontDescription.weight;
959 return TextAbstraction::FontWeight::NORMAL;
962 void Controller::SetDefaultFontWidth( FontWidth width )
964 if( NULL == mImpl->mFontDefaults )
966 mImpl->mFontDefaults = new FontDefaults();
969 mImpl->mFontDefaults->mFontDescription.width = width;
970 mImpl->mFontDefaults->widthDefined = true;
972 // Clear the font-specific data
975 mImpl->RequestRelayout();
978 bool Controller::IsDefaultFontWidthDefined() const
980 if( NULL != mImpl->mFontDefaults )
982 return mImpl->mFontDefaults->widthDefined;
988 FontWidth Controller::GetDefaultFontWidth() const
990 if( NULL != mImpl->mFontDefaults )
992 return mImpl->mFontDefaults->mFontDescription.width;
995 return TextAbstraction::FontWidth::NORMAL;
998 void Controller::SetPlaceholderTextFontWidth( FontWidth width )
1000 if( NULL != mImpl->mEventData )
1002 if( NULL == mImpl->mEventData->mPlaceholderFont )
1004 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
1007 mImpl->mEventData->mPlaceholderFont->mFontDescription.width = width;
1008 mImpl->mEventData->mPlaceholderFont->widthDefined = true;
1010 mImpl->RequestRelayout();
1014 bool Controller::IsPlaceholderTextFontWidthDefined() const
1016 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1018 return mImpl->mEventData->mPlaceholderFont->widthDefined;
1023 FontWidth Controller::GetPlaceholderTextFontWidth() const
1025 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1027 return mImpl->mEventData->mPlaceholderFont->mFontDescription.width;
1030 return TextAbstraction::FontWidth::NORMAL;
1033 void Controller::SetDefaultFontSlant( FontSlant slant )
1035 if( NULL == mImpl->mFontDefaults )
1037 mImpl->mFontDefaults = new FontDefaults();
1040 mImpl->mFontDefaults->mFontDescription.slant = slant;
1041 mImpl->mFontDefaults->slantDefined = true;
1043 // Clear the font-specific data
1046 mImpl->RequestRelayout();
1049 bool Controller::IsDefaultFontSlantDefined() const
1051 if( NULL != mImpl->mFontDefaults )
1053 return mImpl->mFontDefaults->slantDefined;
1058 FontSlant Controller::GetDefaultFontSlant() const
1060 if( NULL != mImpl->mFontDefaults )
1062 return mImpl->mFontDefaults->mFontDescription.slant;
1065 return TextAbstraction::FontSlant::NORMAL;
1068 void Controller::SetPlaceholderTextFontSlant( FontSlant slant )
1070 if( NULL != mImpl->mEventData )
1072 if( NULL == mImpl->mEventData->mPlaceholderFont )
1074 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
1077 mImpl->mEventData->mPlaceholderFont->mFontDescription.slant = slant;
1078 mImpl->mEventData->mPlaceholderFont->slantDefined = true;
1080 mImpl->RequestRelayout();
1084 bool Controller::IsPlaceholderTextFontSlantDefined() const
1086 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1088 return mImpl->mEventData->mPlaceholderFont->slantDefined;
1093 FontSlant Controller::GetPlaceholderTextFontSlant() const
1095 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1097 return mImpl->mEventData->mPlaceholderFont->mFontDescription.slant;
1100 return TextAbstraction::FontSlant::NORMAL;
1103 void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
1105 if( NULL == mImpl->mFontDefaults )
1107 mImpl->mFontDefaults = new FontDefaults();
1114 mImpl->mFontDefaults->mDefaultPointSize = fontSize;
1115 mImpl->mFontDefaults->sizeDefined = true;
1120 // Point size = Pixel size * 72.f / DPI
1121 unsigned int horizontalDpi = 0u;
1122 unsigned int verticalDpi = 0u;
1123 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1124 fontClient.GetDpi( horizontalDpi, verticalDpi );
1126 mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
1127 mImpl->mFontDefaults->sizeDefined = true;
1132 // Clear the font-specific data
1135 mImpl->RequestRelayout();
1138 float Controller::GetDefaultFontSize( FontSizeType type ) const
1141 if( NULL != mImpl->mFontDefaults )
1147 value = mImpl->mFontDefaults->mDefaultPointSize;
1152 // Pixel size = Point size * DPI / 72.f
1153 unsigned int horizontalDpi = 0u;
1154 unsigned int verticalDpi = 0u;
1155 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1156 fontClient.GetDpi( horizontalDpi, verticalDpi );
1158 value = mImpl->mFontDefaults->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1168 void Controller::SetPlaceholderTextFontSize( float fontSize, FontSizeType type )
1170 if( NULL != mImpl->mEventData )
1172 if( NULL == mImpl->mEventData->mPlaceholderFont )
1174 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
1181 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = fontSize;
1182 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1183 mImpl->mEventData->mIsPlaceholderPixelSize = false; // Font size flag
1188 // Point size = Pixel size * 72.f / DPI
1189 unsigned int horizontalDpi = 0u;
1190 unsigned int verticalDpi = 0u;
1191 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1192 fontClient.GetDpi( horizontalDpi, verticalDpi );
1194 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
1195 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1196 mImpl->mEventData->mIsPlaceholderPixelSize = true; // Font size flag
1201 mImpl->RequestRelayout();
1205 float Controller::GetPlaceholderTextFontSize( FontSizeType type ) const
1208 if( NULL != mImpl->mEventData )
1214 if( NULL != mImpl->mEventData->mPlaceholderFont )
1216 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize;
1220 // If the placeholder text font size is not set, then return the default font size.
1221 value = GetDefaultFontSize( POINT_SIZE );
1227 if( NULL != mImpl->mEventData->mPlaceholderFont )
1229 // Pixel size = Point size * DPI / 72.f
1230 unsigned int horizontalDpi = 0u;
1231 unsigned int verticalDpi = 0u;
1232 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1233 fontClient.GetDpi( horizontalDpi, verticalDpi );
1235 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1239 // If the placeholder text font size is not set, then return the default font size.
1240 value = GetDefaultFontSize( PIXEL_SIZE );
1251 void Controller::SetDefaultColor( const Vector4& color )
1253 mImpl->mTextColor = color;
1255 if( !mImpl->IsShowingPlaceholderText() )
1257 mImpl->mModel->mVisualModel->SetTextColor( color );
1259 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
1261 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1263 mImpl->RequestRelayout();
1267 const Vector4& Controller::GetDefaultColor() const
1269 return mImpl->mTextColor;
1272 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
1274 if( NULL != mImpl->mEventData )
1276 mImpl->mEventData->mPlaceholderTextColor = textColor;
1279 if( mImpl->IsShowingPlaceholderText() )
1281 mImpl->mModel->mVisualModel->SetTextColor( textColor );
1282 mImpl->RequestRelayout();
1286 const Vector4& Controller::GetPlaceholderTextColor() const
1288 if( NULL != mImpl->mEventData )
1290 return mImpl->mEventData->mPlaceholderTextColor;
1293 return Color::BLACK;
1296 void Controller::SetShadowOffset( const Vector2& shadowOffset )
1298 mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
1300 mImpl->RequestRelayout();
1303 const Vector2& Controller::GetShadowOffset() const
1305 return mImpl->mModel->mVisualModel->GetShadowOffset();
1308 void Controller::SetShadowColor( const Vector4& shadowColor )
1310 mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
1312 mImpl->RequestRelayout();
1315 const Vector4& Controller::GetShadowColor() const
1317 return mImpl->mModel->mVisualModel->GetShadowColor();
1320 void Controller::SetShadowBlurRadius( const float& shadowBlurRadius )
1322 if ( fabsf( GetShadowBlurRadius() - shadowBlurRadius ) > Math::MACHINE_EPSILON_1 )
1324 mImpl->mModel->mVisualModel->SetShadowBlurRadius( shadowBlurRadius );
1326 mImpl->RequestRelayout();
1330 const float& Controller::GetShadowBlurRadius() const
1332 return mImpl->mModel->mVisualModel->GetShadowBlurRadius();
1335 void Controller::SetUnderlineColor( const Vector4& color )
1337 mImpl->mModel->mVisualModel->SetUnderlineColor( color );
1339 mImpl->RequestRelayout();
1342 const Vector4& Controller::GetUnderlineColor() const
1344 return mImpl->mModel->mVisualModel->GetUnderlineColor();
1347 void Controller::SetUnderlineEnabled( bool enabled )
1349 mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
1351 mImpl->RequestRelayout();
1354 bool Controller::IsUnderlineEnabled() const
1356 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
1359 void Controller::SetUnderlineHeight( float height )
1361 mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
1363 mImpl->RequestRelayout();
1366 float Controller::GetUnderlineHeight() const
1368 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
1371 void Controller::SetOutlineColor( const Vector4& color )
1373 mImpl->mModel->mVisualModel->SetOutlineColor( color );
1375 mImpl->RequestRelayout();
1378 const Vector4& Controller::GetOutlineColor() const
1380 return mImpl->mModel->mVisualModel->GetOutlineColor();
1383 void Controller::SetOutlineWidth( uint16_t width )
1385 mImpl->mModel->mVisualModel->SetOutlineWidth( width );
1387 mImpl->RequestRelayout();
1390 uint16_t Controller::GetOutlineWidth() const
1392 return mImpl->mModel->mVisualModel->GetOutlineWidth();
1395 void Controller::SetBackgroundColor( const Vector4& color )
1397 mImpl->mModel->mVisualModel->SetBackgroundColor( color );
1399 mImpl->RequestRelayout();
1402 const Vector4& Controller::GetBackgroundColor() const
1404 return mImpl->mModel->mVisualModel->GetBackgroundColor();
1407 void Controller::SetBackgroundEnabled( bool enabled )
1409 mImpl->mModel->mVisualModel->SetBackgroundEnabled( enabled );
1411 mImpl->RequestRelayout();
1414 bool Controller::IsBackgroundEnabled() const
1416 return mImpl->mModel->mVisualModel->IsBackgroundEnabled();
1419 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
1421 if( NULL == mImpl->mEmbossDefaults )
1423 mImpl->mEmbossDefaults = new EmbossDefaults();
1426 mImpl->mEmbossDefaults->properties = embossProperties;
1429 const std::string& Controller::GetDefaultEmbossProperties() const
1431 if( NULL != mImpl->mEmbossDefaults )
1433 return mImpl->mEmbossDefaults->properties;
1436 return EMPTY_STRING;
1439 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
1441 if( NULL == mImpl->mOutlineDefaults )
1443 mImpl->mOutlineDefaults = new OutlineDefaults();
1446 mImpl->mOutlineDefaults->properties = outlineProperties;
1449 const std::string& Controller::GetDefaultOutlineProperties() const
1451 if( NULL != mImpl->mOutlineDefaults )
1453 return mImpl->mOutlineDefaults->properties;
1456 return EMPTY_STRING;
1459 bool Controller::SetDefaultLineSpacing( float lineSpacing )
1461 if( std::fabs( lineSpacing - mImpl->mLayoutEngine.GetDefaultLineSpacing() ) > Math::MACHINE_EPSILON_1000 )
1463 mImpl->mLayoutEngine.SetDefaultLineSpacing(lineSpacing);
1464 mImpl->mRecalculateNaturalSize = true;
1470 float Controller::GetDefaultLineSpacing() const
1472 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
1475 void Controller::SetInputColor( const Vector4& color )
1477 if( NULL != mImpl->mEventData )
1479 mImpl->mEventData->mInputStyle.textColor = color;
1480 mImpl->mEventData->mInputStyle.isDefaultColor = false;
1482 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1484 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
1486 // Get start and end position of selection
1487 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
1488 const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
1490 // Add the color run.
1491 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1492 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
1494 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
1495 colorRun.color = color;
1496 colorRun.characterRun.characterIndex = startOfSelectedText;
1497 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1499 // Request to relayout.
1500 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1501 mImpl->RequestRelayout();
1503 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1504 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1505 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1510 const Vector4& Controller::GetInputColor() const
1512 if( NULL != mImpl->mEventData )
1514 return mImpl->mEventData->mInputStyle.textColor;
1517 // Return the default text's color if there is no EventData.
1518 return mImpl->mTextColor;
1522 void Controller::SetInputFontFamily( const std::string& fontFamily )
1524 if( NULL != mImpl->mEventData )
1526 mImpl->mEventData->mInputStyle.familyName = fontFamily;
1527 mImpl->mEventData->mInputStyle.isFamilyDefined = true;
1529 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1531 CharacterIndex startOfSelectedText = 0u;
1532 Length lengthOfSelectedText = 0u;
1533 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1534 mImpl->mModel->mLogicalModel,
1535 startOfSelectedText,
1536 lengthOfSelectedText );
1538 fontDescriptionRun.familyLength = fontFamily.size();
1539 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
1540 memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength );
1541 fontDescriptionRun.familyDefined = true;
1543 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
1545 // Request to relayout.
1546 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1551 UPDATE_LAYOUT_SIZE |
1554 mImpl->mRecalculateNaturalSize = true;
1555 mImpl->RequestRelayout();
1557 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1558 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1559 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1561 // As the font changes, recalculate the handle positions is needed.
1562 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1563 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1564 mImpl->mEventData->mUpdateHighlightBox = true;
1565 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1570 const std::string& Controller::GetInputFontFamily() const
1572 if( NULL != mImpl->mEventData )
1574 return mImpl->mEventData->mInputStyle.familyName;
1577 // Return the default font's family if there is no EventData.
1578 return GetDefaultFontFamily();
1581 void Controller::SetInputFontWeight( FontWeight weight )
1583 if( NULL != mImpl->mEventData )
1585 mImpl->mEventData->mInputStyle.weight = weight;
1586 mImpl->mEventData->mInputStyle.isWeightDefined = true;
1588 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1590 CharacterIndex startOfSelectedText = 0u;
1591 Length lengthOfSelectedText = 0u;
1592 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1593 mImpl->mModel->mLogicalModel,
1594 startOfSelectedText,
1595 lengthOfSelectedText );
1597 fontDescriptionRun.weight = weight;
1598 fontDescriptionRun.weightDefined = true;
1600 // Request to relayout.
1601 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1606 UPDATE_LAYOUT_SIZE |
1609 mImpl->mRecalculateNaturalSize = true;
1610 mImpl->RequestRelayout();
1612 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1613 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1614 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1616 // As the font might change, recalculate the handle positions is needed.
1617 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1618 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1619 mImpl->mEventData->mUpdateHighlightBox = true;
1620 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1625 bool Controller::IsInputFontWeightDefined() const
1627 bool defined = false;
1629 if( NULL != mImpl->mEventData )
1631 defined = mImpl->mEventData->mInputStyle.isWeightDefined;
1637 FontWeight Controller::GetInputFontWeight() const
1639 if( NULL != mImpl->mEventData )
1641 return mImpl->mEventData->mInputStyle.weight;
1644 return GetDefaultFontWeight();
1647 void Controller::SetInputFontWidth( FontWidth width )
1649 if( NULL != mImpl->mEventData )
1651 mImpl->mEventData->mInputStyle.width = width;
1652 mImpl->mEventData->mInputStyle.isWidthDefined = true;
1654 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1656 CharacterIndex startOfSelectedText = 0u;
1657 Length lengthOfSelectedText = 0u;
1658 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1659 mImpl->mModel->mLogicalModel,
1660 startOfSelectedText,
1661 lengthOfSelectedText );
1663 fontDescriptionRun.width = width;
1664 fontDescriptionRun.widthDefined = true;
1666 // Request to relayout.
1667 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1672 UPDATE_LAYOUT_SIZE |
1675 mImpl->mRecalculateNaturalSize = true;
1676 mImpl->RequestRelayout();
1678 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1679 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1680 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1682 // As the font might change, recalculate the handle positions is needed.
1683 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1684 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1685 mImpl->mEventData->mUpdateHighlightBox = true;
1686 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1691 bool Controller::IsInputFontWidthDefined() const
1693 bool defined = false;
1695 if( NULL != mImpl->mEventData )
1697 defined = mImpl->mEventData->mInputStyle.isWidthDefined;
1703 FontWidth Controller::GetInputFontWidth() const
1705 if( NULL != mImpl->mEventData )
1707 return mImpl->mEventData->mInputStyle.width;
1710 return GetDefaultFontWidth();
1713 void Controller::SetInputFontSlant( FontSlant slant )
1715 if( NULL != mImpl->mEventData )
1717 mImpl->mEventData->mInputStyle.slant = slant;
1718 mImpl->mEventData->mInputStyle.isSlantDefined = true;
1720 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1722 CharacterIndex startOfSelectedText = 0u;
1723 Length lengthOfSelectedText = 0u;
1724 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1725 mImpl->mModel->mLogicalModel,
1726 startOfSelectedText,
1727 lengthOfSelectedText );
1729 fontDescriptionRun.slant = slant;
1730 fontDescriptionRun.slantDefined = true;
1732 // Request to relayout.
1733 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1738 UPDATE_LAYOUT_SIZE |
1741 mImpl->mRecalculateNaturalSize = true;
1742 mImpl->RequestRelayout();
1744 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1745 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1746 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1748 // As the font might change, recalculate the handle positions is needed.
1749 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1750 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1751 mImpl->mEventData->mUpdateHighlightBox = true;
1752 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1757 bool Controller::IsInputFontSlantDefined() const
1759 bool defined = false;
1761 if( NULL != mImpl->mEventData )
1763 defined = mImpl->mEventData->mInputStyle.isSlantDefined;
1769 FontSlant Controller::GetInputFontSlant() const
1771 if( NULL != mImpl->mEventData )
1773 return mImpl->mEventData->mInputStyle.slant;
1776 return GetDefaultFontSlant();
1779 void Controller::SetInputFontPointSize( float size )
1781 if( NULL != mImpl->mEventData )
1783 mImpl->mEventData->mInputStyle.size = size;
1784 mImpl->mEventData->mInputStyle.isSizeDefined = true;
1786 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1788 CharacterIndex startOfSelectedText = 0u;
1789 Length lengthOfSelectedText = 0u;
1790 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1791 mImpl->mModel->mLogicalModel,
1792 startOfSelectedText,
1793 lengthOfSelectedText );
1795 fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
1796 fontDescriptionRun.sizeDefined = true;
1798 // Request to relayout.
1799 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1804 UPDATE_LAYOUT_SIZE |
1807 mImpl->mRecalculateNaturalSize = true;
1808 mImpl->RequestRelayout();
1810 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1811 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1812 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1814 // As the font might change, recalculate the handle positions is needed.
1815 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1816 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1817 mImpl->mEventData->mUpdateHighlightBox = true;
1818 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1823 float Controller::GetInputFontPointSize() const
1825 if( NULL != mImpl->mEventData )
1827 return mImpl->mEventData->mInputStyle.size;
1830 // Return the default font's point size if there is no EventData.
1831 return GetDefaultFontSize( Text::Controller::POINT_SIZE );
1834 void Controller::SetInputLineSpacing( float lineSpacing )
1836 if( NULL != mImpl->mEventData )
1838 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1839 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1843 float Controller::GetInputLineSpacing() const
1845 if( NULL != mImpl->mEventData )
1847 return mImpl->mEventData->mInputStyle.lineSpacing;
1853 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1855 if( NULL != mImpl->mEventData )
1857 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1861 const std::string& Controller::GetInputShadowProperties() const
1863 if( NULL != mImpl->mEventData )
1865 return mImpl->mEventData->mInputStyle.shadowProperties;
1868 return EMPTY_STRING;
1871 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1873 if( NULL != mImpl->mEventData )
1875 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1879 const std::string& Controller::GetInputUnderlineProperties() const
1881 if( NULL != mImpl->mEventData )
1883 return mImpl->mEventData->mInputStyle.underlineProperties;
1886 return EMPTY_STRING;
1889 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
1891 if( NULL != mImpl->mEventData )
1893 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1897 const std::string& Controller::GetInputEmbossProperties() const
1899 if( NULL != mImpl->mEventData )
1901 return mImpl->mEventData->mInputStyle.embossProperties;
1904 return GetDefaultEmbossProperties();
1907 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
1909 if( NULL != mImpl->mEventData )
1911 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1915 const std::string& Controller::GetInputOutlineProperties() const
1917 if( NULL != mImpl->mEventData )
1919 return mImpl->mEventData->mInputStyle.outlineProperties;
1922 return GetDefaultOutlineProperties();
1925 void Controller::SetInputModePassword( bool passwordInput )
1927 if( NULL != mImpl->mEventData )
1929 mImpl->mEventData->mPasswordInput = passwordInput;
1933 bool Controller::IsInputModePassword()
1935 if( NULL != mImpl->mEventData )
1937 return mImpl->mEventData->mPasswordInput;
1942 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
1944 if( NULL != mImpl->mEventData )
1946 mImpl->mEventData->mDoubleTapAction = action;
1950 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1952 NoTextTap::Action action = NoTextTap::NO_ACTION;
1954 if( NULL != mImpl->mEventData )
1956 action = mImpl->mEventData->mDoubleTapAction;
1962 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
1964 if( NULL != mImpl->mEventData )
1966 mImpl->mEventData->mLongPressAction = action;
1970 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1972 NoTextTap::Action action = NoTextTap::NO_ACTION;
1974 if( NULL != mImpl->mEventData )
1976 action = mImpl->mEventData->mLongPressAction;
1982 bool Controller::IsUnderlineSetByString()
1984 return mImpl->mUnderlineSetByString;
1987 void Controller::UnderlineSetByString( bool setByString )
1989 mImpl->mUnderlineSetByString = setByString;
1992 bool Controller::IsShadowSetByString()
1994 return mImpl->mShadowSetByString;
1997 void Controller::ShadowSetByString( bool setByString )
1999 mImpl->mShadowSetByString = setByString;
2002 bool Controller::IsOutlineSetByString()
2004 return mImpl->mOutlineSetByString;
2007 void Controller::OutlineSetByString( bool setByString )
2009 mImpl->mOutlineSetByString = setByString;
2012 bool Controller::IsFontStyleSetByString()
2014 return mImpl->mFontStyleSetByString;
2017 void Controller::FontStyleSetByString( bool setByString )
2019 mImpl->mFontStyleSetByString = setByString;
2022 // public : Queries & retrieves.
2024 Layout::Engine& Controller::GetLayoutEngine()
2026 return mImpl->mLayoutEngine;
2029 View& Controller::GetView()
2031 return mImpl->mView;
2034 Vector3 Controller::GetNaturalSize()
2036 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
2037 Vector3 naturalSize;
2039 // Make sure the model is up-to-date before layouting
2040 ProcessModifyEvents();
2042 if( mImpl->mRecalculateNaturalSize )
2044 // Operations that can be done only once until the text changes.
2045 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2051 GET_GLYPH_METRICS );
2053 // Set the update info to relayout the whole text.
2054 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2055 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2057 // Make sure the model is up-to-date before layouting
2058 mImpl->UpdateModel( onlyOnceOperations );
2060 // Layout the text for the new width.
2061 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT | REORDER );
2063 // Store the actual control's size to restore later.
2064 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
2066 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
2067 static_cast<OperationsMask>( onlyOnceOperations |
2069 naturalSize.GetVectorXY() );
2071 // Do not do again the only once operations.
2072 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2074 // Do the size related operations again.
2075 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
2078 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
2080 // Stores the natural size to avoid recalculate it again
2081 // unless the text/style changes.
2082 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
2084 mImpl->mRecalculateNaturalSize = false;
2086 // Clear the update info. This info will be set the next time the text is updated.
2087 mImpl->mTextUpdateInfo.Clear();
2088 mImpl->mTextUpdateInfo.mClearAll = true;
2090 // Restore the actual control's size.
2091 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
2093 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
2097 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
2099 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
2102 naturalSize.x = ConvertToEven( naturalSize.x );
2103 naturalSize.y = ConvertToEven( naturalSize.y );
2108 bool Controller::CheckForTextFit( float pointSize, Size& layoutSize )
2111 mImpl->mFontDefaults->mFitPointSize = pointSize;
2112 mImpl->mFontDefaults->sizeDefined = true;
2115 // Operations that can be done only once until the text changes.
2116 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2122 GET_GLYPH_METRICS );
2124 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2125 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2127 // Make sure the model is up-to-date before layouting
2128 mImpl->UpdateModel( onlyOnceOperations );
2130 DoRelayout( Size( layoutSize.width, MAX_FLOAT ),
2131 static_cast<OperationsMask>( onlyOnceOperations | LAYOUT),
2134 // Clear the update info. This info will be set the next time the text is updated.
2135 mImpl->mTextUpdateInfo.Clear();
2136 mImpl->mTextUpdateInfo.mClearAll = true;
2138 if( textSize.width > layoutSize.width || textSize.height > layoutSize.height )
2145 void Controller::FitPointSizeforLayout( Size layoutSize )
2147 const OperationsMask operations = mImpl->mOperationsPending;
2148 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
2150 bool actualellipsis = mImpl->mModel->mElideEnabled;
2151 float minPointSize = mImpl->mTextFitMinSize;
2152 float maxPointSize = mImpl->mTextFitMaxSize;
2153 float pointInterval = mImpl->mTextFitStepSize;
2155 mImpl->mModel->mElideEnabled = false;
2156 Vector<float> pointSizeArray;
2159 if( pointInterval < 1.f )
2161 mImpl->mTextFitStepSize = pointInterval = 1.0f;
2164 pointSizeArray.Reserve( static_cast< unsigned int >( ceil( ( maxPointSize - minPointSize ) / pointInterval ) ) );
2166 for( float i = minPointSize; i < maxPointSize; i += pointInterval )
2168 pointSizeArray.PushBack( i );
2171 pointSizeArray.PushBack( maxPointSize );
2173 int bestSizeIndex = 0;
2174 int min = bestSizeIndex + 1;
2175 int max = pointSizeArray.Size() - 1;
2178 int destI = ( min + max ) / 2;
2180 if( CheckForTextFit( pointSizeArray[destI], layoutSize ) )
2182 bestSizeIndex = min;
2188 bestSizeIndex = max;
2192 mImpl->mModel->mElideEnabled = actualellipsis;
2193 mImpl->mFontDefaults->mFitPointSize = pointSizeArray[bestSizeIndex];
2194 mImpl->mFontDefaults->sizeDefined = true;
2199 float Controller::GetHeightForWidth( float width )
2201 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
2202 // Make sure the model is up-to-date before layouting
2203 ProcessModifyEvents();
2206 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ||
2207 mImpl->mTextUpdateInfo.mFullRelayoutNeeded ||
2208 mImpl->mTextUpdateInfo.mClearAll )
2210 // Operations that can be done only once until the text changes.
2211 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2217 GET_GLYPH_METRICS );
2219 // Set the update info to relayout the whole text.
2220 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2221 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2223 // Make sure the model is up-to-date before layouting
2224 mImpl->UpdateModel( onlyOnceOperations );
2227 // Layout the text for the new width.
2228 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
2230 // Store the actual control's width.
2231 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
2233 DoRelayout( Size( width, MAX_FLOAT ),
2234 static_cast<OperationsMask>( onlyOnceOperations |
2238 // Do not do again the only once operations.
2239 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2241 // Do the size related operations again.
2242 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
2246 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
2248 // Clear the update info. This info will be set the next time the text is updated.
2249 mImpl->mTextUpdateInfo.Clear();
2250 mImpl->mTextUpdateInfo.mClearAll = true;
2252 // Restore the actual control's width.
2253 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
2255 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
2259 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
2260 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
2263 return layoutSize.height;
2266 int Controller::GetLineCount( float width )
2268 GetHeightForWidth( width );
2269 int numberofLines = mImpl->mModel->GetNumberOfLines();
2270 return numberofLines;
2273 const ModelInterface* const Controller::GetTextModel() const
2275 return mImpl->mModel.Get();
2278 float Controller::GetScrollAmountByUserInput()
2280 float scrollAmount = 0.0f;
2282 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
2284 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
2285 mImpl->mEventData->mCheckScrollAmount = false;
2287 return scrollAmount;
2290 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
2292 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
2295 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
2296 layoutHeight = layout.height;
2297 scrollPosition = mImpl->mModel->mScrollPosition.y;
2298 isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
2302 void Controller::SetHiddenInputOption(const Property::Map& options )
2304 if( NULL == mImpl->mHiddenInput )
2306 mImpl->mHiddenInput = new HiddenText( this );
2308 mImpl->mHiddenInput->SetProperties(options);
2311 void Controller::GetHiddenInputOption(Property::Map& options )
2313 if( NULL != mImpl->mHiddenInput )
2315 mImpl->mHiddenInput->GetProperties(options);
2319 void Controller::SetPlaceholderProperty( const Property::Map& map )
2321 const Property::Map::SizeType count = map.Count();
2323 for( Property::Map::SizeType position = 0; position < count; ++position )
2325 KeyValuePair keyValue = map.GetKeyValue( position );
2326 Property::Key& key = keyValue.first;
2327 Property::Value& value = keyValue.second;
2329 if( key == Toolkit::Text::PlaceHolder::Property::TEXT || key == PLACEHOLDER_TEXT )
2331 std::string text = "";
2333 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
2335 else if( key == Toolkit::Text::PlaceHolder::Property::TEXT_FOCUSED || key == PLACEHOLDER_TEXT_FOCUSED )
2337 std::string text = "";
2339 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
2341 else if( key == Toolkit::Text::PlaceHolder::Property::COLOR || key == PLACEHOLDER_COLOR )
2344 value.Get( textColor );
2345 if( GetPlaceholderTextColor() != textColor )
2347 SetPlaceholderTextColor( textColor );
2350 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_FAMILY || key == PLACEHOLDER_FONT_FAMILY )
2352 std::string fontFamily = "";
2353 value.Get( fontFamily );
2354 SetPlaceholderFontFamily( fontFamily );
2356 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_STYLE || key == PLACEHOLDER_FONT_STYLE )
2358 SetFontStyleProperty( this, value, Text::FontStyle::PLACEHOLDER );
2360 else if( key == Toolkit::Text::PlaceHolder::Property::POINT_SIZE || key == PLACEHOLDER_POINT_SIZE )
2363 value.Get( pointSize );
2364 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
2366 SetPlaceholderTextFontSize( pointSize, Text::Controller::POINT_SIZE );
2369 else if( key == Toolkit::Text::PlaceHolder::Property::PIXEL_SIZE || key == PLACEHOLDER_PIXEL_SIZE )
2372 value.Get( pixelSize );
2373 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
2375 SetPlaceholderTextFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
2378 else if( key == Toolkit::Text::PlaceHolder::Property::ELLIPSIS || key == PLACEHOLDER_ELLIPSIS )
2381 value.Get( ellipsis );
2382 SetPlaceholderTextElideEnabled( ellipsis );
2387 void Controller::GetPlaceholderProperty( Property::Map& map )
2389 if( NULL != mImpl->mEventData )
2391 if( !mImpl->mEventData->mPlaceholderTextActive.empty() )
2393 map[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = mImpl->mEventData->mPlaceholderTextActive;
2395 if( !mImpl->mEventData->mPlaceholderTextInactive.empty() )
2397 map[ Text::PlaceHolder::Property::TEXT ] = mImpl->mEventData->mPlaceholderTextInactive;
2400 map[ Text::PlaceHolder::Property::COLOR ] = mImpl->mEventData->mPlaceholderTextColor;
2401 map[ Text::PlaceHolder::Property::FONT_FAMILY ] = GetPlaceholderFontFamily();
2403 Property::Value fontStyleMapGet;
2404 GetFontStyleProperty( this, fontStyleMapGet, Text::FontStyle::PLACEHOLDER );
2405 map[ Text::PlaceHolder::Property::FONT_STYLE ] = fontStyleMapGet;
2407 // Choose font size : POINT_SIZE or PIXEL_SIZE
2408 if( !mImpl->mEventData->mIsPlaceholderPixelSize )
2410 map[ Text::PlaceHolder::Property::POINT_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE );
2414 map[ Text::PlaceHolder::Property::PIXEL_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE );
2417 if( mImpl->mEventData->mPlaceholderEllipsisFlag )
2419 map[ Text::PlaceHolder::Property::ELLIPSIS ] = IsPlaceholderTextElideEnabled();
2424 Toolkit::DevelText::TextDirection::Type Controller::GetTextDirection()
2426 // Make sure the model is up-to-date before layouting
2427 ProcessModifyEvents();
2429 if ( mImpl->mUpdateTextDirection )
2431 // Operations that can be done only once until the text changes.
2432 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2438 GET_GLYPH_METRICS );
2440 // Set the update info to relayout the whole text.
2441 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2442 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2444 // Make sure the model is up-to-date before layouting
2445 mImpl->UpdateModel( onlyOnceOperations );
2447 Vector3 naturalSize;
2448 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
2449 static_cast<OperationsMask>( onlyOnceOperations |
2450 LAYOUT | REORDER | UPDATE_DIRECTION ),
2451 naturalSize.GetVectorXY() );
2453 // Do not do again the only once operations.
2454 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2456 // Clear the update info. This info will be set the next time the text is updated.
2457 mImpl->mTextUpdateInfo.Clear();
2459 // FullRelayoutNeeded should be true because DoRelayout is MAX_FLOAT, MAX_FLOAT.
2460 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2462 mImpl->mUpdateTextDirection = false;
2465 return mImpl->mIsTextDirectionRTL ? Toolkit::DevelText::TextDirection::RIGHT_TO_LEFT : Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT;
2468 Toolkit::DevelText::VerticalLineAlignment::Type Controller::GetVerticalLineAlignment() const
2470 return mImpl->mModel->GetVerticalLineAlignment();
2473 void Controller::SetVerticalLineAlignment( Toolkit::DevelText::VerticalLineAlignment::Type alignment )
2475 mImpl->mModel->mVerticalLineAlignment = alignment;
2478 // public : Relayout.
2480 Controller::UpdateTextType Controller::Relayout( const Size& size )
2482 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
2484 UpdateTextType updateTextType = NONE_UPDATED;
2486 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
2488 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
2490 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
2491 updateTextType = MODEL_UPDATED;
2494 // Clear the update info. This info will be set the next time the text is updated.
2495 mImpl->mTextUpdateInfo.Clear();
2497 // Not worth to relayout if width or height is equal to zero.
2498 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
2500 return updateTextType;
2503 // Whether a new size has been set.
2504 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
2508 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
2510 if( ( 0 == mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd ) &&
2511 ( 0 == mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) &&
2512 ( ( mImpl->mModel->mVisualModel->mControlSize.width < Math::MACHINE_EPSILON_1000 ) || ( mImpl->mModel->mVisualModel->mControlSize.height < Math::MACHINE_EPSILON_1000 ) ) )
2514 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
2517 // Layout operations that need to be done if the size changes.
2518 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2521 UPDATE_LAYOUT_SIZE |
2523 // Set the update info to relayout the whole text.
2524 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2525 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2527 // Store the size used to layout the text.
2528 mImpl->mModel->mVisualModel->mControlSize = size;
2531 // Whether there are modify events.
2532 if( 0u != mImpl->mModifyEvents.Count() )
2534 // Style operations that need to be done if the text is modified.
2535 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2539 // Set the update info to elide the text.
2540 if( mImpl->mModel->mElideEnabled ||
2541 ( ( NULL != mImpl->mEventData ) && mImpl->mEventData->mIsPlaceholderElideEnabled ) )
2543 // Update Text layout for applying elided
2544 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2547 UPDATE_LAYOUT_SIZE |
2549 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2550 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2553 if( mImpl->mModel->mMatchSystemLanguageDirection )
2555 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( Dali::Stage::GetCurrent().GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
2557 if( mImpl->mLayoutDirection != layoutDirection )
2559 // Clear the update info. This info will be set the next time the text is updated.
2560 mImpl->mTextUpdateInfo.mClearAll = true;
2561 // Apply modifications to the model
2562 // Shape the text again is needed because characters like '()[]{}' have to be mirrored and the glyphs generated again.
2563 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2570 mImpl->mLayoutDirection = layoutDirection;
2574 // Make sure the model is up-to-date before layouting.
2575 ProcessModifyEvents();
2576 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
2580 updated = DoRelayout( size,
2581 mImpl->mOperationsPending,
2582 layoutSize ) || updated;
2587 updateTextType = MODEL_UPDATED;
2590 // Do not re-do any operation until something changes.
2591 mImpl->mOperationsPending = NO_OPERATION;
2592 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
2594 // Whether the text control is editable
2595 const bool isEditable = NULL != mImpl->mEventData;
2597 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
2599 if( newSize && isEditable )
2601 offset = mImpl->mModel->mScrollPosition;
2604 if( !isEditable || !IsMultiLineEnabled() )
2606 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
2607 CalculateVerticalOffset( size );
2614 // If there is a new size, the scroll position needs to be clamped.
2615 mImpl->ClampHorizontalScroll( layoutSize );
2617 // Update the decorator's positions is needed if there is a new size.
2618 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
2621 // Move the cursor, grab handle etc.
2622 if( mImpl->ProcessInputEvents() )
2624 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
2628 // Clear the update info. This info will be set the next time the text is updated.
2629 mImpl->mTextUpdateInfo.Clear();
2630 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
2632 return updateTextType;
2635 void Controller::RequestRelayout()
2637 mImpl->RequestRelayout();
2640 // public : Input style change signals.
2642 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
2644 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
2647 void Controller::ProcessInputStyleChangedSignals()
2649 if( NULL == mImpl->mEventData )
2655 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
2656 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
2660 const InputStyle::Mask mask = *it;
2662 if( NULL != mImpl->mEditableControlInterface )
2664 // Emit the input style changed signal.
2665 mImpl->mEditableControlInterface->InputStyleChanged( mask );
2669 mImpl->mEventData->mInputStyleChangedQueue.Clear();
2672 // public : Text-input Event Queuing.
2674 void Controller::KeyboardFocusGainEvent()
2676 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
2678 if( NULL != mImpl->mEventData )
2680 if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
2681 ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
2683 mImpl->ChangeState( EventData::EDITING );
2684 mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
2685 mImpl->mEventData->mUpdateInputStyle = true;
2686 mImpl->mEventData->mScrollAfterUpdatePosition = true;
2688 mImpl->NotifyInputMethodContextMultiLineStatus();
2689 if( mImpl->IsShowingPlaceholderText() )
2691 // Show alternative placeholder-text when editing
2692 ShowPlaceholderText();
2695 mImpl->RequestRelayout();
2699 void Controller::KeyboardFocusLostEvent()
2701 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
2703 if( NULL != mImpl->mEventData )
2705 if( EventData::INTERRUPTED != mImpl->mEventData->mState )
2707 mImpl->ChangeState( EventData::INACTIVE );
2709 if( !mImpl->IsShowingRealText() )
2711 // Revert to regular placeholder-text when not editing
2712 ShowPlaceholderText();
2716 mImpl->RequestRelayout();
2719 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
2721 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
2723 bool textChanged = false;
2724 bool relayoutNeeded = false;
2726 if( ( NULL != mImpl->mEventData ) &&
2727 ( keyEvent.state == KeyEvent::Down ) )
2729 int keyCode = keyEvent.keyCode;
2730 const std::string& keyString = keyEvent.keyPressed;
2731 const std::string keyName = keyEvent.keyPressedName;
2733 const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
2735 // Pre-process to separate modifying events from non-modifying input events.
2738 // In some platforms arrive key events with no key code.
2742 else if( Dali::DALI_KEY_ESCAPE == keyCode || Dali::DALI_KEY_BACK == keyCode || Dali::DALI_KEY_SEARCH == keyCode )
2747 else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) ||
2748 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
2749 ( Dali::DALI_KEY_CURSOR_UP == keyCode ) ||
2750 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) )
2752 // If don't have any text, do nothing.
2753 if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
2758 uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition;
2759 uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2760 uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition );
2761 uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines();
2763 // Logic to determine whether this text control will lose focus or not.
2764 if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2765 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2766 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) ||
2767 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) ||
2768 ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) ||
2769 ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) )
2771 // Release the active highlight.
2772 if( mImpl->mEventData->mState == EventData::SELECTING )
2774 mImpl->ChangeState( EventData::EDITING );
2776 // Update selection position.
2777 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2778 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2779 mImpl->mEventData->mUpdateCursorPosition = true;
2780 mImpl->RequestRelayout();
2785 mImpl->mEventData->mCheckScrollAmount = true;
2786 Event event( Event::CURSOR_KEY_EVENT );
2787 event.p1.mInt = keyCode;
2788 event.p2.mBool = keyEvent.IsShiftModifier();
2789 mImpl->mEventData->mEventQueue.push_back( event );
2791 // Will request for relayout.
2792 relayoutNeeded = true;
2794 else if ( Dali::DevelKey::DALI_KEY_CONTROL_LEFT == keyCode || Dali::DevelKey::DALI_KEY_CONTROL_RIGHT == keyCode )
2796 // Left or Right Control key event is received before Ctrl-C/V/X key event is received
2797 // If not handle it here, any selected text will be deleted
2802 else if ( keyEvent.IsCtrlModifier() )
2804 bool consumed = false;
2805 if (keyName == KEY_C_NAME)
2807 // Ctrl-C to copy the selected text
2808 TextPopupButtonTouched( Toolkit::TextSelectionPopup::COPY );
2811 else if (keyName == KEY_V_NAME)
2813 // Ctrl-V to paste the copied text
2814 TextPopupButtonTouched( Toolkit::TextSelectionPopup::PASTE );
2817 else if (keyName == KEY_X_NAME)
2819 // Ctrl-X to cut the selected text
2820 TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
2825 else if( ( Dali::DALI_KEY_BACKSPACE == keyCode ) ||
2826 ( Dali::DevelKey::DALI_KEY_DELETE == keyCode ) )
2828 textChanged = DeleteEvent( keyCode );
2830 // Will request for relayout.
2831 relayoutNeeded = true;
2833 else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
2834 IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
2835 IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
2837 // Power key/Menu/Home key behaviour does not allow edit mode to resume.
2838 mImpl->ChangeState( EventData::INACTIVE );
2840 // Will request for relayout.
2841 relayoutNeeded = true;
2843 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2845 else if( ( Dali::DALI_KEY_SHIFT_LEFT == keyCode ) || ( Dali::DALI_KEY_SHIFT_RIGHT == keyCode ) )
2847 // 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
2848 // and a character is typed after the type of a upper case latin character.
2853 else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
2855 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2861 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
2863 if( !keyString.empty() )
2865 // InputMethodContext is no longer handling key-events
2866 mImpl->ClearPreEditFlag();
2868 InsertText( keyString, COMMIT );
2872 // Will request for relayout.
2873 relayoutNeeded = true;
2878 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
2879 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
2881 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
2882 ( Dali::DALI_KEY_SHIFT_RIGHT != keyCode ) &&
2883 ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
2884 ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
2886 // Should not change the state if the key is the shift send by the InputMethodContext.
2887 // Otherwise, when the state is SELECTING the text controller can't send the right
2888 // surrounding info to the InputMethodContext.
2889 mImpl->ChangeState( EventData::EDITING );
2891 // Will request for relayout.
2892 relayoutNeeded = true;
2895 if( relayoutNeeded )
2897 mImpl->RequestRelayout();
2902 ( NULL != mImpl->mEditableControlInterface ) )
2904 // Do this last since it provides callbacks into application code
2905 mImpl->mEditableControlInterface->TextChanged();
2911 void Controller::TapEvent( unsigned int tapCount, float x, float y )
2913 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
2915 if( NULL != mImpl->mEventData )
2917 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
2918 EventData::State state( mImpl->mEventData->mState );
2919 bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
2921 if( mImpl->IsClipboardVisible() )
2923 if( EventData::INACTIVE == state || EventData::EDITING == state)
2925 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2927 relayoutNeeded = true;
2929 else if( 1u == tapCount )
2931 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
2933 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
2936 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
2938 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2939 relayoutNeeded = true;
2943 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
2945 // Hide placeholder text
2949 if( EventData::INACTIVE == state )
2951 mImpl->ChangeState( EventData::EDITING );
2953 else if( !mImpl->IsClipboardEmpty() )
2955 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
2957 relayoutNeeded = true;
2960 else if( 2u == tapCount )
2962 if( mImpl->mEventData->mSelectionEnabled &&
2963 mImpl->IsShowingRealText() )
2965 relayoutNeeded = true;
2966 mImpl->mEventData->mIsLeftHandleSelected = true;
2967 mImpl->mEventData->mIsRightHandleSelected = true;
2971 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
2972 if( relayoutNeeded )
2974 Event event( Event::TAP_EVENT );
2975 event.p1.mUint = tapCount;
2976 event.p2.mFloat = x;
2977 event.p3.mFloat = y;
2978 mImpl->mEventData->mEventQueue.push_back( event );
2980 mImpl->RequestRelayout();
2984 // Reset keyboard as tap event has occurred.
2985 mImpl->ResetInputMethodContext();
2988 void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
2990 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
2992 if( NULL != mImpl->mEventData )
2994 Event event( Event::PAN_EVENT );
2995 event.p1.mInt = state;
2996 event.p2.mFloat = displacement.x;
2997 event.p3.mFloat = displacement.y;
2998 mImpl->mEventData->mEventQueue.push_back( event );
3000 mImpl->RequestRelayout();
3004 void Controller::LongPressEvent( Gesture::State state, float x, float y )
3006 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
3008 if( ( state == Gesture::Started ) &&
3009 ( NULL != mImpl->mEventData ) )
3011 // The 1st long-press on inactive text-field is treated as tap
3012 if( EventData::INACTIVE == mImpl->mEventData->mState )
3014 mImpl->ChangeState( EventData::EDITING );
3016 Event event( Event::TAP_EVENT );
3018 event.p2.mFloat = x;
3019 event.p3.mFloat = y;
3020 mImpl->mEventData->mEventQueue.push_back( event );
3022 mImpl->RequestRelayout();
3024 else if( !mImpl->IsShowingRealText() )
3026 Event event( Event::LONG_PRESS_EVENT );
3027 event.p1.mInt = state;
3028 event.p2.mFloat = x;
3029 event.p3.mFloat = y;
3030 mImpl->mEventData->mEventQueue.push_back( event );
3031 mImpl->RequestRelayout();
3033 else if( !mImpl->IsClipboardVisible() )
3035 // Reset the InputMethodContext to commit the pre-edit before selecting the text.
3036 mImpl->ResetInputMethodContext();
3038 Event event( Event::LONG_PRESS_EVENT );
3039 event.p1.mInt = state;
3040 event.p2.mFloat = x;
3041 event.p3.mFloat = y;
3042 mImpl->mEventData->mEventQueue.push_back( event );
3043 mImpl->RequestRelayout();
3045 mImpl->mEventData->mIsLeftHandleSelected = true;
3046 mImpl->mEventData->mIsRightHandleSelected = true;
3051 void Controller::SelectEvent( float x, float y, bool selectAll )
3053 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
3055 if( NULL != mImpl->mEventData )
3059 Event event( Event::SELECT_ALL );
3060 mImpl->mEventData->mEventQueue.push_back( event );
3064 Event event( Event::SELECT );
3065 event.p2.mFloat = x;
3066 event.p3.mFloat = y;
3067 mImpl->mEventData->mEventQueue.push_back( event );
3070 mImpl->mEventData->mCheckScrollAmount = true;
3071 mImpl->mEventData->mIsLeftHandleSelected = true;
3072 mImpl->mEventData->mIsRightHandleSelected = true;
3073 mImpl->RequestRelayout();
3077 InputMethodContext::CallbackData Controller::OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
3079 // Whether the text needs to be relaid-out.
3080 bool requestRelayout = false;
3082 // Whether to retrieve the text and cursor position to be sent to the InputMethodContext.
3083 bool retrieveText = false;
3084 bool retrieveCursor = false;
3086 switch( inputMethodContextEvent.eventName )
3088 case InputMethodContext::COMMIT:
3090 InsertText( inputMethodContextEvent.predictiveString, Text::Controller::COMMIT );
3091 requestRelayout = true;
3092 retrieveCursor = true;
3095 case InputMethodContext::PRE_EDIT:
3097 InsertText( inputMethodContextEvent.predictiveString, Text::Controller::PRE_EDIT );
3098 requestRelayout = true;
3099 retrieveCursor = true;
3102 case InputMethodContext::DELETE_SURROUNDING:
3104 const bool textDeleted = RemoveText( inputMethodContextEvent.cursorOffset,
3105 inputMethodContextEvent.numberOfChars,
3106 DONT_UPDATE_INPUT_STYLE );
3110 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3111 !mImpl->IsPlaceholderAvailable() )
3113 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3117 ShowPlaceholderText();
3119 mImpl->mEventData->mUpdateCursorPosition = true;
3120 mImpl->mEventData->mScrollAfterDelete = true;
3122 requestRelayout = true;
3126 case InputMethodContext::GET_SURROUNDING:
3128 retrieveText = true;
3129 retrieveCursor = true;
3132 case InputMethodContext::PRIVATE_COMMAND:
3134 // PRIVATECOMMAND event is just for getting the private command message
3135 retrieveText = true;
3136 retrieveCursor = true;
3139 case InputMethodContext::VOID:
3146 if( requestRelayout )
3148 mImpl->mOperationsPending = ALL_OPERATIONS;
3149 mImpl->RequestRelayout();
3153 CharacterIndex cursorPosition = 0u;
3154 Length numberOfWhiteSpaces = 0u;
3156 if( retrieveCursor )
3158 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
3160 cursorPosition = mImpl->GetLogicalCursorPosition();
3162 if( cursorPosition < numberOfWhiteSpaces )
3164 cursorPosition = 0u;
3168 cursorPosition -= numberOfWhiteSpaces;
3174 if( !mImpl->IsShowingPlaceholderText() )
3176 // Retrieves the normal text string.
3177 mImpl->GetText( numberOfWhiteSpaces, text );
3181 // When the current text is Placeholder Text, the surrounding text should be empty string.
3182 // It means DALi should send empty string ("") to IME.
3187 InputMethodContext::CallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
3189 if( requestRelayout &&
3190 ( NULL != mImpl->mEditableControlInterface ) )
3192 // Do this last since it provides callbacks into application code
3193 mImpl->mEditableControlInterface->TextChanged();
3196 return callbackData;
3199 void Controller::PasteClipboardItemEvent()
3201 // Retrieve the clipboard contents first
3202 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
3203 std::string stringToPaste( notifier.GetContent() );
3205 // Commit the current pre-edit text; the contents of the clipboard should be appended
3206 mImpl->ResetInputMethodContext();
3208 // Temporary disable hiding clipboard
3209 mImpl->SetClipboardHideEnable( false );
3212 PasteText( stringToPaste );
3214 mImpl->SetClipboardHideEnable( true );
3217 // protected : Inherit from Text::Decorator::ControllerInterface.
3219 void Controller::GetTargetSize( Vector2& targetSize )
3221 targetSize = mImpl->mModel->mVisualModel->mControlSize;
3224 void Controller::AddDecoration( Actor& actor, bool needsClipping )
3226 if( NULL != mImpl->mEditableControlInterface )
3228 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
3232 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
3234 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
3236 if( NULL != mImpl->mEventData )
3238 switch( handleType )
3242 Event event( Event::GRAB_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 LEFT_SELECTION_HANDLE:
3252 Event event( Event::LEFT_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 RIGHT_SELECTION_HANDLE:
3262 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
3263 event.p1.mUint = state;
3264 event.p2.mFloat = x;
3265 event.p3.mFloat = y;
3267 mImpl->mEventData->mEventQueue.push_back( event );
3270 case LEFT_SELECTION_HANDLE_MARKER:
3271 case RIGHT_SELECTION_HANDLE_MARKER:
3273 // Markers do not move the handles.
3276 case HANDLE_TYPE_COUNT:
3278 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
3282 mImpl->RequestRelayout();
3286 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
3288 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
3290 if( NULL == mImpl->mEventData )
3297 case Toolkit::TextSelectionPopup::CUT:
3299 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
3300 mImpl->mOperationsPending = ALL_OPERATIONS;
3302 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3303 !mImpl->IsPlaceholderAvailable() )
3305 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3309 ShowPlaceholderText();
3312 mImpl->mEventData->mUpdateCursorPosition = true;
3313 mImpl->mEventData->mScrollAfterDelete = true;
3315 mImpl->RequestRelayout();
3317 if( NULL != mImpl->mEditableControlInterface )
3319 mImpl->mEditableControlInterface->TextChanged();
3323 case Toolkit::TextSelectionPopup::COPY:
3325 mImpl->SendSelectionToClipboard( false ); // Text not modified
3327 mImpl->mEventData->mUpdateCursorPosition = true;
3329 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
3332 case Toolkit::TextSelectionPopup::PASTE:
3334 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
3337 case Toolkit::TextSelectionPopup::SELECT:
3339 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
3341 if( mImpl->mEventData->mSelectionEnabled )
3343 // Creates a SELECT event.
3344 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
3348 case Toolkit::TextSelectionPopup::SELECT_ALL:
3350 // Creates a SELECT_ALL event
3351 SelectEvent( 0.f, 0.f, true );
3354 case Toolkit::TextSelectionPopup::CLIPBOARD:
3356 mImpl->ShowClipboard();
3359 case Toolkit::TextSelectionPopup::NONE:
3367 void Controller::DisplayTimeExpired()
3369 mImpl->mEventData->mUpdateCursorPosition = true;
3370 // Apply modifications to the model
3371 mImpl->mOperationsPending = ALL_OPERATIONS;
3373 mImpl->RequestRelayout();
3376 // private : Update.
3378 void Controller::InsertText( const std::string& text, Controller::InsertType type )
3380 bool removedPrevious = false;
3381 bool removedSelected = false;
3382 bool maxLengthReached = false;
3384 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
3386 if( NULL == mImpl->mEventData )
3391 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
3392 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
3393 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3395 // TODO: At the moment the underline runs are only for pre-edit.
3396 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
3398 // Remove the previous InputMethodContext pre-edit.
3399 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
3401 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
3402 mImpl->mEventData->mPreEditLength,
3403 DONT_UPDATE_INPUT_STYLE );
3405 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
3406 mImpl->mEventData->mPreEditLength = 0u;
3410 // Remove the previous Selection.
3411 removedSelected = RemoveSelectedText();
3415 Vector<Character> utf32Characters;
3416 Length characterCount = 0u;
3420 // Convert text into UTF-32
3421 utf32Characters.Resize( text.size() );
3423 // This is a bit horrible but std::string returns a (signed) char*
3424 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
3426 // Transform a text array encoded in utf8 into an array encoded in utf32.
3427 // It returns the actual number of characters.
3428 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
3429 utf32Characters.Resize( characterCount );
3431 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
3432 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
3435 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
3437 // The placeholder text is no longer needed
3438 if( mImpl->IsShowingPlaceholderText() )
3443 mImpl->ChangeState( EventData::EDITING );
3445 // Handle the InputMethodContext (predicitive text) state changes
3446 if( COMMIT == type )
3448 // InputMethodContext is no longer handling key-events
3449 mImpl->ClearPreEditFlag();
3453 if( !mImpl->mEventData->mPreEditFlag )
3455 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
3457 // Record the start of the pre-edit text
3458 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
3461 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
3462 mImpl->mEventData->mPreEditFlag = true;
3464 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3467 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
3469 // Restrict new text to fit within Maximum characters setting.
3470 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
3471 maxLengthReached = ( characterCount > maxSizeOfNewText );
3473 // The cursor position.
3474 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3476 // Update the text's style.
3478 // Updates the text style runs by adding characters.
3479 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
3481 // Get the character index from the cursor index.
3482 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
3484 // Retrieve the text's style for the given index.
3486 mImpl->RetrieveDefaultInputStyle( style );
3487 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
3489 // Whether to add a new text color run.
3490 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor ) && !mImpl->mEventData->mInputStyle.isDefaultColor;
3492 // Whether to add a new font run.
3493 const bool addFontNameRun = ( style.familyName != mImpl->mEventData->mInputStyle.familyName ) && mImpl->mEventData->mInputStyle.isFamilyDefined;
3494 const bool addFontWeightRun = ( style.weight != mImpl->mEventData->mInputStyle.weight ) && mImpl->mEventData->mInputStyle.isWeightDefined;
3495 const bool addFontWidthRun = ( style.width != mImpl->mEventData->mInputStyle.width ) && mImpl->mEventData->mInputStyle.isWidthDefined;
3496 const bool addFontSlantRun = ( style.slant != mImpl->mEventData->mInputStyle.slant ) && mImpl->mEventData->mInputStyle.isSlantDefined;
3497 const bool addFontSizeRun = ( style.size != mImpl->mEventData->mInputStyle.size ) && mImpl->mEventData->mInputStyle.isSizeDefined ;
3502 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
3503 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
3505 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
3506 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
3507 colorRun.characterRun.characterIndex = cursorIndex;
3508 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3511 if( addFontNameRun ||
3517 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
3518 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
3520 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
3522 if( addFontNameRun )
3524 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
3525 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
3526 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
3527 fontDescriptionRun.familyDefined = true;
3529 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
3532 if( addFontWeightRun )
3534 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
3535 fontDescriptionRun.weightDefined = true;
3538 if( addFontWidthRun )
3540 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
3541 fontDescriptionRun.widthDefined = true;
3544 if( addFontSlantRun )
3546 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
3547 fontDescriptionRun.slantDefined = true;
3550 if( addFontSizeRun )
3552 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
3553 fontDescriptionRun.sizeDefined = true;
3556 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
3557 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3560 // Insert at current cursor position.
3561 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
3563 if( cursorIndex < numberOfCharactersInModel )
3565 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3569 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3572 // Mark the first paragraph to be updated.
3573 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3575 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3576 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3577 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
3578 mImpl->mTextUpdateInfo.mClearAll = true;
3582 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3583 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
3586 // Update the cursor index.
3587 cursorIndex += maxSizeOfNewText;
3589 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 );
3592 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
3593 mImpl->IsPlaceholderAvailable() )
3595 // Show place-holder if empty after removing the pre-edit text
3596 ShowPlaceholderText();
3597 mImpl->mEventData->mUpdateCursorPosition = true;
3598 mImpl->ClearPreEditFlag();
3600 else if( removedPrevious ||
3602 ( 0 != utf32Characters.Count() ) )
3604 // Queue an inserted event
3605 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
3607 mImpl->mEventData->mUpdateCursorPosition = true;
3608 if( removedSelected )
3610 mImpl->mEventData->mScrollAfterDelete = true;
3614 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3618 if( maxLengthReached )
3620 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
3622 mImpl->ResetInputMethodContext();
3624 if( NULL != mImpl->mEditableControlInterface )
3626 // Do this last since it provides callbacks into application code
3627 mImpl->mEditableControlInterface->MaxLengthReached();
3632 void Controller::PasteText( const std::string& stringToPaste )
3634 InsertText( stringToPaste, Text::Controller::COMMIT );
3635 mImpl->ChangeState( EventData::EDITING );
3636 mImpl->RequestRelayout();
3638 if( NULL != mImpl->mEditableControlInterface )
3640 // Do this last since it provides callbacks into application code
3641 mImpl->mEditableControlInterface->TextChanged();
3645 bool Controller::RemoveText( int cursorOffset,
3646 int numberOfCharacters,
3647 UpdateInputStyleType type )
3649 bool removed = false;
3651 if( NULL == mImpl->mEventData )
3656 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
3657 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
3659 if( !mImpl->IsShowingPlaceholderText() )
3661 // Delete at current cursor position
3662 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
3663 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3665 CharacterIndex cursorIndex = 0;
3667 // Validate the cursor position & number of characters
3668 if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
3670 cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
3673 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
3675 numberOfCharacters = currentText.Count() - cursorIndex;
3678 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.
3679 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
3681 // Mark the paragraphs to be updated.
3682 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3684 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3685 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3686 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
3687 mImpl->mTextUpdateInfo.mClearAll = true;
3691 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3692 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
3695 // Update the input style and remove the text's style before removing the text.
3697 if( UPDATE_INPUT_STYLE == type )
3699 // Keep a copy of the current input style.
3700 InputStyle currentInputStyle;
3701 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
3703 // Set first the default input style.
3704 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
3706 // Update the input style.
3707 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
3709 // Compare if the input style has changed.
3710 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
3712 if( hasInputStyleChanged )
3714 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
3715 // Queue the input style changed signal.
3716 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
3720 // If the number of current text and the number of characters to be deleted are same,
3721 // it means all texts should be removed and all Preedit variables should be initialized.
3722 if( ( currentText.Count() - numberOfCharacters == 0 ) && ( cursorIndex == 0 ) )
3724 mImpl->ClearPreEditFlag();
3727 // Updates the text style runs by removing characters. Runs with no characters are removed.
3728 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
3730 // Remove the characters.
3731 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
3732 Vector<Character>::Iterator last = first + numberOfCharacters;
3734 currentText.Erase( first, last );
3736 // Cursor position retreat
3737 oldCursorIndex = cursorIndex;
3739 mImpl->mEventData->mScrollAfterDelete = true;
3741 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
3749 bool Controller::RemoveSelectedText()
3751 bool textRemoved( false );
3753 if( EventData::SELECTING == mImpl->mEventData->mState )
3755 std::string removedString;
3756 mImpl->RetrieveSelection( removedString, true );
3758 if( !removedString.empty() )
3761 mImpl->ChangeState( EventData::EDITING );
3768 // private : Relayout.
3770 bool Controller::DoRelayout( const Size& size,
3771 OperationsMask operationsRequired,
3774 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
3775 bool viewUpdated( false );
3777 // Calculate the operations to be done.
3778 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
3780 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
3781 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
3783 // Get the current layout size.
3784 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3786 if( NO_OPERATION != ( LAYOUT & operations ) )
3788 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
3790 // Some vectors with data needed to layout and reorder may be void
3791 // after the first time the text has been laid out.
3792 // Fill the vectors again.
3794 // Calculate the number of glyphs to layout.
3795 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
3796 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
3797 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
3798 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
3800 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
3801 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
3803 // Make sure the index is not out of bound
3804 if ( charactersToGlyph.Count() != glyphsPerCharacter.Count() ||
3805 requestedNumberOfCharacters > charactersToGlyph.Count() ||
3806 ( lastIndex > charactersToGlyph.Count() && charactersToGlyph.Count() > 0u ) )
3808 std::string currentText;
3809 GetText( currentText );
3811 DALI_LOG_ERROR( "Controller::DoRelayout: Attempting to access invalid buffer\n" );
3812 DALI_LOG_ERROR( "Current text is: %s\n", currentText.c_str() );
3813 DALI_LOG_ERROR( "startIndex: %u, lastIndex: %u, requestedNumberOfCharacters: %u, charactersToGlyph.Count = %lu, glyphsPerCharacter.Count = %lu\n", startIndex, lastIndex, requestedNumberOfCharacters, charactersToGlyph.Count(), glyphsPerCharacter.Count());
3818 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
3819 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
3821 if( 0u == totalNumberOfGlyphs )
3823 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3825 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
3828 // Nothing else to do if there is no glyphs.
3829 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
3833 // Set the layout parameters.
3834 Layout::Parameters layoutParameters( size,
3837 // Resize the vector of positions to have the same size than the vector of glyphs.
3838 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
3839 glyphPositions.Resize( totalNumberOfGlyphs );
3841 // Whether the last character is a new paragraph character.
3842 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
3843 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
3844 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
3846 // The initial glyph and the number of glyphs to layout.
3847 layoutParameters.startGlyphIndex = startGlyphIndex;
3848 layoutParameters.numberOfGlyphs = numberOfGlyphs;
3849 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
3850 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
3852 // Update the ellipsis
3853 bool elideTextEnabled = mImpl->mModel->mElideEnabled;
3855 if( NULL != mImpl->mEventData )
3857 if( mImpl->mEventData->mPlaceholderEllipsisFlag && mImpl->IsShowingPlaceholderText() )
3859 elideTextEnabled = mImpl->mEventData->mIsPlaceholderElideEnabled;
3861 else if( EventData::INACTIVE != mImpl->mEventData->mState )
3863 // Disable ellipsis when editing
3864 elideTextEnabled = false;
3867 // Reset the scroll position in inactive state
3868 if( elideTextEnabled && ( mImpl->mEventData->mState == EventData::INACTIVE ) )
3870 ResetScrollPosition();
3874 // Update the visual model.
3875 bool isAutoScrollEnabled = mImpl->mIsAutoScrollEnabled;
3877 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
3880 isAutoScrollEnabled );
3881 mImpl->mIsAutoScrollEnabled = isAutoScrollEnabled;
3883 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
3887 layoutSize = newLayoutSize;
3889 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
3891 mImpl->mIsTextDirectionRTL = false;
3894 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && !mImpl->mModel->mVisualModel->mLines.Empty() )
3896 mImpl->mIsTextDirectionRTL = mImpl->mModel->mVisualModel->mLines[0u].direction;
3899 // Sets the layout size.
3900 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3902 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
3907 if( NO_OPERATION != ( ALIGN & operations ) )
3909 // The laid-out lines.
3910 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
3912 CharacterIndex alignStartIndex = startIndex;
3913 Length alignRequestedNumberOfCharacters = requestedNumberOfCharacters;
3915 // the whole text needs to be full aligned.
3916 // If you do not do a full aligned, only the last line of the multiline input is aligned.
3917 if( mImpl->mEventData && mImpl->mEventData->mUpdateAlignment )
3919 alignStartIndex = 0u;
3920 alignRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
3921 mImpl->mEventData->mUpdateAlignment = false;
3924 // Need to align with the control's size as the text may contain lines
3925 // starting either with left to right text or right to left.
3926 mImpl->mLayoutEngine.Align( size,
3928 alignRequestedNumberOfCharacters,
3929 mImpl->mModel->mHorizontalAlignment,
3931 mImpl->mModel->mAlignmentOffset,
3932 mImpl->mLayoutDirection,
3933 mImpl->mModel->mMatchSystemLanguageDirection );
3937 #if defined(DEBUG_ENABLED)
3938 std::string currentText;
3939 GetText( currentText );
3940 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mIsTextDirectionRTL[%s] [%s]\n", this, (mImpl->mIsTextDirectionRTL)?"true":"false", currentText.c_str() );
3942 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
3946 void Controller::CalculateVerticalOffset( const Size& controlSize )
3948 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3950 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
3952 // Get the line height of the default font.
3953 layoutSize.height = mImpl->GetDefaultFontLineHeight();
3956 switch( mImpl->mModel->mVerticalAlignment )
3958 case VerticalAlignment::TOP:
3960 mImpl->mModel->mScrollPosition.y = 0.f;
3963 case VerticalAlignment::CENTER:
3965 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
3968 case VerticalAlignment::BOTTOM:
3970 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
3976 // private : Events.
3978 void Controller::ProcessModifyEvents()
3980 Vector<ModifyEvent>& events = mImpl->mModifyEvents;
3982 if( 0u == events.Count() )
3988 for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
3989 endIt = events.End();
3993 const ModifyEvent& event = *it;
3995 if( ModifyEvent::TEXT_REPLACED == event.type )
3997 // A (single) replace event should come first, otherwise we wasted time processing NOOP events
3998 DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
4000 TextReplacedEvent();
4002 else if( ModifyEvent::TEXT_INSERTED == event.type )
4004 TextInsertedEvent();
4006 else if( ModifyEvent::TEXT_DELETED == event.type )
4008 // Placeholder-text cannot be deleted
4009 if( !mImpl->IsShowingPlaceholderText() )
4016 if( NULL != mImpl->mEventData )
4018 // When the text is being modified, delay cursor blinking
4019 mImpl->mEventData->mDecorator->DelayCursorBlink();
4021 // Update selection position after modifying the text
4022 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
4023 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
4026 // Discard temporary text
4030 void Controller::TextReplacedEvent()
4032 // The natural size needs to be re-calculated.
4033 mImpl->mRecalculateNaturalSize = true;
4035 // The text direction needs to be updated.
4036 mImpl->mUpdateTextDirection = true;
4038 // Apply modifications to the model
4039 mImpl->mOperationsPending = ALL_OPERATIONS;
4042 void Controller::TextInsertedEvent()
4044 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
4046 if( NULL == mImpl->mEventData )
4051 mImpl->mEventData->mCheckScrollAmount = true;
4053 // The natural size needs to be re-calculated.
4054 mImpl->mRecalculateNaturalSize = true;
4056 // The text direction needs to be updated.
4057 mImpl->mUpdateTextDirection = true;
4059 // Apply modifications to the model; TODO - Optimize this
4060 mImpl->mOperationsPending = ALL_OPERATIONS;
4063 void Controller::TextDeletedEvent()
4065 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
4067 if( NULL == mImpl->mEventData )
4072 mImpl->mEventData->mCheckScrollAmount = true;
4074 // The natural size needs to be re-calculated.
4075 mImpl->mRecalculateNaturalSize = true;
4077 // The text direction needs to be updated.
4078 mImpl->mUpdateTextDirection = true;
4080 // Apply modifications to the model; TODO - Optimize this
4081 mImpl->mOperationsPending = ALL_OPERATIONS;
4084 bool Controller::DeleteEvent( int keyCode )
4086 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p KeyCode : %d \n", this, keyCode );
4088 bool removed = false;
4090 if( NULL == mImpl->mEventData )
4095 // InputMethodContext is no longer handling key-events
4096 mImpl->ClearPreEditFlag();
4098 if( EventData::SELECTING == mImpl->mEventData->mState )
4100 removed = RemoveSelectedText();
4102 else if( ( mImpl->mEventData->mPrimaryCursorPosition > 0 ) && ( keyCode == Dali::DALI_KEY_BACKSPACE) )
4104 // Remove the character before the current cursor position
4105 removed = RemoveText( -1,
4107 UPDATE_INPUT_STYLE );
4109 else if( keyCode == Dali::DevelKey::DALI_KEY_DELETE )
4111 // Remove the character after the current cursor position
4112 removed = RemoveText( 0,
4114 UPDATE_INPUT_STYLE );
4119 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
4120 !mImpl->IsPlaceholderAvailable() )
4122 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
4126 ShowPlaceholderText();
4128 mImpl->mEventData->mUpdateCursorPosition = true;
4129 mImpl->mEventData->mScrollAfterDelete = true;
4135 // private : Helpers.
4137 void Controller::ResetText()
4140 mImpl->mModel->mLogicalModel->mText.Clear();
4142 // Reset the embedded images buffer.
4143 mImpl->mModel->mLogicalModel->ClearEmbeddedImages();
4145 // We have cleared everything including the placeholder-text
4146 mImpl->PlaceholderCleared();
4148 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4149 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4150 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
4152 // Clear any previous text.
4153 mImpl->mTextUpdateInfo.mClearAll = true;
4155 // The natural size needs to be re-calculated.
4156 mImpl->mRecalculateNaturalSize = true;
4158 // The text direction needs to be updated.
4159 mImpl->mUpdateTextDirection = true;
4161 // Apply modifications to the model
4162 mImpl->mOperationsPending = ALL_OPERATIONS;
4165 void Controller::ShowPlaceholderText()
4167 if( mImpl->IsPlaceholderAvailable() )
4169 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
4171 if( NULL == mImpl->mEventData )
4176 mImpl->mEventData->mIsShowingPlaceholderText = true;
4178 // Disable handles when showing place-holder text
4179 mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
4180 mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
4181 mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
4183 const char* text( NULL );
4186 // TODO - Switch Placeholder text when changing state
4187 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
4188 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
4190 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
4191 size = mImpl->mEventData->mPlaceholderTextActive.size();
4195 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
4196 size = mImpl->mEventData->mPlaceholderTextInactive.size();
4199 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4200 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4202 // Reset model for showing placeholder.
4203 mImpl->mModel->mLogicalModel->mText.Clear();
4204 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
4206 // Convert text into UTF-32
4207 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
4208 utf32Characters.Resize( size );
4210 // This is a bit horrible but std::string returns a (signed) char*
4211 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
4213 // Transform a text array encoded in utf8 into an array encoded in utf32.
4214 // It returns the actual number of characters.
4215 const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
4216 utf32Characters.Resize( characterCount );
4218 // The characters to be added.
4219 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
4221 // Reset the cursor position
4222 mImpl->mEventData->mPrimaryCursorPosition = 0;
4224 // The natural size needs to be re-calculated.
4225 mImpl->mRecalculateNaturalSize = true;
4227 // The text direction needs to be updated.
4228 mImpl->mUpdateTextDirection = true;
4230 // Apply modifications to the model
4231 mImpl->mOperationsPending = ALL_OPERATIONS;
4233 // Update the rest of the model during size negotiation
4234 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
4238 void Controller::ClearFontData()
4240 if( mImpl->mFontDefaults )
4242 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
4245 // Set flags to update the model.
4246 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4247 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4248 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
4250 mImpl->mTextUpdateInfo.mClearAll = true;
4251 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
4252 mImpl->mRecalculateNaturalSize = true;
4254 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
4260 UPDATE_LAYOUT_SIZE |
4265 void Controller::ClearStyleData()
4267 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
4268 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
4271 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
4273 // Reset the cursor position
4274 if( NULL != mImpl->mEventData )
4276 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
4278 // Update the cursor if it's in editing mode.
4279 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
4281 mImpl->mEventData->mUpdateCursorPosition = true;
4286 void Controller::ResetScrollPosition()
4288 if( NULL != mImpl->mEventData )
4290 // Reset the scroll position.
4291 mImpl->mModel->mScrollPosition = Vector2::ZERO;
4292 mImpl->mEventData->mScrollAfterUpdatePosition = true;
4296 void Controller::SetControlInterface( ControlInterface* controlInterface )
4298 mImpl->mControlInterface = controlInterface;
4301 bool Controller::ShouldClearFocusOnEscape() const
4303 return mImpl->mShouldClearFocusOnEscape;
4306 Actor Controller::CreateBackgroundActor()
4308 return mImpl->CreateBackgroundActor();
4311 // private : Private contructors & copy operator.
4313 Controller::Controller()
4316 mImpl = new Controller::Impl( NULL, NULL );
4319 Controller::Controller( ControlInterface* controlInterface )
4321 mImpl = new Controller::Impl( controlInterface, NULL );
4324 Controller::Controller( ControlInterface* controlInterface,
4325 EditableControlInterface* editableControlInterface )
4327 mImpl = new Controller::Impl( controlInterface,
4328 editableControlInterface );
4331 // The copy constructor and operator are left unimplemented.
4333 // protected : Destructor.
4335 Controller::~Controller()
4342 } // namespace Toolkit