2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/text/text-controller.h>
25 #include <dali/public-api/adaptor-framework/key.h>
26 #include <dali/integration-api/debug.h>
27 #include <dali/devel-api/adaptor-framework/clipboard-event-notifier.h>
28 #include <dali/devel-api/text-abstraction/font-client.h>
29 #include <dali/devel-api/adaptor-framework/key-devel.h>
32 #include <dali-toolkit/public-api/controls/text-controls/placeholder-properties.h>
33 #include <dali-toolkit/internal/text/bidirectional-support.h>
34 #include <dali-toolkit/internal/text/character-set-conversion.h>
35 #include <dali-toolkit/internal/text/layouts/layout-parameters.h>
36 #include <dali-toolkit/internal/text/markup-processor.h>
37 #include <dali-toolkit/internal/text/multi-language-support.h>
38 #include <dali-toolkit/internal/text/text-controller-impl.h>
39 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
40 #include <dali-toolkit/internal/text/text-font-style.h>
45 #if defined(DEBUG_ENABLED)
46 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
49 const float MAX_FLOAT = std::numeric_limits<float>::max();
51 const std::string EMPTY_STRING("");
53 const std::string KEY_C_NAME = "c";
54 const std::string KEY_V_NAME = "v";
55 const std::string KEY_X_NAME = "x";
57 const char * const PLACEHOLDER_TEXT = "text";
58 const char * const PLACEHOLDER_TEXT_FOCUSED = "textFocused";
59 const char * const PLACEHOLDER_COLOR = "color";
60 const char * const PLACEHOLDER_FONT_FAMILY = "fontFamily";
61 const char * const PLACEHOLDER_FONT_STYLE = "fontStyle";
62 const char * const PLACEHOLDER_POINT_SIZE = "pointSize";
63 const char * const PLACEHOLDER_PIXEL_SIZE = "pixelSize";
64 const char * const PLACEHOLDER_ELLIPSIS = "ellipsis";
66 float ConvertToEven( float value )
68 int intValue(static_cast<int>( value ));
69 return static_cast<float>( intValue + ( intValue & 1 ) );
72 int ConvertPixelToPint( float pixel )
74 unsigned int horizontalDpi = 0u;
75 unsigned int verticalDpi = 0u;
76 Dali::TextAbstraction::FontClient fontClient = Dali::TextAbstraction::FontClient::Get();
77 fontClient.GetDpi( horizontalDpi, verticalDpi );
79 return ( pixel * 72.f ) / static_cast< float >( horizontalDpi );
94 * @brief Adds a new font description run for the selected text.
96 * The new font parameters are added after the call to this method.
98 * @param[in] eventData The event data pointer.
99 * @param[in] logicalModel The logical model where to add the new font description run.
100 * @param[out] startOfSelectedText Index to the first selected character.
101 * @param[out] lengthOfSelectedText Number of selected characters.
103 FontDescriptionRun& UpdateSelectionFontStyleRun( EventData* eventData,
104 LogicalModelPtr logicalModel,
105 CharacterIndex& startOfSelectedText,
106 Length& lengthOfSelectedText )
108 const bool handlesCrossed = eventData->mLeftSelectionPosition > eventData->mRightSelectionPosition;
110 // Get start and end position of selection
111 startOfSelectedText = handlesCrossed ? eventData->mRightSelectionPosition : eventData->mLeftSelectionPosition;
112 lengthOfSelectedText = ( handlesCrossed ? eventData->mLeftSelectionPosition : eventData->mRightSelectionPosition ) - startOfSelectedText;
115 const VectorBase::SizeType numberOfRuns = logicalModel->mFontDescriptionRuns.Count();
116 logicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
118 FontDescriptionRun& fontDescriptionRun = *( logicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
120 fontDescriptionRun.characterRun.characterIndex = startOfSelectedText;
121 fontDescriptionRun.characterRun.numberOfCharacters = lengthOfSelectedText;
123 // Recalculate the selection highlight as the metrics may have changed.
124 eventData->mUpdateLeftSelectionPosition = true;
125 eventData->mUpdateRightSelectionPosition = true;
126 eventData->mUpdateHighlightBox = true;
128 return fontDescriptionRun;
131 // public : Constructor.
133 ControllerPtr Controller::New()
135 return ControllerPtr( new Controller() );
138 ControllerPtr Controller::New( ControlInterface* controlInterface )
140 return ControllerPtr( new Controller( controlInterface ) );
143 ControllerPtr Controller::New( ControlInterface* controlInterface,
144 EditableControlInterface* editableControlInterface )
146 return ControllerPtr( new Controller( controlInterface,
147 editableControlInterface ) );
150 // public : Configure the text controller.
152 void Controller::EnableTextInput( DecoratorPtr decorator, InputMethodContext& inputMethodContext )
156 delete mImpl->mEventData;
157 mImpl->mEventData = NULL;
159 // Nothing else to do.
163 if( NULL == mImpl->mEventData )
165 mImpl->mEventData = new EventData( decorator, inputMethodContext );
169 void Controller::SetGlyphType( TextAbstraction::GlyphType glyphType )
171 // Metrics for bitmap & vector based glyphs are different
172 mImpl->mMetrics->SetGlyphType( glyphType );
174 // Clear the font-specific data
177 mImpl->RequestRelayout();
180 void Controller::SetMarkupProcessorEnabled( bool enable )
182 if( enable != mImpl->mMarkupProcessorEnabled )
184 //If Text was already set, call the SetText again for enabling or disabling markup
185 mImpl->mMarkupProcessorEnabled = enable;
192 bool Controller::IsMarkupProcessorEnabled() const
194 return mImpl->mMarkupProcessorEnabled;
197 void Controller::SetAutoScrollEnabled( bool enable )
199 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled[%s] SingleBox[%s]-> [%p]\n", (enable)?"true":"false", ( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX)?"true":"false", this );
201 if( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX )
205 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled for SINGLE_LINE_BOX\n" );
206 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
216 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled Disabling autoscroll\n");
217 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
224 mImpl->mIsAutoScrollEnabled = enable;
225 mImpl->RequestRelayout();
229 DALI_LOG_WARNING( "Attempted AutoScrolling on a non SINGLE_LINE_BOX, request ignored\n" );
230 mImpl->mIsAutoScrollEnabled = false;
234 bool Controller::IsAutoScrollEnabled() const
236 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::IsAutoScrollEnabled[%s]\n", mImpl->mIsAutoScrollEnabled?"true":"false" );
238 return mImpl->mIsAutoScrollEnabled;
241 CharacterDirection Controller::GetAutoScrollDirection() const
243 return mImpl->mIsTextDirectionRTL;
246 float Controller::GetAutoScrollLineAlignment() const
250 if( mImpl->mModel->mVisualModel &&
251 ( 0u != mImpl->mModel->mVisualModel->mLines.Count() ) )
253 offset = ( *mImpl->mModel->mVisualModel->mLines.Begin() ).alignmentOffset;
259 void Controller::SetHorizontalScrollEnabled( bool enable )
261 if( ( NULL != mImpl->mEventData ) &&
262 mImpl->mEventData->mDecorator )
264 mImpl->mEventData->mDecorator->SetHorizontalScrollEnabled( enable );
267 bool Controller::IsHorizontalScrollEnabled() const
269 if( ( NULL != mImpl->mEventData ) &&
270 mImpl->mEventData->mDecorator )
272 return mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
278 void Controller::SetVerticalScrollEnabled( bool enable )
280 if( ( NULL != mImpl->mEventData ) &&
281 mImpl->mEventData->mDecorator )
283 if( mImpl->mEventData->mDecorator )
285 mImpl->mEventData->mDecorator->SetVerticalScrollEnabled( enable );
290 bool Controller::IsVerticalScrollEnabled() const
292 if( ( NULL != mImpl->mEventData ) &&
293 mImpl->mEventData->mDecorator )
295 return mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
301 void Controller::SetSmoothHandlePanEnabled( bool enable )
303 if( ( NULL != mImpl->mEventData ) &&
304 mImpl->mEventData->mDecorator )
306 mImpl->mEventData->mDecorator->SetSmoothHandlePanEnabled( enable );
310 bool Controller::IsSmoothHandlePanEnabled() const
312 if( ( NULL != mImpl->mEventData ) &&
313 mImpl->mEventData->mDecorator )
315 return mImpl->mEventData->mDecorator->IsSmoothHandlePanEnabled();
321 void Controller::SetMaximumNumberOfCharacters( Length maxCharacters )
323 mImpl->mMaximumNumberOfCharacters = maxCharacters;
326 int Controller::GetMaximumNumberOfCharacters()
328 return mImpl->mMaximumNumberOfCharacters;
331 void Controller::SetEnableCursorBlink( bool enable )
333 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "TextInput disabled" );
335 if( NULL != mImpl->mEventData )
337 mImpl->mEventData->mCursorBlinkEnabled = enable;
340 mImpl->mEventData->mDecorator )
342 mImpl->mEventData->mDecorator->StopCursorBlink();
347 bool Controller::GetEnableCursorBlink() const
349 if( NULL != mImpl->mEventData )
351 return mImpl->mEventData->mCursorBlinkEnabled;
357 void Controller::SetMultiLineEnabled( bool enable )
359 const Layout::Engine::Type layout = enable ? Layout::Engine::MULTI_LINE_BOX : Layout::Engine::SINGLE_LINE_BOX;
361 if( layout != mImpl->mLayoutEngine.GetLayout() )
363 // Set the layout type.
364 mImpl->mLayoutEngine.SetLayout( layout );
366 // Set the flags to redo the layout operations
367 const OperationsMask layoutOperations = static_cast<OperationsMask>( LAYOUT |
372 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
373 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | layoutOperations );
375 // Need to recalculate natural size
376 mImpl->mRecalculateNaturalSize = true;
378 mImpl->RequestRelayout();
382 bool Controller::IsMultiLineEnabled() const
384 return Layout::Engine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
387 void Controller::SetHorizontalAlignment( Text::HorizontalAlignment::Type alignment )
389 if( alignment != mImpl->mModel->mHorizontalAlignment )
391 // Set the alignment.
392 mImpl->mModel->mHorizontalAlignment = alignment;
394 // Set the flag to redo the alignment operation.
395 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
397 if( mImpl->mEventData )
399 mImpl->mEventData->mUpdateAlignment = true;
401 // Update the cursor if it's in editing mode
402 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
404 mImpl->ChangeState( EventData::EDITING );
405 mImpl->mEventData->mUpdateCursorPosition = true;
409 mImpl->RequestRelayout();
413 Text::HorizontalAlignment::Type Controller::GetHorizontalAlignment() const
415 return mImpl->mModel->mHorizontalAlignment;
418 void Controller::SetVerticalAlignment( VerticalAlignment::Type alignment )
420 if( alignment != mImpl->mModel->mVerticalAlignment )
422 // Set the alignment.
423 mImpl->mModel->mVerticalAlignment = alignment;
425 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
427 mImpl->RequestRelayout();
431 VerticalAlignment::Type Controller::GetVerticalAlignment() const
433 return mImpl->mModel->mVerticalAlignment;
436 bool Controller::IsIgnoreSpacesAfterText() const
438 return mImpl->mModel->mIgnoreSpacesAfterText;
441 void Controller::SetIgnoreSpacesAfterText( bool ignore )
443 mImpl->mModel->mIgnoreSpacesAfterText = ignore;
446 bool Controller::IsMatchSystemLanguageDirection() const
448 return mImpl->mModel->mMatchSystemLanguageDirection;
451 void Controller::SetMatchSystemLanguageDirection( bool match )
453 mImpl->mModel->mMatchSystemLanguageDirection = match;
456 void Controller::SetLayoutDirection( Dali::LayoutDirection::Type layoutDirection )
458 mImpl->mLayoutDirection = layoutDirection;
461 bool Controller::IsShowingRealText() const
463 return mImpl->IsShowingRealText();
467 void Controller::SetLineWrapMode( Text::LineWrap::Mode lineWrapMode )
469 if( lineWrapMode != mImpl->mModel->mLineWrapMode )
471 // Set the text wrap mode.
472 mImpl->mModel->mLineWrapMode = lineWrapMode;
475 // Update Text layout for applying wrap mode
476 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
481 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
482 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
483 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
486 mImpl->RequestRelayout();
490 Text::LineWrap::Mode Controller::GetLineWrapMode() const
492 return mImpl->mModel->mLineWrapMode;
495 void Controller::SetTextElideEnabled( bool enabled )
497 mImpl->mModel->mElideEnabled = enabled;
500 bool Controller::IsTextElideEnabled() const
502 return mImpl->mModel->mElideEnabled;
505 void Controller::SetTextFitEnabled(bool enabled)
507 mImpl->mTextFitEnabled = enabled;
510 bool Controller::IsTextFitEnabled() const
512 return mImpl->mTextFitEnabled;
515 void Controller::SetTextFitMinSize( float minSize, FontSizeType type )
521 mImpl->mTextFitMinSize = minSize;
526 mImpl->mTextFitMinSize = ConvertPixelToPint( minSize );
532 float Controller::GetTextFitMinSize() const
534 return mImpl->mTextFitMinSize;
537 void Controller::SetTextFitMaxSize( float maxSize, FontSizeType type )
543 mImpl->mTextFitMaxSize = maxSize;
548 mImpl->mTextFitMaxSize = ConvertPixelToPint( maxSize );
554 float Controller::GetTextFitMaxSize() const
556 return mImpl->mTextFitMaxSize;
559 void Controller::SetTextFitStepSize( float step, FontSizeType type )
565 mImpl->mTextFitStepSize = step;
570 mImpl->mTextFitStepSize = ConvertPixelToPint( step );
576 float Controller::GetTextFitStepSize() const
578 return mImpl->mTextFitStepSize;
581 void Controller::SetTextFitContentSize(Vector2 size)
583 mImpl->mTextFitContentSize = size;
586 Vector2 Controller::GetTextFitContentSize() const
588 return mImpl->mTextFitContentSize;
591 void Controller::SetPlaceholderTextElideEnabled( bool enabled )
593 mImpl->mEventData->mIsPlaceholderElideEnabled = enabled;
594 mImpl->mEventData->mPlaceholderEllipsisFlag = true;
596 // Update placeholder if there is no text
597 if( mImpl->IsShowingPlaceholderText() ||
598 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
600 ShowPlaceholderText();
604 bool Controller::IsPlaceholderTextElideEnabled() const
606 return mImpl->mEventData->mIsPlaceholderElideEnabled;
609 void Controller::SetSelectionEnabled( bool enabled )
611 mImpl->mEventData->mSelectionEnabled = enabled;
614 bool Controller::IsSelectionEnabled() const
616 return mImpl->mEventData->mSelectionEnabled;
619 void Controller::SetShiftSelectionEnabled( bool enabled )
621 mImpl->mEventData->mShiftSelectionFlag = enabled;
624 bool Controller::IsShiftSelectionEnabled() const
626 return mImpl->mEventData->mShiftSelectionFlag;
629 void Controller::SetGrabHandleEnabled( bool enabled )
631 mImpl->mEventData->mGrabHandleEnabled = enabled;
634 bool Controller::IsGrabHandleEnabled() const
636 return mImpl->mEventData->mGrabHandleEnabled;
639 void Controller::SetGrabHandlePopupEnabled(bool enabled)
641 mImpl->mEventData->mGrabHandlePopupEnabled = enabled;
644 bool Controller::IsGrabHandlePopupEnabled() const
646 return mImpl->mEventData->mGrabHandlePopupEnabled;
651 void Controller::SetText( const std::string& text )
653 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" );
655 // Reset keyboard as text changed
656 mImpl->ResetInputMethodContext();
658 // Remove the previously set text and style.
664 CharacterIndex lastCursorIndex = 0u;
666 if( NULL != mImpl->mEventData )
668 // If popup shown then hide it by switching to Editing state
669 if( ( EventData::SELECTING == mImpl->mEventData->mState ) ||
670 ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
671 ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) ||
672 ( EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState ) )
674 mImpl->ChangeState( EventData::EDITING );
680 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mTextColor );
682 MarkupProcessData markupProcessData( mImpl->mModel->mLogicalModel->mColorRuns,
683 mImpl->mModel->mLogicalModel->mFontDescriptionRuns,
684 mImpl->mModel->mLogicalModel->mEmbeddedItems );
686 Length textSize = 0u;
687 const uint8_t* utf8 = NULL;
688 if( mImpl->mMarkupProcessorEnabled )
690 ProcessMarkupString( text, markupProcessData );
691 textSize = markupProcessData.markupProcessedText.size();
693 // This is a bit horrible but std::string returns a (signed) char*
694 utf8 = reinterpret_cast<const uint8_t*>( markupProcessData.markupProcessedText.c_str() );
698 textSize = text.size();
700 // This is a bit horrible but std::string returns a (signed) char*
701 utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
704 // Convert text into UTF-32
705 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
706 utf32Characters.Resize( textSize );
708 // Transform a text array encoded in utf8 into an array encoded in utf32.
709 // It returns the actual number of characters.
710 Length characterCount = Utf8ToUtf32( utf8, textSize, utf32Characters.Begin() );
711 utf32Characters.Resize( characterCount );
713 DALI_ASSERT_DEBUG( textSize >= characterCount && "Invalid UTF32 conversion length" );
714 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", this, textSize, mImpl->mModel->mLogicalModel->mText.Count() );
716 // The characters to be added.
717 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
719 // To reset the cursor position
720 lastCursorIndex = characterCount;
722 // Update the rest of the model during size negotiation
723 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
725 // The natural size needs to be re-calculated.
726 mImpl->mRecalculateNaturalSize = true;
728 // The text direction needs to be updated.
729 mImpl->mUpdateTextDirection = true;
731 // Apply modifications to the model
732 mImpl->mOperationsPending = ALL_OPERATIONS;
736 ShowPlaceholderText();
739 // Resets the cursor position.
740 ResetCursorPosition( lastCursorIndex );
742 // Scrolls the text to make the cursor visible.
743 ResetScrollPosition();
745 mImpl->RequestRelayout();
747 if( NULL != mImpl->mEventData )
749 // Cancel previously queued events
750 mImpl->mEventData->mEventQueue.clear();
753 // Do this last since it provides callbacks into application code.
754 if( NULL != mImpl->mEditableControlInterface )
756 mImpl->mEditableControlInterface->TextChanged();
760 void Controller::GetText( std::string& text ) const
762 if( !mImpl->IsShowingPlaceholderText() )
764 // Retrieves the text string.
765 mImpl->GetText( 0u, text );
769 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this );
773 void Controller::SetPlaceholderText( PlaceholderType type, const std::string& text )
775 if( NULL != mImpl->mEventData )
777 if( PLACEHOLDER_TYPE_INACTIVE == type )
779 mImpl->mEventData->mPlaceholderTextInactive = text;
783 mImpl->mEventData->mPlaceholderTextActive = text;
786 // Update placeholder if there is no text
787 if( mImpl->IsShowingPlaceholderText() ||
788 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
790 ShowPlaceholderText();
795 void Controller::GetPlaceholderText( PlaceholderType type, std::string& text ) const
797 if( NULL != mImpl->mEventData )
799 if( PLACEHOLDER_TYPE_INACTIVE == type )
801 text = mImpl->mEventData->mPlaceholderTextInactive;
805 text = mImpl->mEventData->mPlaceholderTextActive;
810 void Controller::UpdateAfterFontChange( const std::string& newDefaultFont )
812 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
814 if( !mImpl->mFontDefaults->familyDefined ) // If user defined font then should not update when system font changes
816 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
817 mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
821 mImpl->RequestRelayout();
825 // public : Default style & Input style
827 void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
829 if( NULL == mImpl->mFontDefaults )
831 mImpl->mFontDefaults = new FontDefaults();
834 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
835 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
836 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
838 // Clear the font-specific data
841 mImpl->RequestRelayout();
844 const std::string& Controller::GetDefaultFontFamily() const
846 if( NULL != mImpl->mFontDefaults )
848 return mImpl->mFontDefaults->mFontDescription.family;
854 void Controller::SetPlaceholderFontFamily( const std::string& placeholderTextFontFamily )
856 if( NULL != mImpl->mEventData )
858 if( NULL == mImpl->mEventData->mPlaceholderFont )
860 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
863 mImpl->mEventData->mPlaceholderFont->mFontDescription.family = placeholderTextFontFamily;
864 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetPlaceholderFontFamily %s\n", placeholderTextFontFamily.c_str());
865 mImpl->mEventData->mPlaceholderFont->familyDefined = !placeholderTextFontFamily.empty();
867 mImpl->RequestRelayout();
871 const std::string& Controller::GetPlaceholderFontFamily() const
873 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
875 return mImpl->mEventData->mPlaceholderFont->mFontDescription.family;
881 void Controller::SetDefaultFontWeight( FontWeight weight )
883 if( NULL == mImpl->mFontDefaults )
885 mImpl->mFontDefaults = new FontDefaults();
888 mImpl->mFontDefaults->mFontDescription.weight = weight;
889 mImpl->mFontDefaults->weightDefined = true;
891 // Clear the font-specific data
894 mImpl->RequestRelayout();
897 bool Controller::IsDefaultFontWeightDefined() const
899 if( NULL != mImpl->mFontDefaults )
901 return mImpl->mFontDefaults->weightDefined;
907 FontWeight Controller::GetDefaultFontWeight() const
909 if( NULL != mImpl->mFontDefaults )
911 return mImpl->mFontDefaults->mFontDescription.weight;
914 return TextAbstraction::FontWeight::NORMAL;
917 void Controller::SetPlaceholderTextFontWeight( FontWeight weight )
919 if( NULL != mImpl->mEventData )
921 if( NULL == mImpl->mEventData->mPlaceholderFont )
923 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
926 mImpl->mEventData->mPlaceholderFont->mFontDescription.weight = weight;
927 mImpl->mEventData->mPlaceholderFont->weightDefined = true;
929 mImpl->RequestRelayout();
933 bool Controller::IsPlaceholderTextFontWeightDefined() const
935 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
937 return mImpl->mEventData->mPlaceholderFont->weightDefined;
942 FontWeight Controller::GetPlaceholderTextFontWeight() const
944 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
946 return mImpl->mEventData->mPlaceholderFont->mFontDescription.weight;
949 return TextAbstraction::FontWeight::NORMAL;
952 void Controller::SetDefaultFontWidth( FontWidth width )
954 if( NULL == mImpl->mFontDefaults )
956 mImpl->mFontDefaults = new FontDefaults();
959 mImpl->mFontDefaults->mFontDescription.width = width;
960 mImpl->mFontDefaults->widthDefined = true;
962 // Clear the font-specific data
965 mImpl->RequestRelayout();
968 bool Controller::IsDefaultFontWidthDefined() const
970 if( NULL != mImpl->mFontDefaults )
972 return mImpl->mFontDefaults->widthDefined;
978 FontWidth Controller::GetDefaultFontWidth() const
980 if( NULL != mImpl->mFontDefaults )
982 return mImpl->mFontDefaults->mFontDescription.width;
985 return TextAbstraction::FontWidth::NORMAL;
988 void Controller::SetPlaceholderTextFontWidth( FontWidth width )
990 if( NULL != mImpl->mEventData )
992 if( NULL == mImpl->mEventData->mPlaceholderFont )
994 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
997 mImpl->mEventData->mPlaceholderFont->mFontDescription.width = width;
998 mImpl->mEventData->mPlaceholderFont->widthDefined = true;
1000 mImpl->RequestRelayout();
1004 bool Controller::IsPlaceholderTextFontWidthDefined() const
1006 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1008 return mImpl->mEventData->mPlaceholderFont->widthDefined;
1013 FontWidth Controller::GetPlaceholderTextFontWidth() const
1015 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1017 return mImpl->mEventData->mPlaceholderFont->mFontDescription.width;
1020 return TextAbstraction::FontWidth::NORMAL;
1023 void Controller::SetDefaultFontSlant( FontSlant slant )
1025 if( NULL == mImpl->mFontDefaults )
1027 mImpl->mFontDefaults = new FontDefaults();
1030 mImpl->mFontDefaults->mFontDescription.slant = slant;
1031 mImpl->mFontDefaults->slantDefined = true;
1033 // Clear the font-specific data
1036 mImpl->RequestRelayout();
1039 bool Controller::IsDefaultFontSlantDefined() const
1041 if( NULL != mImpl->mFontDefaults )
1043 return mImpl->mFontDefaults->slantDefined;
1048 FontSlant Controller::GetDefaultFontSlant() const
1050 if( NULL != mImpl->mFontDefaults )
1052 return mImpl->mFontDefaults->mFontDescription.slant;
1055 return TextAbstraction::FontSlant::NORMAL;
1058 void Controller::SetPlaceholderTextFontSlant( FontSlant slant )
1060 if( NULL != mImpl->mEventData )
1062 if( NULL == mImpl->mEventData->mPlaceholderFont )
1064 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
1067 mImpl->mEventData->mPlaceholderFont->mFontDescription.slant = slant;
1068 mImpl->mEventData->mPlaceholderFont->slantDefined = true;
1070 mImpl->RequestRelayout();
1074 bool Controller::IsPlaceholderTextFontSlantDefined() const
1076 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1078 return mImpl->mEventData->mPlaceholderFont->slantDefined;
1083 FontSlant Controller::GetPlaceholderTextFontSlant() const
1085 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1087 return mImpl->mEventData->mPlaceholderFont->mFontDescription.slant;
1090 return TextAbstraction::FontSlant::NORMAL;
1093 void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
1095 if( NULL == mImpl->mFontDefaults )
1097 mImpl->mFontDefaults = new FontDefaults();
1104 mImpl->mFontDefaults->mDefaultPointSize = fontSize;
1105 mImpl->mFontDefaults->sizeDefined = true;
1110 // Point size = Pixel size * 72.f / DPI
1111 unsigned int horizontalDpi = 0u;
1112 unsigned int verticalDpi = 0u;
1113 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1114 fontClient.GetDpi( horizontalDpi, verticalDpi );
1116 mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
1117 mImpl->mFontDefaults->sizeDefined = true;
1122 // Clear the font-specific data
1125 mImpl->RequestRelayout();
1128 float Controller::GetDefaultFontSize( FontSizeType type ) const
1131 if( NULL != mImpl->mFontDefaults )
1137 value = mImpl->mFontDefaults->mDefaultPointSize;
1142 // Pixel size = Point size * DPI / 72.f
1143 unsigned int horizontalDpi = 0u;
1144 unsigned int verticalDpi = 0u;
1145 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1146 fontClient.GetDpi( horizontalDpi, verticalDpi );
1148 value = mImpl->mFontDefaults->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1158 void Controller::SetPlaceholderTextFontSize( float fontSize, FontSizeType type )
1160 if( NULL != mImpl->mEventData )
1162 if( NULL == mImpl->mEventData->mPlaceholderFont )
1164 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
1171 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = fontSize;
1172 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1173 mImpl->mEventData->mIsPlaceholderPixelSize = false; // Font size flag
1178 // Point size = Pixel size * 72.f / DPI
1179 unsigned int horizontalDpi = 0u;
1180 unsigned int verticalDpi = 0u;
1181 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1182 fontClient.GetDpi( horizontalDpi, verticalDpi );
1184 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
1185 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1186 mImpl->mEventData->mIsPlaceholderPixelSize = true; // Font size flag
1191 mImpl->RequestRelayout();
1195 float Controller::GetPlaceholderTextFontSize( FontSizeType type ) const
1198 if( NULL != mImpl->mEventData )
1204 if( NULL != mImpl->mEventData->mPlaceholderFont )
1206 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize;
1210 // If the placeholder text font size is not set, then return the default font size.
1211 value = GetDefaultFontSize( POINT_SIZE );
1217 if( NULL != mImpl->mEventData->mPlaceholderFont )
1219 // Pixel size = Point size * DPI / 72.f
1220 unsigned int horizontalDpi = 0u;
1221 unsigned int verticalDpi = 0u;
1222 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1223 fontClient.GetDpi( horizontalDpi, verticalDpi );
1225 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1229 // If the placeholder text font size is not set, then return the default font size.
1230 value = GetDefaultFontSize( PIXEL_SIZE );
1241 void Controller::SetDefaultColor( const Vector4& color )
1243 mImpl->mTextColor = color;
1245 if( !mImpl->IsShowingPlaceholderText() )
1247 mImpl->mModel->mVisualModel->SetTextColor( color );
1249 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
1251 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1253 mImpl->RequestRelayout();
1257 const Vector4& Controller::GetDefaultColor() const
1259 return mImpl->mTextColor;
1262 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
1264 if( NULL != mImpl->mEventData )
1266 mImpl->mEventData->mPlaceholderTextColor = textColor;
1269 if( mImpl->IsShowingPlaceholderText() )
1271 mImpl->mModel->mVisualModel->SetTextColor( textColor );
1272 mImpl->RequestRelayout();
1276 const Vector4& Controller::GetPlaceholderTextColor() const
1278 if( NULL != mImpl->mEventData )
1280 return mImpl->mEventData->mPlaceholderTextColor;
1283 return Color::BLACK;
1286 void Controller::SetShadowOffset( const Vector2& shadowOffset )
1288 mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
1290 mImpl->RequestRelayout();
1293 const Vector2& Controller::GetShadowOffset() const
1295 return mImpl->mModel->mVisualModel->GetShadowOffset();
1298 void Controller::SetShadowColor( const Vector4& shadowColor )
1300 mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
1302 mImpl->RequestRelayout();
1305 const Vector4& Controller::GetShadowColor() const
1307 return mImpl->mModel->mVisualModel->GetShadowColor();
1310 void Controller::SetShadowBlurRadius( const float& shadowBlurRadius )
1312 if ( fabsf( GetShadowBlurRadius() - shadowBlurRadius ) > Math::MACHINE_EPSILON_1 )
1314 mImpl->mModel->mVisualModel->SetShadowBlurRadius( shadowBlurRadius );
1316 mImpl->RequestRelayout();
1320 const float& Controller::GetShadowBlurRadius() const
1322 return mImpl->mModel->mVisualModel->GetShadowBlurRadius();
1325 void Controller::SetUnderlineColor( const Vector4& color )
1327 mImpl->mModel->mVisualModel->SetUnderlineColor( color );
1329 mImpl->RequestRelayout();
1332 const Vector4& Controller::GetUnderlineColor() const
1334 return mImpl->mModel->mVisualModel->GetUnderlineColor();
1337 void Controller::SetUnderlineEnabled( bool enabled )
1339 mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
1341 mImpl->RequestRelayout();
1344 bool Controller::IsUnderlineEnabled() const
1346 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
1349 void Controller::SetUnderlineHeight( float height )
1351 mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
1353 mImpl->RequestRelayout();
1356 float Controller::GetUnderlineHeight() const
1358 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
1361 void Controller::SetOutlineColor( const Vector4& color )
1363 mImpl->mModel->mVisualModel->SetOutlineColor( color );
1365 mImpl->RequestRelayout();
1368 const Vector4& Controller::GetOutlineColor() const
1370 return mImpl->mModel->mVisualModel->GetOutlineColor();
1373 void Controller::SetOutlineWidth( uint16_t width )
1375 mImpl->mModel->mVisualModel->SetOutlineWidth( width );
1377 mImpl->RequestRelayout();
1380 uint16_t Controller::GetOutlineWidth() const
1382 return mImpl->mModel->mVisualModel->GetOutlineWidth();
1385 void Controller::SetBackgroundColor( const Vector4& color )
1387 mImpl->mModel->mVisualModel->SetBackgroundColor( color );
1389 mImpl->RequestRelayout();
1392 const Vector4& Controller::GetBackgroundColor() const
1394 return mImpl->mModel->mVisualModel->GetBackgroundColor();
1397 void Controller::SetBackgroundEnabled( bool enabled )
1399 mImpl->mModel->mVisualModel->SetBackgroundEnabled( enabled );
1401 mImpl->RequestRelayout();
1404 bool Controller::IsBackgroundEnabled() const
1406 return mImpl->mModel->mVisualModel->IsBackgroundEnabled();
1409 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
1411 if( NULL == mImpl->mEmbossDefaults )
1413 mImpl->mEmbossDefaults = new EmbossDefaults();
1416 mImpl->mEmbossDefaults->properties = embossProperties;
1419 const std::string& Controller::GetDefaultEmbossProperties() const
1421 if( NULL != mImpl->mEmbossDefaults )
1423 return mImpl->mEmbossDefaults->properties;
1426 return EMPTY_STRING;
1429 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
1431 if( NULL == mImpl->mOutlineDefaults )
1433 mImpl->mOutlineDefaults = new OutlineDefaults();
1436 mImpl->mOutlineDefaults->properties = outlineProperties;
1439 const std::string& Controller::GetDefaultOutlineProperties() const
1441 if( NULL != mImpl->mOutlineDefaults )
1443 return mImpl->mOutlineDefaults->properties;
1446 return EMPTY_STRING;
1449 bool Controller::SetDefaultLineSpacing( float lineSpacing )
1451 if( std::fabs( lineSpacing - mImpl->mLayoutEngine.GetDefaultLineSpacing() ) > Math::MACHINE_EPSILON_1000 )
1453 mImpl->mLayoutEngine.SetDefaultLineSpacing(lineSpacing);
1454 mImpl->mRecalculateNaturalSize = true;
1460 float Controller::GetDefaultLineSpacing() const
1462 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
1465 bool Controller::SetDefaultLineSize( float lineSize )
1467 if( std::fabs( lineSize - mImpl->mLayoutEngine.GetDefaultLineSize() ) > Math::MACHINE_EPSILON_1000 )
1469 mImpl->mLayoutEngine.SetDefaultLineSize(lineSize);
1470 mImpl->mRecalculateNaturalSize = true;
1476 float Controller::GetDefaultLineSize() const
1478 return mImpl->mLayoutEngine.GetDefaultLineSize();
1481 void Controller::SetInputColor( const Vector4& color )
1483 if( NULL != mImpl->mEventData )
1485 mImpl->mEventData->mInputStyle.textColor = color;
1486 mImpl->mEventData->mInputStyle.isDefaultColor = false;
1488 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1490 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
1492 // Get start and end position of selection
1493 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
1494 const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
1496 // Add the color run.
1497 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1498 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
1500 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
1501 colorRun.color = color;
1502 colorRun.characterRun.characterIndex = startOfSelectedText;
1503 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1505 // Request to relayout.
1506 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1507 mImpl->RequestRelayout();
1509 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1510 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1511 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1516 const Vector4& Controller::GetInputColor() const
1518 if( NULL != mImpl->mEventData )
1520 return mImpl->mEventData->mInputStyle.textColor;
1523 // Return the default text's color if there is no EventData.
1524 return mImpl->mTextColor;
1528 void Controller::SetInputFontFamily( const std::string& fontFamily )
1530 if( NULL != mImpl->mEventData )
1532 mImpl->mEventData->mInputStyle.familyName = fontFamily;
1533 mImpl->mEventData->mInputStyle.isFamilyDefined = true;
1535 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1537 CharacterIndex startOfSelectedText = 0u;
1538 Length lengthOfSelectedText = 0u;
1540 if( EventData::SELECTING == mImpl->mEventData->mState )
1542 // Update a font description run for the selecting state.
1543 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1544 mImpl->mModel->mLogicalModel,
1545 startOfSelectedText,
1546 lengthOfSelectedText );
1548 fontDescriptionRun.familyLength = fontFamily.size();
1549 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
1550 memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength );
1551 fontDescriptionRun.familyDefined = true;
1553 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
1555 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1556 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1557 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1561 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
1562 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
1563 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
1566 // Request to relayout.
1567 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1572 UPDATE_LAYOUT_SIZE |
1575 mImpl->mRecalculateNaturalSize = true;
1576 mImpl->RequestRelayout();
1578 // As the font changes, recalculate the handle positions is needed.
1579 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1580 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1581 mImpl->mEventData->mUpdateHighlightBox = true;
1582 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1587 const std::string& Controller::GetInputFontFamily() const
1589 if( NULL != mImpl->mEventData )
1591 return mImpl->mEventData->mInputStyle.familyName;
1594 // Return the default font's family if there is no EventData.
1595 return GetDefaultFontFamily();
1598 void Controller::SetInputFontWeight( FontWeight weight )
1600 if( NULL != mImpl->mEventData )
1602 mImpl->mEventData->mInputStyle.weight = weight;
1603 mImpl->mEventData->mInputStyle.isWeightDefined = true;
1605 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1607 CharacterIndex startOfSelectedText = 0u;
1608 Length lengthOfSelectedText = 0u;
1610 if( EventData::SELECTING == mImpl->mEventData->mState )
1612 // Update a font description run for the selecting state.
1613 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1614 mImpl->mModel->mLogicalModel,
1615 startOfSelectedText,
1616 lengthOfSelectedText );
1618 fontDescriptionRun.weight = weight;
1619 fontDescriptionRun.weightDefined = true;
1621 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1622 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1623 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1627 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
1628 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
1629 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
1632 // Request to relayout.
1633 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1638 UPDATE_LAYOUT_SIZE |
1641 mImpl->mRecalculateNaturalSize = true;
1642 mImpl->RequestRelayout();
1644 // As the font might change, recalculate the handle positions is needed.
1645 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1646 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1647 mImpl->mEventData->mUpdateHighlightBox = true;
1648 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1653 bool Controller::IsInputFontWeightDefined() const
1655 bool defined = false;
1657 if( NULL != mImpl->mEventData )
1659 defined = mImpl->mEventData->mInputStyle.isWeightDefined;
1665 FontWeight Controller::GetInputFontWeight() const
1667 if( NULL != mImpl->mEventData )
1669 return mImpl->mEventData->mInputStyle.weight;
1672 return GetDefaultFontWeight();
1675 void Controller::SetInputFontWidth( FontWidth width )
1677 if( NULL != mImpl->mEventData )
1679 mImpl->mEventData->mInputStyle.width = width;
1680 mImpl->mEventData->mInputStyle.isWidthDefined = true;
1682 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1684 CharacterIndex startOfSelectedText = 0u;
1685 Length lengthOfSelectedText = 0u;
1687 if( EventData::SELECTING == mImpl->mEventData->mState )
1689 // Update a font description run for the selecting state.
1690 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1691 mImpl->mModel->mLogicalModel,
1692 startOfSelectedText,
1693 lengthOfSelectedText );
1695 fontDescriptionRun.width = width;
1696 fontDescriptionRun.widthDefined = true;
1698 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1699 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1700 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1704 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
1705 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
1706 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
1709 // Request to relayout.
1710 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1715 UPDATE_LAYOUT_SIZE |
1718 mImpl->mRecalculateNaturalSize = true;
1719 mImpl->RequestRelayout();
1721 // As the font might change, recalculate the handle positions is needed.
1722 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1723 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1724 mImpl->mEventData->mUpdateHighlightBox = true;
1725 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1730 bool Controller::IsInputFontWidthDefined() const
1732 bool defined = false;
1734 if( NULL != mImpl->mEventData )
1736 defined = mImpl->mEventData->mInputStyle.isWidthDefined;
1742 FontWidth Controller::GetInputFontWidth() const
1744 if( NULL != mImpl->mEventData )
1746 return mImpl->mEventData->mInputStyle.width;
1749 return GetDefaultFontWidth();
1752 void Controller::SetInputFontSlant( FontSlant slant )
1754 if( NULL != mImpl->mEventData )
1756 mImpl->mEventData->mInputStyle.slant = slant;
1757 mImpl->mEventData->mInputStyle.isSlantDefined = true;
1759 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1761 CharacterIndex startOfSelectedText = 0u;
1762 Length lengthOfSelectedText = 0u;
1764 if( EventData::SELECTING == mImpl->mEventData->mState )
1766 // Update a font description run for the selecting state.
1767 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1768 mImpl->mModel->mLogicalModel,
1769 startOfSelectedText,
1770 lengthOfSelectedText );
1772 fontDescriptionRun.slant = slant;
1773 fontDescriptionRun.slantDefined = true;
1775 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1776 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1777 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1781 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
1782 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
1783 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
1786 // Request to relayout.
1787 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1792 UPDATE_LAYOUT_SIZE |
1795 mImpl->mRecalculateNaturalSize = true;
1796 mImpl->RequestRelayout();
1798 // As the font might change, recalculate the handle positions is needed.
1799 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1800 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1801 mImpl->mEventData->mUpdateHighlightBox = true;
1802 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1807 bool Controller::IsInputFontSlantDefined() const
1809 bool defined = false;
1811 if( NULL != mImpl->mEventData )
1813 defined = mImpl->mEventData->mInputStyle.isSlantDefined;
1819 FontSlant Controller::GetInputFontSlant() const
1821 if( NULL != mImpl->mEventData )
1823 return mImpl->mEventData->mInputStyle.slant;
1826 return GetDefaultFontSlant();
1829 void Controller::SetInputFontPointSize( float size )
1831 if( NULL != mImpl->mEventData )
1833 mImpl->mEventData->mInputStyle.size = size;
1834 mImpl->mEventData->mInputStyle.isSizeDefined = true;
1836 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1838 CharacterIndex startOfSelectedText = 0u;
1839 Length lengthOfSelectedText = 0u;
1841 if( EventData::SELECTING == mImpl->mEventData->mState )
1843 // Update a font description run for the selecting state.
1844 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1845 mImpl->mModel->mLogicalModel,
1846 startOfSelectedText,
1847 lengthOfSelectedText );
1849 fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
1850 fontDescriptionRun.sizeDefined = true;
1852 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1853 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1854 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1858 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
1859 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
1860 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
1863 // Request to relayout.
1864 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1869 UPDATE_LAYOUT_SIZE |
1872 mImpl->mRecalculateNaturalSize = true;
1873 mImpl->RequestRelayout();
1875 // As the font might change, recalculate the handle positions is needed.
1876 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1877 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1878 mImpl->mEventData->mUpdateHighlightBox = true;
1879 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1884 float Controller::GetInputFontPointSize() const
1886 if( NULL != mImpl->mEventData )
1888 return mImpl->mEventData->mInputStyle.size;
1891 // Return the default font's point size if there is no EventData.
1892 return GetDefaultFontSize( Text::Controller::POINT_SIZE );
1895 void Controller::SetInputLineSpacing( float lineSpacing )
1897 if( NULL != mImpl->mEventData )
1899 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1900 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1904 float Controller::GetInputLineSpacing() const
1906 if( NULL != mImpl->mEventData )
1908 return mImpl->mEventData->mInputStyle.lineSpacing;
1914 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1916 if( NULL != mImpl->mEventData )
1918 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1922 const std::string& Controller::GetInputShadowProperties() const
1924 if( NULL != mImpl->mEventData )
1926 return mImpl->mEventData->mInputStyle.shadowProperties;
1929 return EMPTY_STRING;
1932 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1934 if( NULL != mImpl->mEventData )
1936 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1940 const std::string& Controller::GetInputUnderlineProperties() const
1942 if( NULL != mImpl->mEventData )
1944 return mImpl->mEventData->mInputStyle.underlineProperties;
1947 return EMPTY_STRING;
1950 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
1952 if( NULL != mImpl->mEventData )
1954 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1958 const std::string& Controller::GetInputEmbossProperties() const
1960 if( NULL != mImpl->mEventData )
1962 return mImpl->mEventData->mInputStyle.embossProperties;
1965 return GetDefaultEmbossProperties();
1968 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
1970 if( NULL != mImpl->mEventData )
1972 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1976 const std::string& Controller::GetInputOutlineProperties() const
1978 if( NULL != mImpl->mEventData )
1980 return mImpl->mEventData->mInputStyle.outlineProperties;
1983 return GetDefaultOutlineProperties();
1986 void Controller::SetInputModePassword( bool passwordInput )
1988 if( NULL != mImpl->mEventData )
1990 mImpl->mEventData->mPasswordInput = passwordInput;
1994 bool Controller::IsInputModePassword()
1996 if( NULL != mImpl->mEventData )
1998 return mImpl->mEventData->mPasswordInput;
2003 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
2005 if( NULL != mImpl->mEventData )
2007 mImpl->mEventData->mDoubleTapAction = action;
2011 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
2013 NoTextTap::Action action = NoTextTap::NO_ACTION;
2015 if( NULL != mImpl->mEventData )
2017 action = mImpl->mEventData->mDoubleTapAction;
2023 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
2025 if( NULL != mImpl->mEventData )
2027 mImpl->mEventData->mLongPressAction = action;
2031 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
2033 NoTextTap::Action action = NoTextTap::NO_ACTION;
2035 if( NULL != mImpl->mEventData )
2037 action = mImpl->mEventData->mLongPressAction;
2043 bool Controller::IsUnderlineSetByString()
2045 return mImpl->mUnderlineSetByString;
2048 void Controller::UnderlineSetByString( bool setByString )
2050 mImpl->mUnderlineSetByString = setByString;
2053 bool Controller::IsShadowSetByString()
2055 return mImpl->mShadowSetByString;
2058 void Controller::ShadowSetByString( bool setByString )
2060 mImpl->mShadowSetByString = setByString;
2063 bool Controller::IsOutlineSetByString()
2065 return mImpl->mOutlineSetByString;
2068 void Controller::OutlineSetByString( bool setByString )
2070 mImpl->mOutlineSetByString = setByString;
2073 bool Controller::IsFontStyleSetByString()
2075 return mImpl->mFontStyleSetByString;
2078 void Controller::FontStyleSetByString( bool setByString )
2080 mImpl->mFontStyleSetByString = setByString;
2083 // public : Queries & retrieves.
2085 Layout::Engine& Controller::GetLayoutEngine()
2087 return mImpl->mLayoutEngine;
2090 View& Controller::GetView()
2092 return mImpl->mView;
2095 Vector3 Controller::GetNaturalSize()
2097 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
2098 Vector3 naturalSize;
2100 // Make sure the model is up-to-date before layouting
2101 ProcessModifyEvents();
2103 if( mImpl->mRecalculateNaturalSize )
2105 // Operations that can be done only once until the text changes.
2106 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2112 GET_GLYPH_METRICS );
2114 // Set the update info to relayout the whole text.
2115 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2116 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2118 // Make sure the model is up-to-date before layouting
2119 mImpl->UpdateModel( onlyOnceOperations );
2121 // Layout the text for the new width.
2122 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT | REORDER );
2124 // Store the actual control's size to restore later.
2125 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
2127 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
2128 static_cast<OperationsMask>( onlyOnceOperations |
2130 naturalSize.GetVectorXY() );
2132 // Do not do again the only once operations.
2133 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2135 // Do the size related operations again.
2136 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
2139 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
2141 // Stores the natural size to avoid recalculate it again
2142 // unless the text/style changes.
2143 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
2145 mImpl->mRecalculateNaturalSize = false;
2147 // Clear the update info. This info will be set the next time the text is updated.
2148 mImpl->mTextUpdateInfo.Clear();
2149 mImpl->mTextUpdateInfo.mClearAll = true;
2151 // Restore the actual control's size.
2152 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
2154 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
2158 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
2160 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
2163 naturalSize.x = ConvertToEven( naturalSize.x );
2164 naturalSize.y = ConvertToEven( naturalSize.y );
2169 bool Controller::CheckForTextFit( float pointSize, Size& layoutSize )
2172 mImpl->mFontDefaults->mFitPointSize = pointSize;
2173 mImpl->mFontDefaults->sizeDefined = true;
2176 // Operations that can be done only once until the text changes.
2177 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2183 GET_GLYPH_METRICS );
2185 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2186 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2188 // Make sure the model is up-to-date before layouting
2189 mImpl->UpdateModel( onlyOnceOperations );
2191 DoRelayout( Size( layoutSize.width, MAX_FLOAT ),
2192 static_cast<OperationsMask>( onlyOnceOperations | LAYOUT),
2195 // Clear the update info. This info will be set the next time the text is updated.
2196 mImpl->mTextUpdateInfo.Clear();
2197 mImpl->mTextUpdateInfo.mClearAll = true;
2199 if( textSize.width > layoutSize.width || textSize.height > layoutSize.height )
2206 void Controller::FitPointSizeforLayout( Size layoutSize )
2208 const OperationsMask operations = mImpl->mOperationsPending;
2209 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) || mImpl->mTextFitContentSize != layoutSize )
2211 bool actualellipsis = mImpl->mModel->mElideEnabled;
2212 float minPointSize = mImpl->mTextFitMinSize;
2213 float maxPointSize = mImpl->mTextFitMaxSize;
2214 float pointInterval = mImpl->mTextFitStepSize;
2216 mImpl->mModel->mElideEnabled = false;
2217 Vector<float> pointSizeArray;
2220 if( pointInterval < 1.f )
2222 mImpl->mTextFitStepSize = pointInterval = 1.0f;
2225 pointSizeArray.Reserve( static_cast< unsigned int >( ceil( ( maxPointSize - minPointSize ) / pointInterval ) ) );
2227 for( float i = minPointSize; i < maxPointSize; i += pointInterval )
2229 pointSizeArray.PushBack( i );
2232 pointSizeArray.PushBack( maxPointSize );
2234 int bestSizeIndex = 0;
2235 int min = bestSizeIndex + 1;
2236 int max = pointSizeArray.Size() - 1;
2239 int destI = ( min + max ) / 2;
2241 if( CheckForTextFit( pointSizeArray[destI], layoutSize ) )
2243 bestSizeIndex = min;
2249 bestSizeIndex = max;
2253 mImpl->mModel->mElideEnabled = actualellipsis;
2254 mImpl->mFontDefaults->mFitPointSize = pointSizeArray[bestSizeIndex];
2255 mImpl->mFontDefaults->sizeDefined = true;
2260 float Controller::GetHeightForWidth( float width )
2262 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
2263 // Make sure the model is up-to-date before layouting
2264 ProcessModifyEvents();
2267 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ||
2268 mImpl->mTextUpdateInfo.mFullRelayoutNeeded ||
2269 mImpl->mTextUpdateInfo.mClearAll )
2271 // Operations that can be done only once until the text changes.
2272 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2278 GET_GLYPH_METRICS );
2280 // Set the update info to relayout the whole text.
2281 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2282 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2284 // Make sure the model is up-to-date before layouting
2285 mImpl->UpdateModel( onlyOnceOperations );
2288 // Layout the text for the new width.
2289 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
2291 // Store the actual control's width.
2292 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
2294 DoRelayout( Size( width, MAX_FLOAT ),
2295 static_cast<OperationsMask>( onlyOnceOperations |
2299 // Do not do again the only once operations.
2300 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2302 // Do the size related operations again.
2303 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
2307 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
2309 // Clear the update info. This info will be set the next time the text is updated.
2310 mImpl->mTextUpdateInfo.Clear();
2311 mImpl->mTextUpdateInfo.mClearAll = true;
2313 // Restore the actual control's width.
2314 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
2316 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
2320 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
2321 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
2324 return layoutSize.height;
2327 int Controller::GetLineCount( float width )
2329 GetHeightForWidth( width );
2330 int numberofLines = mImpl->mModel->GetNumberOfLines();
2331 return numberofLines;
2334 const ModelInterface* const Controller::GetTextModel() const
2336 return mImpl->mModel.Get();
2339 float Controller::GetScrollAmountByUserInput()
2341 float scrollAmount = 0.0f;
2343 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
2345 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
2346 mImpl->mEventData->mCheckScrollAmount = false;
2348 return scrollAmount;
2351 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
2353 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
2356 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
2357 layoutHeight = layout.height;
2358 scrollPosition = mImpl->mModel->mScrollPosition.y;
2359 isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
2363 void Controller::SetHiddenInputOption(const Property::Map& options )
2365 if( NULL == mImpl->mHiddenInput )
2367 mImpl->mHiddenInput = new HiddenText( this );
2369 mImpl->mHiddenInput->SetProperties(options);
2372 void Controller::GetHiddenInputOption(Property::Map& options )
2374 if( NULL != mImpl->mHiddenInput )
2376 mImpl->mHiddenInput->GetProperties(options);
2380 void Controller::SetPlaceholderProperty( const Property::Map& map )
2382 const Property::Map::SizeType count = map.Count();
2384 for( Property::Map::SizeType position = 0; position < count; ++position )
2386 KeyValuePair keyValue = map.GetKeyValue( position );
2387 Property::Key& key = keyValue.first;
2388 Property::Value& value = keyValue.second;
2390 if( key == Toolkit::Text::PlaceHolder::Property::TEXT || key == PLACEHOLDER_TEXT )
2392 std::string text = "";
2394 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
2396 else if( key == Toolkit::Text::PlaceHolder::Property::TEXT_FOCUSED || key == PLACEHOLDER_TEXT_FOCUSED )
2398 std::string text = "";
2400 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
2402 else if( key == Toolkit::Text::PlaceHolder::Property::COLOR || key == PLACEHOLDER_COLOR )
2405 value.Get( textColor );
2406 if( GetPlaceholderTextColor() != textColor )
2408 SetPlaceholderTextColor( textColor );
2411 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_FAMILY || key == PLACEHOLDER_FONT_FAMILY )
2413 std::string fontFamily = "";
2414 value.Get( fontFamily );
2415 SetPlaceholderFontFamily( fontFamily );
2417 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_STYLE || key == PLACEHOLDER_FONT_STYLE )
2419 SetFontStyleProperty( this, value, Text::FontStyle::PLACEHOLDER );
2421 else if( key == Toolkit::Text::PlaceHolder::Property::POINT_SIZE || key == PLACEHOLDER_POINT_SIZE )
2424 value.Get( pointSize );
2425 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
2427 SetPlaceholderTextFontSize( pointSize, Text::Controller::POINT_SIZE );
2430 else if( key == Toolkit::Text::PlaceHolder::Property::PIXEL_SIZE || key == PLACEHOLDER_PIXEL_SIZE )
2433 value.Get( pixelSize );
2434 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
2436 SetPlaceholderTextFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
2439 else if( key == Toolkit::Text::PlaceHolder::Property::ELLIPSIS || key == PLACEHOLDER_ELLIPSIS )
2442 value.Get( ellipsis );
2443 SetPlaceholderTextElideEnabled( ellipsis );
2448 void Controller::GetPlaceholderProperty( Property::Map& map )
2450 if( NULL != mImpl->mEventData )
2452 if( !mImpl->mEventData->mPlaceholderTextActive.empty() )
2454 map[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = mImpl->mEventData->mPlaceholderTextActive;
2456 if( !mImpl->mEventData->mPlaceholderTextInactive.empty() )
2458 map[ Text::PlaceHolder::Property::TEXT ] = mImpl->mEventData->mPlaceholderTextInactive;
2461 map[ Text::PlaceHolder::Property::COLOR ] = mImpl->mEventData->mPlaceholderTextColor;
2462 map[ Text::PlaceHolder::Property::FONT_FAMILY ] = GetPlaceholderFontFamily();
2464 Property::Value fontStyleMapGet;
2465 GetFontStyleProperty( this, fontStyleMapGet, Text::FontStyle::PLACEHOLDER );
2466 map[ Text::PlaceHolder::Property::FONT_STYLE ] = fontStyleMapGet;
2468 // Choose font size : POINT_SIZE or PIXEL_SIZE
2469 if( !mImpl->mEventData->mIsPlaceholderPixelSize )
2471 map[ Text::PlaceHolder::Property::POINT_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE );
2475 map[ Text::PlaceHolder::Property::PIXEL_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE );
2478 if( mImpl->mEventData->mPlaceholderEllipsisFlag )
2480 map[ Text::PlaceHolder::Property::ELLIPSIS ] = IsPlaceholderTextElideEnabled();
2485 Toolkit::DevelText::TextDirection::Type Controller::GetTextDirection()
2487 // Make sure the model is up-to-date before layouting
2488 ProcessModifyEvents();
2490 if ( mImpl->mUpdateTextDirection )
2492 // Operations that can be done only once until the text changes.
2493 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2499 GET_GLYPH_METRICS );
2501 // Set the update info to relayout the whole text.
2502 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2503 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2505 // Make sure the model is up-to-date before layouting
2506 mImpl->UpdateModel( onlyOnceOperations );
2508 Vector3 naturalSize;
2509 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
2510 static_cast<OperationsMask>( onlyOnceOperations |
2511 LAYOUT | REORDER | UPDATE_DIRECTION ),
2512 naturalSize.GetVectorXY() );
2514 // Do not do again the only once operations.
2515 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2517 // Clear the update info. This info will be set the next time the text is updated.
2518 mImpl->mTextUpdateInfo.Clear();
2520 // FullRelayoutNeeded should be true because DoRelayout is MAX_FLOAT, MAX_FLOAT.
2521 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2523 mImpl->mUpdateTextDirection = false;
2526 return mImpl->mIsTextDirectionRTL ? Toolkit::DevelText::TextDirection::RIGHT_TO_LEFT : Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT;
2529 Toolkit::DevelText::VerticalLineAlignment::Type Controller::GetVerticalLineAlignment() const
2531 return mImpl->mModel->GetVerticalLineAlignment();
2534 void Controller::SetVerticalLineAlignment( Toolkit::DevelText::VerticalLineAlignment::Type alignment )
2536 mImpl->mModel->mVerticalLineAlignment = alignment;
2539 // public : Relayout.
2541 Controller::UpdateTextType Controller::Relayout( const Size& size, Dali::LayoutDirection::Type layoutDirection )
2543 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
2545 UpdateTextType updateTextType = NONE_UPDATED;
2547 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
2549 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
2551 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
2552 updateTextType = MODEL_UPDATED;
2555 // Clear the update info. This info will be set the next time the text is updated.
2556 mImpl->mTextUpdateInfo.Clear();
2558 // Not worth to relayout if width or height is equal to zero.
2559 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
2561 return updateTextType;
2564 // Whether a new size has been set.
2565 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
2569 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
2571 if( ( 0 == mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd ) &&
2572 ( 0 == mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) &&
2573 ( ( mImpl->mModel->mVisualModel->mControlSize.width < Math::MACHINE_EPSILON_1000 ) || ( mImpl->mModel->mVisualModel->mControlSize.height < Math::MACHINE_EPSILON_1000 ) ) )
2575 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
2578 // Layout operations that need to be done if the size changes.
2579 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2582 UPDATE_LAYOUT_SIZE |
2584 // Set the update info to relayout the whole text.
2585 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2586 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2588 // Store the size used to layout the text.
2589 mImpl->mModel->mVisualModel->mControlSize = size;
2592 // Whether there are modify events.
2593 if( 0u != mImpl->mModifyEvents.Count() )
2595 // Style operations that need to be done if the text is modified.
2596 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2600 // Set the update info to elide the text.
2601 if( mImpl->mModel->mElideEnabled ||
2602 ( ( NULL != mImpl->mEventData ) && mImpl->mEventData->mIsPlaceholderElideEnabled ) )
2604 // Update Text layout for applying elided
2605 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2608 UPDATE_LAYOUT_SIZE |
2610 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2611 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2614 if( mImpl->mModel->mMatchSystemLanguageDirection && mImpl->mLayoutDirection != layoutDirection )
2616 // Clear the update info. This info will be set the next time the text is updated.
2617 mImpl->mTextUpdateInfo.mClearAll = true;
2618 // Apply modifications to the model
2619 // Shape the text again is needed because characters like '()[]{}' have to be mirrored and the glyphs generated again.
2620 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2627 mImpl->mLayoutDirection = layoutDirection;
2630 // Make sure the model is up-to-date before layouting.
2631 ProcessModifyEvents();
2632 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
2636 updated = DoRelayout( size,
2637 mImpl->mOperationsPending,
2638 layoutSize ) || updated;
2643 updateTextType = MODEL_UPDATED;
2646 // Do not re-do any operation until something changes.
2647 mImpl->mOperationsPending = NO_OPERATION;
2648 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
2650 // Whether the text control is editable
2651 const bool isEditable = NULL != mImpl->mEventData;
2653 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
2655 if( newSize && isEditable )
2657 offset = mImpl->mModel->mScrollPosition;
2660 if( !isEditable || !IsMultiLineEnabled() )
2662 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
2663 CalculateVerticalOffset( size );
2670 // If there is a new size, the scroll position needs to be clamped.
2671 mImpl->ClampHorizontalScroll( layoutSize );
2673 // Update the decorator's positions is needed if there is a new size.
2674 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
2677 // Move the cursor, grab handle etc.
2678 if( mImpl->ProcessInputEvents() )
2680 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
2684 // Clear the update info. This info will be set the next time the text is updated.
2685 mImpl->mTextUpdateInfo.Clear();
2686 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
2688 return updateTextType;
2691 void Controller::RequestRelayout()
2693 mImpl->RequestRelayout();
2696 // public : Input style change signals.
2698 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
2700 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
2703 void Controller::ProcessInputStyleChangedSignals()
2705 if( NULL == mImpl->mEventData )
2711 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
2712 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
2716 const InputStyle::Mask mask = *it;
2718 if( NULL != mImpl->mEditableControlInterface )
2720 // Emit the input style changed signal.
2721 mImpl->mEditableControlInterface->InputStyleChanged( mask );
2725 mImpl->mEventData->mInputStyleChangedQueue.Clear();
2728 // public : Text-input Event Queuing.
2730 void Controller::KeyboardFocusGainEvent()
2732 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
2734 if( NULL != mImpl->mEventData )
2736 if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
2737 ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
2739 mImpl->ChangeState( EventData::EDITING );
2740 mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
2741 mImpl->mEventData->mUpdateInputStyle = true;
2742 mImpl->mEventData->mScrollAfterUpdatePosition = true;
2744 mImpl->NotifyInputMethodContextMultiLineStatus();
2745 if( mImpl->IsShowingPlaceholderText() )
2747 // Show alternative placeholder-text when editing
2748 ShowPlaceholderText();
2751 mImpl->RequestRelayout();
2755 void Controller::KeyboardFocusLostEvent()
2757 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
2759 if( NULL != mImpl->mEventData )
2761 if( EventData::INTERRUPTED != mImpl->mEventData->mState )
2763 mImpl->ChangeState( EventData::INACTIVE );
2765 if( !mImpl->IsShowingRealText() )
2767 // Revert to regular placeholder-text when not editing
2768 ShowPlaceholderText();
2772 mImpl->RequestRelayout();
2775 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
2777 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
2779 bool textChanged = false;
2780 bool relayoutNeeded = false;
2782 if( ( NULL != mImpl->mEventData ) &&
2783 ( keyEvent.state == KeyEvent::Down ) )
2785 int keyCode = keyEvent.keyCode;
2786 const std::string& keyString = keyEvent.keyPressed;
2787 const std::string keyName = keyEvent.keyPressedName;
2789 const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
2791 // Pre-process to separate modifying events from non-modifying input events.
2794 // In some platforms arrive key events with no key code.
2798 else if( Dali::DALI_KEY_ESCAPE == keyCode || Dali::DALI_KEY_BACK == keyCode || Dali::DALI_KEY_SEARCH == keyCode )
2803 else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) ||
2804 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
2805 ( Dali::DALI_KEY_CURSOR_UP == keyCode ) ||
2806 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) )
2808 // If don't have any text, do nothing.
2809 if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
2814 uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition;
2815 uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2816 uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition );
2817 uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines();
2819 // Logic to determine whether this text control will lose focus or not.
2820 if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2821 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2822 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) ||
2823 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) ||
2824 ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) ||
2825 ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) )
2827 // Release the active highlight.
2828 if( mImpl->mEventData->mState == EventData::SELECTING )
2830 mImpl->ChangeState( EventData::EDITING );
2832 // Update selection position.
2833 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2834 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2835 mImpl->mEventData->mUpdateCursorPosition = true;
2836 mImpl->RequestRelayout();
2841 mImpl->mEventData->mCheckScrollAmount = true;
2842 Event event( Event::CURSOR_KEY_EVENT );
2843 event.p1.mInt = keyCode;
2844 event.p2.mBool = keyEvent.IsShiftModifier();
2845 mImpl->mEventData->mEventQueue.push_back( event );
2847 // Will request for relayout.
2848 relayoutNeeded = true;
2850 else if ( Dali::DevelKey::DALI_KEY_CONTROL_LEFT == keyCode || Dali::DevelKey::DALI_KEY_CONTROL_RIGHT == keyCode )
2852 // Left or Right Control key event is received before Ctrl-C/V/X key event is received
2853 // If not handle it here, any selected text will be deleted
2858 else if ( keyEvent.IsCtrlModifier() )
2860 bool consumed = false;
2861 if (keyName == KEY_C_NAME)
2863 // Ctrl-C to copy the selected text
2864 TextPopupButtonTouched( Toolkit::TextSelectionPopup::COPY );
2867 else if (keyName == KEY_V_NAME)
2869 // Ctrl-V to paste the copied text
2870 TextPopupButtonTouched( Toolkit::TextSelectionPopup::PASTE );
2873 else if (keyName == KEY_X_NAME)
2875 // Ctrl-X to cut the selected text
2876 TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
2881 else if( ( Dali::DALI_KEY_BACKSPACE == keyCode ) ||
2882 ( Dali::DevelKey::DALI_KEY_DELETE == keyCode ) )
2884 textChanged = DeleteEvent( keyCode );
2886 // Will request for relayout.
2887 relayoutNeeded = true;
2889 else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
2890 IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
2891 IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
2893 // Power key/Menu/Home key behaviour does not allow edit mode to resume.
2894 mImpl->ChangeState( EventData::INACTIVE );
2896 // Will request for relayout.
2897 relayoutNeeded = true;
2899 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2901 else if( ( Dali::DALI_KEY_SHIFT_LEFT == keyCode ) || ( Dali::DALI_KEY_SHIFT_RIGHT == keyCode ) )
2903 // 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
2904 // and a character is typed after the type of a upper case latin character.
2909 else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
2911 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2917 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
2919 if( !keyString.empty() )
2921 // InputMethodContext is no longer handling key-events
2922 mImpl->ClearPreEditFlag();
2924 InsertText( keyString, COMMIT );
2928 // Will request for relayout.
2929 relayoutNeeded = true;
2934 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
2935 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
2937 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
2938 ( Dali::DALI_KEY_SHIFT_RIGHT != keyCode ) &&
2939 ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
2940 ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
2942 // Should not change the state if the key is the shift send by the InputMethodContext.
2943 // Otherwise, when the state is SELECTING the text controller can't send the right
2944 // surrounding info to the InputMethodContext.
2945 mImpl->ChangeState( EventData::EDITING );
2947 // Will request for relayout.
2948 relayoutNeeded = true;
2951 if( relayoutNeeded )
2953 mImpl->RequestRelayout();
2958 ( NULL != mImpl->mEditableControlInterface ) )
2960 // Do this last since it provides callbacks into application code
2961 mImpl->mEditableControlInterface->TextChanged();
2967 void Controller::TapEvent( unsigned int tapCount, float x, float y )
2969 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
2971 if( NULL != mImpl->mEventData )
2973 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
2974 EventData::State state( mImpl->mEventData->mState );
2975 bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
2977 if( mImpl->IsClipboardVisible() )
2979 if( EventData::INACTIVE == state || EventData::EDITING == state)
2981 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2983 relayoutNeeded = true;
2985 else if( 1u == tapCount )
2987 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
2989 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
2992 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
2994 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2995 relayoutNeeded = true;
2999 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
3001 // Hide placeholder text
3005 if( EventData::INACTIVE == state )
3007 mImpl->ChangeState( EventData::EDITING );
3009 else if( !mImpl->IsClipboardEmpty() )
3011 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
3013 relayoutNeeded = true;
3016 else if( 2u == tapCount )
3018 if( mImpl->mEventData->mSelectionEnabled &&
3019 mImpl->IsShowingRealText() )
3021 relayoutNeeded = true;
3022 mImpl->mEventData->mIsLeftHandleSelected = true;
3023 mImpl->mEventData->mIsRightHandleSelected = true;
3027 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
3028 if( relayoutNeeded )
3030 Event event( Event::TAP_EVENT );
3031 event.p1.mUint = tapCount;
3032 event.p2.mFloat = x;
3033 event.p3.mFloat = y;
3034 mImpl->mEventData->mEventQueue.push_back( event );
3036 mImpl->RequestRelayout();
3040 // Reset keyboard as tap event has occurred.
3041 mImpl->ResetInputMethodContext();
3044 void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
3046 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
3048 if( NULL != mImpl->mEventData )
3050 Event event( Event::PAN_EVENT );
3051 event.p1.mInt = state;
3052 event.p2.mFloat = displacement.x;
3053 event.p3.mFloat = displacement.y;
3054 mImpl->mEventData->mEventQueue.push_back( event );
3056 mImpl->RequestRelayout();
3060 void Controller::LongPressEvent( Gesture::State state, float x, float y )
3062 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
3064 if( ( state == Gesture::Started ) &&
3065 ( NULL != mImpl->mEventData ) )
3067 // The 1st long-press on inactive text-field is treated as tap
3068 if( EventData::INACTIVE == mImpl->mEventData->mState )
3070 mImpl->ChangeState( EventData::EDITING );
3072 Event event( Event::TAP_EVENT );
3074 event.p2.mFloat = x;
3075 event.p3.mFloat = y;
3076 mImpl->mEventData->mEventQueue.push_back( event );
3078 mImpl->RequestRelayout();
3080 else if( !mImpl->IsShowingRealText() )
3082 Event event( Event::LONG_PRESS_EVENT );
3083 event.p1.mInt = state;
3084 event.p2.mFloat = x;
3085 event.p3.mFloat = y;
3086 mImpl->mEventData->mEventQueue.push_back( event );
3087 mImpl->RequestRelayout();
3089 else if( !mImpl->IsClipboardVisible() )
3091 // Reset the InputMethodContext to commit the pre-edit before selecting the text.
3092 mImpl->ResetInputMethodContext();
3094 Event event( Event::LONG_PRESS_EVENT );
3095 event.p1.mInt = state;
3096 event.p2.mFloat = x;
3097 event.p3.mFloat = y;
3098 mImpl->mEventData->mEventQueue.push_back( event );
3099 mImpl->RequestRelayout();
3101 mImpl->mEventData->mIsLeftHandleSelected = true;
3102 mImpl->mEventData->mIsRightHandleSelected = true;
3107 void Controller::SelectEvent( float x, float y, SelectionType selectType )
3109 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
3111 if( NULL != mImpl->mEventData )
3113 if( selectType == SelectionType::ALL )
3115 Event event( Event::SELECT_ALL );
3116 mImpl->mEventData->mEventQueue.push_back( event );
3118 else if( selectType == SelectionType::NONE )
3120 Event event( Event::SELECT_NONE );
3121 mImpl->mEventData->mEventQueue.push_back( event );
3125 Event event( Event::SELECT );
3126 event.p2.mFloat = x;
3127 event.p3.mFloat = y;
3128 mImpl->mEventData->mEventQueue.push_back( event );
3131 mImpl->mEventData->mCheckScrollAmount = true;
3132 mImpl->mEventData->mIsLeftHandleSelected = true;
3133 mImpl->mEventData->mIsRightHandleSelected = true;
3134 mImpl->RequestRelayout();
3138 InputMethodContext::CallbackData Controller::OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
3140 // Whether the text needs to be relaid-out.
3141 bool requestRelayout = false;
3143 // Whether to retrieve the text and cursor position to be sent to the InputMethodContext.
3144 bool retrieveText = false;
3145 bool retrieveCursor = false;
3147 switch( inputMethodContextEvent.eventName )
3149 case InputMethodContext::COMMIT:
3151 InsertText( inputMethodContextEvent.predictiveString, Text::Controller::COMMIT );
3152 requestRelayout = true;
3153 retrieveCursor = true;
3156 case InputMethodContext::PRE_EDIT:
3158 InsertText( inputMethodContextEvent.predictiveString, Text::Controller::PRE_EDIT );
3159 requestRelayout = true;
3160 retrieveCursor = true;
3163 case InputMethodContext::DELETE_SURROUNDING:
3165 const bool textDeleted = RemoveText( inputMethodContextEvent.cursorOffset,
3166 inputMethodContextEvent.numberOfChars,
3167 DONT_UPDATE_INPUT_STYLE );
3171 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3172 !mImpl->IsPlaceholderAvailable() )
3174 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3178 ShowPlaceholderText();
3180 mImpl->mEventData->mUpdateCursorPosition = true;
3181 mImpl->mEventData->mScrollAfterDelete = true;
3183 requestRelayout = true;
3187 case InputMethodContext::GET_SURROUNDING:
3189 retrieveText = true;
3190 retrieveCursor = true;
3193 case InputMethodContext::PRIVATE_COMMAND:
3195 // PRIVATECOMMAND event is just for getting the private command message
3196 retrieveText = true;
3197 retrieveCursor = true;
3200 case InputMethodContext::VOID:
3207 if( requestRelayout )
3209 mImpl->mOperationsPending = ALL_OPERATIONS;
3210 mImpl->RequestRelayout();
3214 CharacterIndex cursorPosition = 0u;
3215 Length numberOfWhiteSpaces = 0u;
3217 if( retrieveCursor )
3219 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
3221 cursorPosition = mImpl->GetLogicalCursorPosition();
3223 if( cursorPosition < numberOfWhiteSpaces )
3225 cursorPosition = 0u;
3229 cursorPosition -= numberOfWhiteSpaces;
3235 if( !mImpl->IsShowingPlaceholderText() )
3237 // Retrieves the normal text string.
3238 mImpl->GetText( numberOfWhiteSpaces, text );
3242 // When the current text is Placeholder Text, the surrounding text should be empty string.
3243 // It means DALi should send empty string ("") to IME.
3248 InputMethodContext::CallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
3250 if( requestRelayout &&
3251 ( NULL != mImpl->mEditableControlInterface ) )
3253 // Do this last since it provides callbacks into application code
3254 mImpl->mEditableControlInterface->TextChanged();
3257 return callbackData;
3260 void Controller::PasteClipboardItemEvent()
3262 // Retrieve the clipboard contents first
3263 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
3264 std::string stringToPaste( notifier.GetContent() );
3266 // Commit the current pre-edit text; the contents of the clipboard should be appended
3267 mImpl->ResetInputMethodContext();
3269 // Temporary disable hiding clipboard
3270 mImpl->SetClipboardHideEnable( false );
3273 PasteText( stringToPaste );
3275 mImpl->SetClipboardHideEnable( true );
3278 // protected : Inherit from Text::Decorator::ControllerInterface.
3280 void Controller::GetTargetSize( Vector2& targetSize )
3282 targetSize = mImpl->mModel->mVisualModel->mControlSize;
3285 void Controller::AddDecoration( Actor& actor, bool needsClipping )
3287 if( NULL != mImpl->mEditableControlInterface )
3289 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
3293 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
3295 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
3297 if( NULL != mImpl->mEventData )
3299 switch( handleType )
3303 Event event( Event::GRAB_HANDLE_EVENT );
3304 event.p1.mUint = state;
3305 event.p2.mFloat = x;
3306 event.p3.mFloat = y;
3308 mImpl->mEventData->mEventQueue.push_back( event );
3311 case LEFT_SELECTION_HANDLE:
3313 Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
3314 event.p1.mUint = state;
3315 event.p2.mFloat = x;
3316 event.p3.mFloat = y;
3318 mImpl->mEventData->mEventQueue.push_back( event );
3321 case RIGHT_SELECTION_HANDLE:
3323 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
3324 event.p1.mUint = state;
3325 event.p2.mFloat = x;
3326 event.p3.mFloat = y;
3328 mImpl->mEventData->mEventQueue.push_back( event );
3331 case LEFT_SELECTION_HANDLE_MARKER:
3332 case RIGHT_SELECTION_HANDLE_MARKER:
3334 // Markers do not move the handles.
3337 case HANDLE_TYPE_COUNT:
3339 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
3343 mImpl->RequestRelayout();
3347 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
3349 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
3351 if( NULL == mImpl->mEventData )
3358 case Toolkit::TextSelectionPopup::CUT:
3360 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
3361 mImpl->mOperationsPending = ALL_OPERATIONS;
3363 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3364 !mImpl->IsPlaceholderAvailable() )
3366 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3370 ShowPlaceholderText();
3373 mImpl->mEventData->mUpdateCursorPosition = true;
3374 mImpl->mEventData->mScrollAfterDelete = true;
3376 mImpl->RequestRelayout();
3378 if( NULL != mImpl->mEditableControlInterface )
3380 mImpl->mEditableControlInterface->TextChanged();
3384 case Toolkit::TextSelectionPopup::COPY:
3386 mImpl->SendSelectionToClipboard( false ); // Text not modified
3388 mImpl->mEventData->mUpdateCursorPosition = true;
3390 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
3393 case Toolkit::TextSelectionPopup::PASTE:
3395 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
3398 case Toolkit::TextSelectionPopup::SELECT:
3400 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
3402 if( mImpl->mEventData->mSelectionEnabled )
3404 // Creates a SELECT event.
3405 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, SelectionType::INTERACTIVE );
3409 case Toolkit::TextSelectionPopup::SELECT_ALL:
3411 // Creates a SELECT_ALL event
3412 SelectEvent( 0.f, 0.f, SelectionType::ALL );
3415 case Toolkit::TextSelectionPopup::CLIPBOARD:
3417 mImpl->ShowClipboard();
3420 case Toolkit::TextSelectionPopup::NONE:
3428 void Controller::DisplayTimeExpired()
3430 mImpl->mEventData->mUpdateCursorPosition = true;
3431 // Apply modifications to the model
3432 mImpl->mOperationsPending = ALL_OPERATIONS;
3434 mImpl->RequestRelayout();
3437 // private : Update.
3439 void Controller::InsertText( const std::string& text, Controller::InsertType type )
3441 bool removedPrevious = false;
3442 bool removedSelected = false;
3443 bool maxLengthReached = false;
3445 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
3447 if( NULL == mImpl->mEventData )
3452 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
3453 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
3454 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3456 // TODO: At the moment the underline runs are only for pre-edit.
3457 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
3459 // Remove the previous InputMethodContext pre-edit.
3460 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
3462 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
3463 mImpl->mEventData->mPreEditLength,
3464 DONT_UPDATE_INPUT_STYLE );
3466 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
3467 mImpl->mEventData->mPreEditLength = 0u;
3471 // Remove the previous Selection.
3472 removedSelected = RemoveSelectedText();
3476 Vector<Character> utf32Characters;
3477 Length characterCount = 0u;
3481 // Convert text into UTF-32
3482 utf32Characters.Resize( text.size() );
3484 // This is a bit horrible but std::string returns a (signed) char*
3485 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
3487 // Transform a text array encoded in utf8 into an array encoded in utf32.
3488 // It returns the actual number of characters.
3489 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
3490 utf32Characters.Resize( characterCount );
3492 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
3493 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
3496 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
3498 // The placeholder text is no longer needed
3499 if( mImpl->IsShowingPlaceholderText() )
3504 mImpl->ChangeState( EventData::EDITING );
3506 // Handle the InputMethodContext (predicitive text) state changes
3507 if( COMMIT == type )
3509 // InputMethodContext is no longer handling key-events
3510 mImpl->ClearPreEditFlag();
3514 if( !mImpl->mEventData->mPreEditFlag )
3516 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
3518 // Record the start of the pre-edit text
3519 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
3522 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
3523 mImpl->mEventData->mPreEditFlag = true;
3525 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3528 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
3530 // Restrict new text to fit within Maximum characters setting.
3531 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
3532 maxLengthReached = ( characterCount > maxSizeOfNewText );
3534 // The cursor position.
3535 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3537 // Update the text's style.
3539 // Updates the text style runs by adding characters.
3540 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
3542 // Get the character index from the cursor index.
3543 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
3545 // Retrieve the text's style for the given index.
3547 mImpl->RetrieveDefaultInputStyle( style );
3548 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
3550 // Whether to add a new text color run.
3551 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor ) && !mImpl->mEventData->mInputStyle.isDefaultColor;
3553 // Whether to add a new font run.
3554 const bool addFontNameRun = ( style.familyName != mImpl->mEventData->mInputStyle.familyName ) && mImpl->mEventData->mInputStyle.isFamilyDefined;
3555 const bool addFontWeightRun = ( style.weight != mImpl->mEventData->mInputStyle.weight ) && mImpl->mEventData->mInputStyle.isWeightDefined;
3556 const bool addFontWidthRun = ( style.width != mImpl->mEventData->mInputStyle.width ) && mImpl->mEventData->mInputStyle.isWidthDefined;
3557 const bool addFontSlantRun = ( style.slant != mImpl->mEventData->mInputStyle.slant ) && mImpl->mEventData->mInputStyle.isSlantDefined;
3558 const bool addFontSizeRun = ( style.size != mImpl->mEventData->mInputStyle.size ) && mImpl->mEventData->mInputStyle.isSizeDefined ;
3563 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
3564 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
3566 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
3567 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
3568 colorRun.characterRun.characterIndex = cursorIndex;
3569 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3572 if( addFontNameRun ||
3578 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
3579 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
3581 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
3583 if( addFontNameRun )
3585 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
3586 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
3587 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
3588 fontDescriptionRun.familyDefined = true;
3590 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
3593 if( addFontWeightRun )
3595 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
3596 fontDescriptionRun.weightDefined = true;
3599 if( addFontWidthRun )
3601 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
3602 fontDescriptionRun.widthDefined = true;
3605 if( addFontSlantRun )
3607 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
3608 fontDescriptionRun.slantDefined = true;
3611 if( addFontSizeRun )
3613 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
3614 fontDescriptionRun.sizeDefined = true;
3617 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
3618 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3621 // Insert at current cursor position.
3622 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
3624 if( cursorIndex < numberOfCharactersInModel )
3626 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3630 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3633 // Mark the first paragraph to be updated.
3634 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3636 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3637 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3638 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
3639 mImpl->mTextUpdateInfo.mClearAll = true;
3643 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3644 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
3647 // Update the cursor index.
3648 cursorIndex += maxSizeOfNewText;
3650 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 );
3653 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
3654 mImpl->IsPlaceholderAvailable() )
3656 // Show place-holder if empty after removing the pre-edit text
3657 ShowPlaceholderText();
3658 mImpl->mEventData->mUpdateCursorPosition = true;
3659 mImpl->ClearPreEditFlag();
3661 else if( removedPrevious ||
3663 ( 0 != utf32Characters.Count() ) )
3665 // Queue an inserted event
3666 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
3668 mImpl->mEventData->mUpdateCursorPosition = true;
3669 if( removedSelected )
3671 mImpl->mEventData->mScrollAfterDelete = true;
3675 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3679 if( maxLengthReached )
3681 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
3683 mImpl->ResetInputMethodContext();
3685 if( NULL != mImpl->mEditableControlInterface )
3687 // Do this last since it provides callbacks into application code
3688 mImpl->mEditableControlInterface->MaxLengthReached();
3693 void Controller::PasteText( const std::string& stringToPaste )
3695 InsertText( stringToPaste, Text::Controller::COMMIT );
3696 mImpl->ChangeState( EventData::EDITING );
3697 mImpl->RequestRelayout();
3699 if( NULL != mImpl->mEditableControlInterface )
3701 // Do this last since it provides callbacks into application code
3702 mImpl->mEditableControlInterface->TextChanged();
3706 bool Controller::RemoveText( int cursorOffset,
3707 int numberOfCharacters,
3708 UpdateInputStyleType type )
3710 bool removed = false;
3712 if( NULL == mImpl->mEventData )
3717 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
3718 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
3720 if( !mImpl->IsShowingPlaceholderText() )
3722 // Delete at current cursor position
3723 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
3724 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3726 CharacterIndex cursorIndex = 0;
3728 // Validate the cursor position & number of characters
3729 if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
3731 cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
3734 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
3736 numberOfCharacters = currentText.Count() - cursorIndex;
3739 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.
3740 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
3742 // Mark the paragraphs to be updated.
3743 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3745 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3746 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3747 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
3748 mImpl->mTextUpdateInfo.mClearAll = true;
3752 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3753 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
3756 // Update the input style and remove the text's style before removing the text.
3758 if( UPDATE_INPUT_STYLE == type )
3760 // Keep a copy of the current input style.
3761 InputStyle currentInputStyle;
3762 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
3764 // Set first the default input style.
3765 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
3767 // Update the input style.
3768 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
3770 // Compare if the input style has changed.
3771 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
3773 if( hasInputStyleChanged )
3775 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
3776 // Queue the input style changed signal.
3777 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
3781 // If the number of current text and the number of characters to be deleted are same,
3782 // it means all texts should be removed and all Preedit variables should be initialized.
3783 if( ( currentText.Count() - numberOfCharacters == 0 ) && ( cursorIndex == 0 ) )
3785 mImpl->ClearPreEditFlag();
3788 // Updates the text style runs by removing characters. Runs with no characters are removed.
3789 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
3791 // Remove the characters.
3792 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
3793 Vector<Character>::Iterator last = first + numberOfCharacters;
3795 currentText.Erase( first, last );
3797 // Cursor position retreat
3798 oldCursorIndex = cursorIndex;
3800 mImpl->mEventData->mScrollAfterDelete = true;
3802 if( EventData::INACTIVE == mImpl->mEventData->mState )
3804 mImpl->ChangeState( EventData::EDITING );
3807 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
3815 bool Controller::RemoveSelectedText()
3817 bool textRemoved( false );
3819 if( EventData::SELECTING == mImpl->mEventData->mState )
3821 std::string removedString;
3822 mImpl->RetrieveSelection( removedString, true );
3824 if( !removedString.empty() )
3827 mImpl->ChangeState( EventData::EDITING );
3834 std::string Controller::GetSelectedText()
3837 if( EventData::SELECTING == mImpl->mEventData->mState )
3839 mImpl->RetrieveSelection( text, false );
3844 // private : Relayout.
3846 bool Controller::DoRelayout( const Size& size,
3847 OperationsMask operationsRequired,
3850 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
3851 bool viewUpdated( false );
3853 // Calculate the operations to be done.
3854 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
3856 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
3857 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
3859 // Get the current layout size.
3860 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3862 if( NO_OPERATION != ( LAYOUT & operations ) )
3864 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
3866 // Some vectors with data needed to layout and reorder may be void
3867 // after the first time the text has been laid out.
3868 // Fill the vectors again.
3870 // Calculate the number of glyphs to layout.
3871 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
3872 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
3873 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
3874 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
3876 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
3877 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
3879 // Make sure the index is not out of bound
3880 if ( charactersToGlyph.Count() != glyphsPerCharacter.Count() ||
3881 requestedNumberOfCharacters > charactersToGlyph.Count() ||
3882 ( lastIndex > charactersToGlyph.Count() && charactersToGlyph.Count() > 0u ) )
3884 std::string currentText;
3885 GetText( currentText );
3887 DALI_LOG_ERROR( "Controller::DoRelayout: Attempting to access invalid buffer\n" );
3888 DALI_LOG_ERROR( "Current text is: %s\n", currentText.c_str() );
3889 DALI_LOG_ERROR( "startIndex: %u, lastIndex: %u, requestedNumberOfCharacters: %u, charactersToGlyph.Count = %lu, glyphsPerCharacter.Count = %lu\n", startIndex, lastIndex, requestedNumberOfCharacters, charactersToGlyph.Count(), glyphsPerCharacter.Count());
3894 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
3895 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
3897 if( 0u == totalNumberOfGlyphs )
3899 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3901 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
3904 // Nothing else to do if there is no glyphs.
3905 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
3909 // Set the layout parameters.
3910 Layout::Parameters layoutParameters( size,
3913 // Resize the vector of positions to have the same size than the vector of glyphs.
3914 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
3915 glyphPositions.Resize( totalNumberOfGlyphs );
3917 // Whether the last character is a new paragraph character.
3918 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
3919 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
3920 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
3922 // The initial glyph and the number of glyphs to layout.
3923 layoutParameters.startGlyphIndex = startGlyphIndex;
3924 layoutParameters.numberOfGlyphs = numberOfGlyphs;
3925 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
3926 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
3928 // Update the ellipsis
3929 bool elideTextEnabled = mImpl->mModel->mElideEnabled;
3931 if( NULL != mImpl->mEventData )
3933 if( mImpl->mEventData->mPlaceholderEllipsisFlag && mImpl->IsShowingPlaceholderText() )
3935 elideTextEnabled = mImpl->mEventData->mIsPlaceholderElideEnabled;
3937 else if( EventData::INACTIVE != mImpl->mEventData->mState )
3939 // Disable ellipsis when editing
3940 elideTextEnabled = false;
3943 // Reset the scroll position in inactive state
3944 if( elideTextEnabled && ( mImpl->mEventData->mState == EventData::INACTIVE ) )
3946 ResetScrollPosition();
3950 // Update the visual model.
3951 bool isAutoScrollEnabled = mImpl->mIsAutoScrollEnabled;
3953 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
3956 isAutoScrollEnabled );
3957 mImpl->mIsAutoScrollEnabled = isAutoScrollEnabled;
3959 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
3963 layoutSize = newLayoutSize;
3965 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
3967 mImpl->mIsTextDirectionRTL = false;
3970 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && !mImpl->mModel->mVisualModel->mLines.Empty() )
3972 mImpl->mIsTextDirectionRTL = mImpl->mModel->mVisualModel->mLines[0u].direction;
3975 // Sets the layout size.
3976 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3978 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
3983 if( NO_OPERATION != ( ALIGN & operations ) )
3985 // The laid-out lines.
3986 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
3988 CharacterIndex alignStartIndex = startIndex;
3989 Length alignRequestedNumberOfCharacters = requestedNumberOfCharacters;
3991 // the whole text needs to be full aligned.
3992 // If you do not do a full aligned, only the last line of the multiline input is aligned.
3993 if( mImpl->mEventData && mImpl->mEventData->mUpdateAlignment )
3995 alignStartIndex = 0u;
3996 alignRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
3997 mImpl->mEventData->mUpdateAlignment = false;
4000 // Need to align with the control's size as the text may contain lines
4001 // starting either with left to right text or right to left.
4002 mImpl->mLayoutEngine.Align( size,
4004 alignRequestedNumberOfCharacters,
4005 mImpl->mModel->mHorizontalAlignment,
4007 mImpl->mModel->mAlignmentOffset,
4008 mImpl->mLayoutDirection,
4009 mImpl->mModel->mMatchSystemLanguageDirection );
4013 #if defined(DEBUG_ENABLED)
4014 std::string currentText;
4015 GetText( currentText );
4016 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mIsTextDirectionRTL[%s] [%s]\n", this, (mImpl->mIsTextDirectionRTL)?"true":"false", currentText.c_str() );
4018 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
4022 void Controller::CalculateVerticalOffset( const Size& controlSize )
4024 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
4026 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
4028 // Get the line height of the default font.
4029 layoutSize.height = mImpl->GetDefaultFontLineHeight();
4032 switch( mImpl->mModel->mVerticalAlignment )
4034 case VerticalAlignment::TOP:
4036 mImpl->mModel->mScrollPosition.y = 0.f;
4039 case VerticalAlignment::CENTER:
4041 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
4044 case VerticalAlignment::BOTTOM:
4046 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
4052 // private : Events.
4054 void Controller::ProcessModifyEvents()
4056 Vector<ModifyEvent>& events = mImpl->mModifyEvents;
4058 if( 0u == events.Count() )
4064 for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
4065 endIt = events.End();
4069 const ModifyEvent& event = *it;
4071 if( ModifyEvent::TEXT_REPLACED == event.type )
4073 // A (single) replace event should come first, otherwise we wasted time processing NOOP events
4074 DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
4076 TextReplacedEvent();
4078 else if( ModifyEvent::TEXT_INSERTED == event.type )
4080 TextInsertedEvent();
4082 else if( ModifyEvent::TEXT_DELETED == event.type )
4084 // Placeholder-text cannot be deleted
4085 if( !mImpl->IsShowingPlaceholderText() )
4092 if( NULL != mImpl->mEventData )
4094 // When the text is being modified, delay cursor blinking
4095 mImpl->mEventData->mDecorator->DelayCursorBlink();
4097 // Update selection position after modifying the text
4098 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
4099 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
4102 // Discard temporary text
4106 void Controller::TextReplacedEvent()
4108 // The natural size needs to be re-calculated.
4109 mImpl->mRecalculateNaturalSize = true;
4111 // The text direction needs to be updated.
4112 mImpl->mUpdateTextDirection = true;
4114 // Apply modifications to the model
4115 mImpl->mOperationsPending = ALL_OPERATIONS;
4118 void Controller::TextInsertedEvent()
4120 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
4122 if( NULL == mImpl->mEventData )
4127 mImpl->mEventData->mCheckScrollAmount = true;
4129 // The natural size needs to be re-calculated.
4130 mImpl->mRecalculateNaturalSize = true;
4132 // The text direction needs to be updated.
4133 mImpl->mUpdateTextDirection = true;
4135 // Apply modifications to the model; TODO - Optimize this
4136 mImpl->mOperationsPending = ALL_OPERATIONS;
4139 void Controller::TextDeletedEvent()
4141 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
4143 if( NULL == mImpl->mEventData )
4148 mImpl->mEventData->mCheckScrollAmount = true;
4150 // The natural size needs to be re-calculated.
4151 mImpl->mRecalculateNaturalSize = true;
4153 // The text direction needs to be updated.
4154 mImpl->mUpdateTextDirection = true;
4156 // Apply modifications to the model; TODO - Optimize this
4157 mImpl->mOperationsPending = ALL_OPERATIONS;
4160 bool Controller::DeleteEvent( int keyCode )
4162 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p KeyCode : %d \n", this, keyCode );
4164 bool removed = false;
4166 if( NULL == mImpl->mEventData )
4171 // InputMethodContext is no longer handling key-events
4172 mImpl->ClearPreEditFlag();
4174 if( EventData::SELECTING == mImpl->mEventData->mState )
4176 removed = RemoveSelectedText();
4178 else if( ( mImpl->mEventData->mPrimaryCursorPosition > 0 ) && ( keyCode == Dali::DALI_KEY_BACKSPACE) )
4180 // Remove the character before the current cursor position
4181 removed = RemoveText( -1,
4183 UPDATE_INPUT_STYLE );
4185 else if( keyCode == Dali::DevelKey::DALI_KEY_DELETE )
4187 // Remove the character after the current cursor position
4188 removed = RemoveText( 0,
4190 UPDATE_INPUT_STYLE );
4195 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
4196 !mImpl->IsPlaceholderAvailable() )
4198 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
4202 ShowPlaceholderText();
4204 mImpl->mEventData->mUpdateCursorPosition = true;
4205 mImpl->mEventData->mScrollAfterDelete = true;
4211 // private : Helpers.
4213 void Controller::ResetText()
4216 mImpl->mModel->mLogicalModel->mText.Clear();
4218 // Reset the embedded images buffer.
4219 mImpl->mModel->mLogicalModel->ClearEmbeddedImages();
4221 // We have cleared everything including the placeholder-text
4222 mImpl->PlaceholderCleared();
4224 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4225 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4226 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
4228 // Clear any previous text.
4229 mImpl->mTextUpdateInfo.mClearAll = true;
4231 // The natural size needs to be re-calculated.
4232 mImpl->mRecalculateNaturalSize = true;
4234 // The text direction needs to be updated.
4235 mImpl->mUpdateTextDirection = true;
4237 // Apply modifications to the model
4238 mImpl->mOperationsPending = ALL_OPERATIONS;
4241 void Controller::ShowPlaceholderText()
4243 if( mImpl->IsPlaceholderAvailable() )
4245 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
4247 if( NULL == mImpl->mEventData )
4252 mImpl->mEventData->mIsShowingPlaceholderText = true;
4254 // Disable handles when showing place-holder text
4255 mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
4256 mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
4257 mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
4259 const char* text( NULL );
4262 // TODO - Switch Placeholder text when changing state
4263 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
4264 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
4266 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
4267 size = mImpl->mEventData->mPlaceholderTextActive.size();
4271 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
4272 size = mImpl->mEventData->mPlaceholderTextInactive.size();
4275 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4276 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4278 // Reset model for showing placeholder.
4279 mImpl->mModel->mLogicalModel->mText.Clear();
4280 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
4282 // Convert text into UTF-32
4283 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
4284 utf32Characters.Resize( size );
4286 // This is a bit horrible but std::string returns a (signed) char*
4287 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
4289 // Transform a text array encoded in utf8 into an array encoded in utf32.
4290 // It returns the actual number of characters.
4291 const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
4292 utf32Characters.Resize( characterCount );
4294 // The characters to be added.
4295 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
4297 // Reset the cursor position
4298 mImpl->mEventData->mPrimaryCursorPosition = 0;
4300 // The natural size needs to be re-calculated.
4301 mImpl->mRecalculateNaturalSize = true;
4303 // The text direction needs to be updated.
4304 mImpl->mUpdateTextDirection = true;
4306 // Apply modifications to the model
4307 mImpl->mOperationsPending = ALL_OPERATIONS;
4309 // Update the rest of the model during size negotiation
4310 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
4314 void Controller::ClearFontData()
4316 if( mImpl->mFontDefaults )
4318 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
4321 // Set flags to update the model.
4322 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4323 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4324 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
4326 mImpl->mTextUpdateInfo.mClearAll = true;
4327 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
4328 mImpl->mRecalculateNaturalSize = true;
4330 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
4336 UPDATE_LAYOUT_SIZE |
4341 void Controller::ClearStyleData()
4343 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
4344 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
4347 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
4349 // Reset the cursor position
4350 if( NULL != mImpl->mEventData )
4352 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
4354 // Update the cursor if it's in editing mode.
4355 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
4357 mImpl->mEventData->mUpdateCursorPosition = true;
4362 void Controller::ResetScrollPosition()
4364 if( NULL != mImpl->mEventData )
4366 // Reset the scroll position.
4367 mImpl->mModel->mScrollPosition = Vector2::ZERO;
4368 mImpl->mEventData->mScrollAfterUpdatePosition = true;
4372 void Controller::SetControlInterface( ControlInterface* controlInterface )
4374 mImpl->mControlInterface = controlInterface;
4377 bool Controller::ShouldClearFocusOnEscape() const
4379 return mImpl->mShouldClearFocusOnEscape;
4382 Actor Controller::CreateBackgroundActor()
4384 return mImpl->CreateBackgroundActor();
4387 // private : Private contructors & copy operator.
4389 Controller::Controller()
4392 mImpl = new Controller::Impl( NULL, NULL );
4395 Controller::Controller( ControlInterface* controlInterface )
4397 mImpl = new Controller::Impl( controlInterface, NULL );
4400 Controller::Controller( ControlInterface* controlInterface,
4401 EditableControlInterface* editableControlInterface )
4403 mImpl = new Controller::Impl( controlInterface,
4404 editableControlInterface );
4407 // The copy constructor and operator are left unimplemented.
4409 // protected : Destructor.
4411 Controller::~Controller()
4418 } // namespace Toolkit