2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/text/text-controller.h>
25 #include <dali/public-api/adaptor-framework/key.h>
26 #include <dali/integration-api/debug.h>
27 #include <dali/devel-api/adaptor-framework/clipboard-event-notifier.h>
28 #include <dali/devel-api/text-abstraction/font-client.h>
29 #include <dali/devel-api/adaptor-framework/key-devel.h>
32 #include <dali-toolkit/public-api/controls/text-controls/placeholder-properties.h>
33 #include <dali-toolkit/internal/text/bidirectional-support.h>
34 #include <dali-toolkit/internal/text/character-set-conversion.h>
35 #include <dali-toolkit/internal/text/layouts/layout-parameters.h>
36 #include <dali-toolkit/internal/text/markup-processor.h>
37 #include <dali-toolkit/internal/text/multi-language-support.h>
38 #include <dali-toolkit/internal/text/text-controller-impl.h>
39 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
40 #include <dali-toolkit/internal/text/text-font-style.h>
45 #if defined(DEBUG_ENABLED)
46 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
49 const float MAX_FLOAT = std::numeric_limits<float>::max();
51 const std::string EMPTY_STRING("");
53 const std::string KEY_C_NAME = "c";
54 const std::string KEY_V_NAME = "v";
55 const std::string KEY_X_NAME = "x";
57 const char * const PLACEHOLDER_TEXT = "text";
58 const char * const PLACEHOLDER_TEXT_FOCUSED = "textFocused";
59 const char * const PLACEHOLDER_COLOR = "color";
60 const char * const PLACEHOLDER_FONT_FAMILY = "fontFamily";
61 const char * const PLACEHOLDER_FONT_STYLE = "fontStyle";
62 const char * const PLACEHOLDER_POINT_SIZE = "pointSize";
63 const char * const PLACEHOLDER_PIXEL_SIZE = "pixelSize";
64 const char * const PLACEHOLDER_ELLIPSIS = "ellipsis";
66 float ConvertToEven( float value )
68 int intValue(static_cast<int>( value ));
69 return static_cast<float>( intValue + ( intValue & 1 ) );
72 int ConvertPixelToPint( float pixel )
74 unsigned int horizontalDpi = 0u;
75 unsigned int verticalDpi = 0u;
76 Dali::TextAbstraction::FontClient fontClient = Dali::TextAbstraction::FontClient::Get();
77 fontClient.GetDpi( horizontalDpi, verticalDpi );
79 return ( pixel * 72.f ) / static_cast< float >( horizontalDpi );
94 * @brief Adds a new font description run for the selected text.
96 * The new font parameters are added after the call to this method.
98 * @param[in] eventData The event data pointer.
99 * @param[in] logicalModel The logical model where to add the new font description run.
100 * @param[out] startOfSelectedText Index to the first selected character.
101 * @param[out] lengthOfSelectedText Number of selected characters.
103 FontDescriptionRun& UpdateSelectionFontStyleRun( EventData* eventData,
104 LogicalModelPtr logicalModel,
105 CharacterIndex& startOfSelectedText,
106 Length& lengthOfSelectedText )
108 const bool handlesCrossed = eventData->mLeftSelectionPosition > eventData->mRightSelectionPosition;
110 // Get start and end position of selection
111 startOfSelectedText = handlesCrossed ? eventData->mRightSelectionPosition : eventData->mLeftSelectionPosition;
112 lengthOfSelectedText = ( handlesCrossed ? eventData->mLeftSelectionPosition : eventData->mRightSelectionPosition ) - startOfSelectedText;
115 const VectorBase::SizeType numberOfRuns = logicalModel->mFontDescriptionRuns.Count();
116 logicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
118 FontDescriptionRun& fontDescriptionRun = *( logicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
120 fontDescriptionRun.characterRun.characterIndex = startOfSelectedText;
121 fontDescriptionRun.characterRun.numberOfCharacters = lengthOfSelectedText;
123 // Recalculate the selection highlight as the metrics may have changed.
124 eventData->mUpdateLeftSelectionPosition = true;
125 eventData->mUpdateRightSelectionPosition = true;
126 eventData->mUpdateHighlightBox = true;
128 return fontDescriptionRun;
131 // public : Constructor.
133 ControllerPtr Controller::New()
135 return ControllerPtr( new Controller() );
138 ControllerPtr Controller::New( ControlInterface* controlInterface )
140 return ControllerPtr( new Controller( controlInterface ) );
143 ControllerPtr Controller::New( ControlInterface* controlInterface,
144 EditableControlInterface* editableControlInterface )
146 return ControllerPtr( new Controller( controlInterface,
147 editableControlInterface ) );
150 // public : Configure the text controller.
152 void Controller::EnableTextInput( DecoratorPtr decorator, InputMethodContext& inputMethodContext )
156 delete mImpl->mEventData;
157 mImpl->mEventData = NULL;
159 // Nothing else to do.
163 if( NULL == mImpl->mEventData )
165 mImpl->mEventData = new EventData( decorator, inputMethodContext );
169 void Controller::SetGlyphType( TextAbstraction::GlyphType glyphType )
171 // Metrics for bitmap & vector based glyphs are different
172 mImpl->mMetrics->SetGlyphType( glyphType );
174 // Clear the font-specific data
177 mImpl->RequestRelayout();
180 void Controller::SetMarkupProcessorEnabled( bool enable )
182 if( enable != mImpl->mMarkupProcessorEnabled )
184 //If Text was already set, call the SetText again for enabling or disabling markup
185 mImpl->mMarkupProcessorEnabled = enable;
192 bool Controller::IsMarkupProcessorEnabled() const
194 return mImpl->mMarkupProcessorEnabled;
197 void Controller::SetAutoScrollEnabled( bool enable )
199 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled[%s] SingleBox[%s]-> [%p]\n", (enable)?"true":"false", ( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX)?"true":"false", this );
201 if( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX )
205 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled for SINGLE_LINE_BOX\n" );
206 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
216 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled Disabling autoscroll\n");
217 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
224 mImpl->mIsAutoScrollEnabled = enable;
225 mImpl->RequestRelayout();
229 DALI_LOG_WARNING( "Attempted AutoScrolling on a non SINGLE_LINE_BOX, request ignored\n" );
230 mImpl->mIsAutoScrollEnabled = false;
234 bool Controller::IsAutoScrollEnabled() const
236 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::IsAutoScrollEnabled[%s]\n", mImpl->mIsAutoScrollEnabled?"true":"false" );
238 return mImpl->mIsAutoScrollEnabled;
241 CharacterDirection Controller::GetAutoScrollDirection() const
243 return mImpl->mIsTextDirectionRTL;
246 float Controller::GetAutoScrollLineAlignment() const
250 if( mImpl->mModel->mVisualModel &&
251 ( 0u != mImpl->mModel->mVisualModel->mLines.Count() ) )
253 offset = ( *mImpl->mModel->mVisualModel->mLines.Begin() ).alignmentOffset;
259 void Controller::SetHorizontalScrollEnabled( bool enable )
261 if( ( NULL != mImpl->mEventData ) &&
262 mImpl->mEventData->mDecorator )
264 mImpl->mEventData->mDecorator->SetHorizontalScrollEnabled( enable );
267 bool Controller::IsHorizontalScrollEnabled() const
269 if( ( NULL != mImpl->mEventData ) &&
270 mImpl->mEventData->mDecorator )
272 return mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
278 void Controller::SetVerticalScrollEnabled( bool enable )
280 if( ( NULL != mImpl->mEventData ) &&
281 mImpl->mEventData->mDecorator )
283 if( mImpl->mEventData->mDecorator )
285 mImpl->mEventData->mDecorator->SetVerticalScrollEnabled( enable );
290 bool Controller::IsVerticalScrollEnabled() const
292 if( ( NULL != mImpl->mEventData ) &&
293 mImpl->mEventData->mDecorator )
295 return mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
301 void Controller::SetSmoothHandlePanEnabled( bool enable )
303 if( ( NULL != mImpl->mEventData ) &&
304 mImpl->mEventData->mDecorator )
306 mImpl->mEventData->mDecorator->SetSmoothHandlePanEnabled( enable );
310 bool Controller::IsSmoothHandlePanEnabled() const
312 if( ( NULL != mImpl->mEventData ) &&
313 mImpl->mEventData->mDecorator )
315 return mImpl->mEventData->mDecorator->IsSmoothHandlePanEnabled();
321 void Controller::SetMaximumNumberOfCharacters( Length maxCharacters )
323 mImpl->mMaximumNumberOfCharacters = maxCharacters;
326 int Controller::GetMaximumNumberOfCharacters()
328 return mImpl->mMaximumNumberOfCharacters;
331 void Controller::SetEnableCursorBlink( bool enable )
333 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "TextInput disabled" );
335 if( NULL != mImpl->mEventData )
337 mImpl->mEventData->mCursorBlinkEnabled = enable;
340 mImpl->mEventData->mDecorator )
342 mImpl->mEventData->mDecorator->StopCursorBlink();
347 bool Controller::GetEnableCursorBlink() const
349 if( NULL != mImpl->mEventData )
351 return mImpl->mEventData->mCursorBlinkEnabled;
357 void Controller::SetMultiLineEnabled( bool enable )
359 const Layout::Engine::Type layout = enable ? Layout::Engine::MULTI_LINE_BOX : Layout::Engine::SINGLE_LINE_BOX;
361 if( layout != mImpl->mLayoutEngine.GetLayout() )
363 // Set the layout type.
364 mImpl->mLayoutEngine.SetLayout( layout );
366 // Set the flags to redo the layout operations
367 const OperationsMask layoutOperations = static_cast<OperationsMask>( LAYOUT |
372 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
373 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | layoutOperations );
375 // Need to recalculate natural size
376 mImpl->mRecalculateNaturalSize = true;
378 mImpl->RequestRelayout();
382 bool Controller::IsMultiLineEnabled() const
384 return Layout::Engine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
387 void Controller::SetHorizontalAlignment( Text::HorizontalAlignment::Type alignment )
389 if( alignment != mImpl->mModel->mHorizontalAlignment )
391 // Set the alignment.
392 mImpl->mModel->mHorizontalAlignment = alignment;
394 // Set the flag to redo the alignment operation.
395 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
397 if( mImpl->mEventData )
399 mImpl->mEventData->mUpdateAlignment = true;
401 // Update the cursor if it's in editing mode
402 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
404 mImpl->ChangeState( EventData::EDITING );
405 mImpl->mEventData->mUpdateCursorPosition = true;
409 mImpl->RequestRelayout();
413 Text::HorizontalAlignment::Type Controller::GetHorizontalAlignment() const
415 return mImpl->mModel->mHorizontalAlignment;
418 void Controller::SetVerticalAlignment( VerticalAlignment::Type alignment )
420 if( alignment != mImpl->mModel->mVerticalAlignment )
422 // Set the alignment.
423 mImpl->mModel->mVerticalAlignment = alignment;
425 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
427 mImpl->RequestRelayout();
431 VerticalAlignment::Type Controller::GetVerticalAlignment() const
433 return mImpl->mModel->mVerticalAlignment;
436 bool Controller::IsIgnoreSpacesAfterText() const
438 return mImpl->mModel->mIgnoreSpacesAfterText;
441 void Controller::SetIgnoreSpacesAfterText( bool ignore )
443 mImpl->mModel->mIgnoreSpacesAfterText = ignore;
446 bool Controller::IsMatchSystemLanguageDirection() const
448 return mImpl->mModel->mMatchSystemLanguageDirection;
451 void Controller::SetMatchSystemLanguageDirection( bool match )
453 mImpl->mModel->mMatchSystemLanguageDirection = match;
456 void Controller::SetLayoutDirection( Dali::LayoutDirection::Type layoutDirection )
458 mImpl->mLayoutDirection = layoutDirection;
461 bool Controller::IsShowingRealText() const
463 return mImpl->IsShowingRealText();
467 void Controller::SetLineWrapMode( Text::LineWrap::Mode lineWrapMode )
469 if( lineWrapMode != mImpl->mModel->mLineWrapMode )
471 // Set the text wrap mode.
472 mImpl->mModel->mLineWrapMode = lineWrapMode;
475 // Update Text layout for applying wrap mode
476 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
481 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
482 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
483 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
486 mImpl->RequestRelayout();
490 Text::LineWrap::Mode Controller::GetLineWrapMode() const
492 return mImpl->mModel->mLineWrapMode;
495 void Controller::SetTextElideEnabled( bool enabled )
497 mImpl->mModel->mElideEnabled = enabled;
500 bool Controller::IsTextElideEnabled() const
502 return mImpl->mModel->mElideEnabled;
505 void Controller::SetTextFitEnabled(bool enabled)
507 mImpl->mTextFitEnabled = enabled;
510 bool Controller::IsTextFitEnabled() const
512 return mImpl->mTextFitEnabled;
515 void Controller::SetTextFitMinSize( float minSize, FontSizeType type )
521 mImpl->mTextFitMinSize = minSize;
526 mImpl->mTextFitMinSize = ConvertPixelToPint( minSize );
532 float Controller::GetTextFitMinSize() const
534 return mImpl->mTextFitMinSize;
537 void Controller::SetTextFitMaxSize( float maxSize, FontSizeType type )
543 mImpl->mTextFitMaxSize = maxSize;
548 mImpl->mTextFitMaxSize = ConvertPixelToPint( maxSize );
554 float Controller::GetTextFitMaxSize() const
556 return mImpl->mTextFitMaxSize;
559 void Controller::SetTextFitStepSize( float step, FontSizeType type )
565 mImpl->mTextFitStepSize = step;
570 mImpl->mTextFitStepSize = ConvertPixelToPint( step );
576 float Controller::GetTextFitStepSize() const
578 return mImpl->mTextFitStepSize;
581 void Controller::SetTextFitContentSize(Vector2 size)
583 mImpl->mTextFitContentSize = size;
586 Vector2 Controller::GetTextFitContentSize() const
588 return mImpl->mTextFitContentSize;
591 void Controller::SetPlaceholderTextElideEnabled( bool enabled )
593 mImpl->mEventData->mIsPlaceholderElideEnabled = enabled;
594 mImpl->mEventData->mPlaceholderEllipsisFlag = true;
596 // Update placeholder if there is no text
597 if( mImpl->IsShowingPlaceholderText() ||
598 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
600 ShowPlaceholderText();
604 bool Controller::IsPlaceholderTextElideEnabled() const
606 return mImpl->mEventData->mIsPlaceholderElideEnabled;
609 void Controller::SetSelectionEnabled( bool enabled )
611 mImpl->mEventData->mSelectionEnabled = enabled;
614 bool Controller::IsSelectionEnabled() const
616 return mImpl->mEventData->mSelectionEnabled;
619 void Controller::SetShiftSelectionEnabled( bool enabled )
621 mImpl->mEventData->mShiftSelectionFlag = enabled;
624 bool Controller::IsShiftSelectionEnabled() const
626 return mImpl->mEventData->mShiftSelectionFlag;
629 void Controller::SetGrabHandleEnabled( bool enabled )
631 mImpl->mEventData->mGrabHandleEnabled = enabled;
634 bool Controller::IsGrabHandleEnabled() const
636 return mImpl->mEventData->mGrabHandleEnabled;
639 void Controller::SetGrabHandlePopupEnabled(bool enabled)
641 mImpl->mEventData->mGrabHandlePopupEnabled = enabled;
644 bool Controller::IsGrabHandlePopupEnabled() const
646 return mImpl->mEventData->mGrabHandlePopupEnabled;
651 void Controller::SetText( const std::string& text )
653 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" );
655 // Reset keyboard as text changed
656 mImpl->ResetInputMethodContext();
658 // Remove the previously set text and style.
664 CharacterIndex lastCursorIndex = 0u;
666 if( NULL != mImpl->mEventData )
668 // If popup shown then hide it by switching to Editing state
669 if( ( EventData::SELECTING == mImpl->mEventData->mState ) ||
670 ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
671 ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) ||
672 ( EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState ) )
674 mImpl->ChangeState( EventData::EDITING );
680 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mTextColor );
682 MarkupProcessData markupProcessData( mImpl->mModel->mLogicalModel->mColorRuns,
683 mImpl->mModel->mLogicalModel->mFontDescriptionRuns,
684 mImpl->mModel->mLogicalModel->mEmbeddedItems );
686 Length textSize = 0u;
687 const uint8_t* utf8 = NULL;
688 if( mImpl->mMarkupProcessorEnabled )
690 ProcessMarkupString( text, markupProcessData );
691 textSize = markupProcessData.markupProcessedText.size();
693 // This is a bit horrible but std::string returns a (signed) char*
694 utf8 = reinterpret_cast<const uint8_t*>( markupProcessData.markupProcessedText.c_str() );
698 textSize = text.size();
700 // This is a bit horrible but std::string returns a (signed) char*
701 utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
704 // Convert text into UTF-32
705 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
706 utf32Characters.Resize( textSize );
708 // Transform a text array encoded in utf8 into an array encoded in utf32.
709 // It returns the actual number of characters.
710 Length characterCount = Utf8ToUtf32( utf8, textSize, utf32Characters.Begin() );
711 utf32Characters.Resize( characterCount );
713 DALI_ASSERT_DEBUG( textSize >= characterCount && "Invalid UTF32 conversion length" );
714 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", this, textSize, mImpl->mModel->mLogicalModel->mText.Count() );
716 // The characters to be added.
717 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
719 // To reset the cursor position
720 lastCursorIndex = characterCount;
722 // Update the rest of the model during size negotiation
723 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
725 // The natural size needs to be re-calculated.
726 mImpl->mRecalculateNaturalSize = true;
728 // The text direction needs to be updated.
729 mImpl->mUpdateTextDirection = true;
731 // Apply modifications to the model
732 mImpl->mOperationsPending = ALL_OPERATIONS;
736 ShowPlaceholderText();
739 // Resets the cursor position.
740 ResetCursorPosition( lastCursorIndex );
742 // Scrolls the text to make the cursor visible.
743 ResetScrollPosition();
745 mImpl->RequestRelayout();
747 if( NULL != mImpl->mEventData )
749 // Cancel previously queued events
750 mImpl->mEventData->mEventQueue.clear();
753 // Do this last since it provides callbacks into application code.
754 if( NULL != mImpl->mEditableControlInterface )
756 mImpl->mEditableControlInterface->TextChanged();
760 void Controller::GetText( std::string& text ) const
762 if( !mImpl->IsShowingPlaceholderText() )
764 // Retrieves the text string.
765 mImpl->GetText( 0u, text );
769 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this );
773 void Controller::SetPlaceholderText( PlaceholderType type, const std::string& text )
775 if( NULL != mImpl->mEventData )
777 if( PLACEHOLDER_TYPE_INACTIVE == type )
779 mImpl->mEventData->mPlaceholderTextInactive = text;
783 mImpl->mEventData->mPlaceholderTextActive = text;
786 // Update placeholder if there is no text
787 if( mImpl->IsShowingPlaceholderText() ||
788 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
790 ShowPlaceholderText();
795 void Controller::GetPlaceholderText( PlaceholderType type, std::string& text ) const
797 if( NULL != mImpl->mEventData )
799 if( PLACEHOLDER_TYPE_INACTIVE == type )
801 text = mImpl->mEventData->mPlaceholderTextInactive;
805 text = mImpl->mEventData->mPlaceholderTextActive;
810 void Controller::UpdateAfterFontChange( const std::string& newDefaultFont )
812 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
814 if( !mImpl->mFontDefaults->familyDefined ) // If user defined font then should not update when system font changes
816 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
817 mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
821 mImpl->RequestRelayout();
825 // public : Default style & Input style
827 void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
829 if( NULL == mImpl->mFontDefaults )
831 mImpl->mFontDefaults = new FontDefaults();
834 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
835 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
836 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
838 // Clear the font-specific data
841 mImpl->RequestRelayout();
844 const std::string& Controller::GetDefaultFontFamily() const
846 if( NULL != mImpl->mFontDefaults )
848 return mImpl->mFontDefaults->mFontDescription.family;
854 void Controller::SetPlaceholderFontFamily( const std::string& placeholderTextFontFamily )
856 if( NULL != mImpl->mEventData )
858 if( NULL == mImpl->mEventData->mPlaceholderFont )
860 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
863 mImpl->mEventData->mPlaceholderFont->mFontDescription.family = placeholderTextFontFamily;
864 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetPlaceholderFontFamily %s\n", placeholderTextFontFamily.c_str());
865 mImpl->mEventData->mPlaceholderFont->familyDefined = !placeholderTextFontFamily.empty();
867 mImpl->RequestRelayout();
871 const std::string& Controller::GetPlaceholderFontFamily() const
873 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
875 return mImpl->mEventData->mPlaceholderFont->mFontDescription.family;
881 void Controller::SetDefaultFontWeight( FontWeight weight )
883 if( NULL == mImpl->mFontDefaults )
885 mImpl->mFontDefaults = new FontDefaults();
888 mImpl->mFontDefaults->mFontDescription.weight = weight;
889 mImpl->mFontDefaults->weightDefined = true;
891 // Clear the font-specific data
894 mImpl->RequestRelayout();
897 bool Controller::IsDefaultFontWeightDefined() const
899 if( NULL != mImpl->mFontDefaults )
901 return mImpl->mFontDefaults->weightDefined;
907 FontWeight Controller::GetDefaultFontWeight() const
909 if( NULL != mImpl->mFontDefaults )
911 return mImpl->mFontDefaults->mFontDescription.weight;
914 return TextAbstraction::FontWeight::NORMAL;
917 void Controller::SetPlaceholderTextFontWeight( FontWeight weight )
919 if( NULL != mImpl->mEventData )
921 if( NULL == mImpl->mEventData->mPlaceholderFont )
923 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
926 mImpl->mEventData->mPlaceholderFont->mFontDescription.weight = weight;
927 mImpl->mEventData->mPlaceholderFont->weightDefined = true;
929 mImpl->RequestRelayout();
933 bool Controller::IsPlaceholderTextFontWeightDefined() const
935 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
937 return mImpl->mEventData->mPlaceholderFont->weightDefined;
942 FontWeight Controller::GetPlaceholderTextFontWeight() const
944 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
946 return mImpl->mEventData->mPlaceholderFont->mFontDescription.weight;
949 return TextAbstraction::FontWeight::NORMAL;
952 void Controller::SetDefaultFontWidth( FontWidth width )
954 if( NULL == mImpl->mFontDefaults )
956 mImpl->mFontDefaults = new FontDefaults();
959 mImpl->mFontDefaults->mFontDescription.width = width;
960 mImpl->mFontDefaults->widthDefined = true;
962 // Clear the font-specific data
965 mImpl->RequestRelayout();
968 bool Controller::IsDefaultFontWidthDefined() const
970 if( NULL != mImpl->mFontDefaults )
972 return mImpl->mFontDefaults->widthDefined;
978 FontWidth Controller::GetDefaultFontWidth() const
980 if( NULL != mImpl->mFontDefaults )
982 return mImpl->mFontDefaults->mFontDescription.width;
985 return TextAbstraction::FontWidth::NORMAL;
988 void Controller::SetPlaceholderTextFontWidth( FontWidth width )
990 if( NULL != mImpl->mEventData )
992 if( NULL == mImpl->mEventData->mPlaceholderFont )
994 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
997 mImpl->mEventData->mPlaceholderFont->mFontDescription.width = width;
998 mImpl->mEventData->mPlaceholderFont->widthDefined = true;
1000 mImpl->RequestRelayout();
1004 bool Controller::IsPlaceholderTextFontWidthDefined() const
1006 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1008 return mImpl->mEventData->mPlaceholderFont->widthDefined;
1013 FontWidth Controller::GetPlaceholderTextFontWidth() const
1015 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1017 return mImpl->mEventData->mPlaceholderFont->mFontDescription.width;
1020 return TextAbstraction::FontWidth::NORMAL;
1023 void Controller::SetDefaultFontSlant( FontSlant slant )
1025 if( NULL == mImpl->mFontDefaults )
1027 mImpl->mFontDefaults = new FontDefaults();
1030 mImpl->mFontDefaults->mFontDescription.slant = slant;
1031 mImpl->mFontDefaults->slantDefined = true;
1033 // Clear the font-specific data
1036 mImpl->RequestRelayout();
1039 bool Controller::IsDefaultFontSlantDefined() const
1041 if( NULL != mImpl->mFontDefaults )
1043 return mImpl->mFontDefaults->slantDefined;
1048 FontSlant Controller::GetDefaultFontSlant() const
1050 if( NULL != mImpl->mFontDefaults )
1052 return mImpl->mFontDefaults->mFontDescription.slant;
1055 return TextAbstraction::FontSlant::NORMAL;
1058 void Controller::SetPlaceholderTextFontSlant( FontSlant slant )
1060 if( NULL != mImpl->mEventData )
1062 if( NULL == mImpl->mEventData->mPlaceholderFont )
1064 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
1067 mImpl->mEventData->mPlaceholderFont->mFontDescription.slant = slant;
1068 mImpl->mEventData->mPlaceholderFont->slantDefined = true;
1070 mImpl->RequestRelayout();
1074 bool Controller::IsPlaceholderTextFontSlantDefined() const
1076 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1078 return mImpl->mEventData->mPlaceholderFont->slantDefined;
1083 FontSlant Controller::GetPlaceholderTextFontSlant() const
1085 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1087 return mImpl->mEventData->mPlaceholderFont->mFontDescription.slant;
1090 return TextAbstraction::FontSlant::NORMAL;
1093 void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
1095 if( NULL == mImpl->mFontDefaults )
1097 mImpl->mFontDefaults = new FontDefaults();
1104 mImpl->mFontDefaults->mDefaultPointSize = fontSize;
1105 mImpl->mFontDefaults->sizeDefined = true;
1110 // Point size = Pixel size * 72.f / DPI
1111 unsigned int horizontalDpi = 0u;
1112 unsigned int verticalDpi = 0u;
1113 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1114 fontClient.GetDpi( horizontalDpi, verticalDpi );
1116 mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
1117 mImpl->mFontDefaults->sizeDefined = true;
1122 // Clear the font-specific data
1125 mImpl->RequestRelayout();
1128 float Controller::GetDefaultFontSize( FontSizeType type ) const
1131 if( NULL != mImpl->mFontDefaults )
1137 value = mImpl->mFontDefaults->mDefaultPointSize;
1142 // Pixel size = Point size * DPI / 72.f
1143 unsigned int horizontalDpi = 0u;
1144 unsigned int verticalDpi = 0u;
1145 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1146 fontClient.GetDpi( horizontalDpi, verticalDpi );
1148 value = mImpl->mFontDefaults->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1158 void Controller::SetPlaceholderTextFontSize( float fontSize, FontSizeType type )
1160 if( NULL != mImpl->mEventData )
1162 if( NULL == mImpl->mEventData->mPlaceholderFont )
1164 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
1171 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = fontSize;
1172 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1173 mImpl->mEventData->mIsPlaceholderPixelSize = false; // Font size flag
1178 // Point size = Pixel size * 72.f / DPI
1179 unsigned int horizontalDpi = 0u;
1180 unsigned int verticalDpi = 0u;
1181 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1182 fontClient.GetDpi( horizontalDpi, verticalDpi );
1184 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
1185 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1186 mImpl->mEventData->mIsPlaceholderPixelSize = true; // Font size flag
1191 mImpl->RequestRelayout();
1195 float Controller::GetPlaceholderTextFontSize( FontSizeType type ) const
1198 if( NULL != mImpl->mEventData )
1204 if( NULL != mImpl->mEventData->mPlaceholderFont )
1206 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize;
1210 // If the placeholder text font size is not set, then return the default font size.
1211 value = GetDefaultFontSize( POINT_SIZE );
1217 if( NULL != mImpl->mEventData->mPlaceholderFont )
1219 // Pixel size = Point size * DPI / 72.f
1220 unsigned int horizontalDpi = 0u;
1221 unsigned int verticalDpi = 0u;
1222 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1223 fontClient.GetDpi( horizontalDpi, verticalDpi );
1225 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1229 // If the placeholder text font size is not set, then return the default font size.
1230 value = GetDefaultFontSize( PIXEL_SIZE );
1241 void Controller::SetDefaultColor( const Vector4& color )
1243 mImpl->mTextColor = color;
1245 if( !mImpl->IsShowingPlaceholderText() )
1247 mImpl->mModel->mVisualModel->SetTextColor( color );
1249 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
1251 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1253 mImpl->RequestRelayout();
1257 const Vector4& Controller::GetDefaultColor() const
1259 return mImpl->mTextColor;
1262 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
1264 if( NULL != mImpl->mEventData )
1266 mImpl->mEventData->mPlaceholderTextColor = textColor;
1269 if( mImpl->IsShowingPlaceholderText() )
1271 mImpl->mModel->mVisualModel->SetTextColor( textColor );
1272 mImpl->RequestRelayout();
1276 const Vector4& Controller::GetPlaceholderTextColor() const
1278 if( NULL != mImpl->mEventData )
1280 return mImpl->mEventData->mPlaceholderTextColor;
1283 return Color::BLACK;
1286 void Controller::SetShadowOffset( const Vector2& shadowOffset )
1288 mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
1290 mImpl->RequestRelayout();
1293 const Vector2& Controller::GetShadowOffset() const
1295 return mImpl->mModel->mVisualModel->GetShadowOffset();
1298 void Controller::SetShadowColor( const Vector4& shadowColor )
1300 mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
1302 mImpl->RequestRelayout();
1305 const Vector4& Controller::GetShadowColor() const
1307 return mImpl->mModel->mVisualModel->GetShadowColor();
1310 void Controller::SetShadowBlurRadius( const float& shadowBlurRadius )
1312 if ( fabsf( GetShadowBlurRadius() - shadowBlurRadius ) > Math::MACHINE_EPSILON_1 )
1314 mImpl->mModel->mVisualModel->SetShadowBlurRadius( shadowBlurRadius );
1316 mImpl->RequestRelayout();
1320 const float& Controller::GetShadowBlurRadius() const
1322 return mImpl->mModel->mVisualModel->GetShadowBlurRadius();
1325 void Controller::SetUnderlineColor( const Vector4& color )
1327 mImpl->mModel->mVisualModel->SetUnderlineColor( color );
1329 mImpl->RequestRelayout();
1332 const Vector4& Controller::GetUnderlineColor() const
1334 return mImpl->mModel->mVisualModel->GetUnderlineColor();
1337 void Controller::SetUnderlineEnabled( bool enabled )
1339 mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
1341 mImpl->RequestRelayout();
1344 bool Controller::IsUnderlineEnabled() const
1346 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
1349 void Controller::SetUnderlineHeight( float height )
1351 mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
1353 mImpl->RequestRelayout();
1356 float Controller::GetUnderlineHeight() const
1358 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
1361 void Controller::SetOutlineColor( const Vector4& color )
1363 mImpl->mModel->mVisualModel->SetOutlineColor( color );
1365 mImpl->RequestRelayout();
1368 const Vector4& Controller::GetOutlineColor() const
1370 return mImpl->mModel->mVisualModel->GetOutlineColor();
1373 void Controller::SetOutlineWidth( uint16_t width )
1375 mImpl->mModel->mVisualModel->SetOutlineWidth( width );
1377 mImpl->RequestRelayout();
1380 uint16_t Controller::GetOutlineWidth() const
1382 return mImpl->mModel->mVisualModel->GetOutlineWidth();
1385 void Controller::SetBackgroundColor( const Vector4& color )
1387 mImpl->mModel->mVisualModel->SetBackgroundColor( color );
1389 mImpl->RequestRelayout();
1392 const Vector4& Controller::GetBackgroundColor() const
1394 return mImpl->mModel->mVisualModel->GetBackgroundColor();
1397 void Controller::SetBackgroundEnabled( bool enabled )
1399 mImpl->mModel->mVisualModel->SetBackgroundEnabled( enabled );
1401 mImpl->RequestRelayout();
1404 bool Controller::IsBackgroundEnabled() const
1406 return mImpl->mModel->mVisualModel->IsBackgroundEnabled();
1409 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
1411 if( NULL == mImpl->mEmbossDefaults )
1413 mImpl->mEmbossDefaults = new EmbossDefaults();
1416 mImpl->mEmbossDefaults->properties = embossProperties;
1419 const std::string& Controller::GetDefaultEmbossProperties() const
1421 if( NULL != mImpl->mEmbossDefaults )
1423 return mImpl->mEmbossDefaults->properties;
1426 return EMPTY_STRING;
1429 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
1431 if( NULL == mImpl->mOutlineDefaults )
1433 mImpl->mOutlineDefaults = new OutlineDefaults();
1436 mImpl->mOutlineDefaults->properties = outlineProperties;
1439 const std::string& Controller::GetDefaultOutlineProperties() const
1441 if( NULL != mImpl->mOutlineDefaults )
1443 return mImpl->mOutlineDefaults->properties;
1446 return EMPTY_STRING;
1449 bool Controller::SetDefaultLineSpacing( float lineSpacing )
1451 if( std::fabs( lineSpacing - mImpl->mLayoutEngine.GetDefaultLineSpacing() ) > Math::MACHINE_EPSILON_1000 )
1453 mImpl->mLayoutEngine.SetDefaultLineSpacing(lineSpacing);
1454 mImpl->mRecalculateNaturalSize = true;
1460 float Controller::GetDefaultLineSpacing() const
1462 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
1465 void Controller::SetInputColor( const Vector4& color )
1467 if( NULL != mImpl->mEventData )
1469 mImpl->mEventData->mInputStyle.textColor = color;
1470 mImpl->mEventData->mInputStyle.isDefaultColor = false;
1472 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1474 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
1476 // Get start and end position of selection
1477 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
1478 const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
1480 // Add the color run.
1481 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1482 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
1484 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
1485 colorRun.color = color;
1486 colorRun.characterRun.characterIndex = startOfSelectedText;
1487 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1489 // Request to relayout.
1490 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1491 mImpl->RequestRelayout();
1493 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1494 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1495 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1500 const Vector4& Controller::GetInputColor() const
1502 if( NULL != mImpl->mEventData )
1504 return mImpl->mEventData->mInputStyle.textColor;
1507 // Return the default text's color if there is no EventData.
1508 return mImpl->mTextColor;
1512 void Controller::SetInputFontFamily( const std::string& fontFamily )
1514 if( NULL != mImpl->mEventData )
1516 mImpl->mEventData->mInputStyle.familyName = fontFamily;
1517 mImpl->mEventData->mInputStyle.isFamilyDefined = true;
1519 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1521 CharacterIndex startOfSelectedText = 0u;
1522 Length lengthOfSelectedText = 0u;
1524 if( EventData::SELECTING == mImpl->mEventData->mState )
1526 // Update a font description run for the selecting state.
1527 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1528 mImpl->mModel->mLogicalModel,
1529 startOfSelectedText,
1530 lengthOfSelectedText );
1532 fontDescriptionRun.familyLength = fontFamily.size();
1533 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
1534 memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength );
1535 fontDescriptionRun.familyDefined = true;
1537 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
1539 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1540 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1541 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1545 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
1546 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
1547 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
1550 // Request to relayout.
1551 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1556 UPDATE_LAYOUT_SIZE |
1559 mImpl->mRecalculateNaturalSize = true;
1560 mImpl->RequestRelayout();
1562 // As the font changes, recalculate the handle positions is needed.
1563 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1564 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1565 mImpl->mEventData->mUpdateHighlightBox = true;
1566 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1571 const std::string& Controller::GetInputFontFamily() const
1573 if( NULL != mImpl->mEventData )
1575 return mImpl->mEventData->mInputStyle.familyName;
1578 // Return the default font's family if there is no EventData.
1579 return GetDefaultFontFamily();
1582 void Controller::SetInputFontWeight( FontWeight weight )
1584 if( NULL != mImpl->mEventData )
1586 mImpl->mEventData->mInputStyle.weight = weight;
1587 mImpl->mEventData->mInputStyle.isWeightDefined = true;
1589 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1591 CharacterIndex startOfSelectedText = 0u;
1592 Length lengthOfSelectedText = 0u;
1594 if( EventData::SELECTING == mImpl->mEventData->mState )
1596 // Update a font description run for the selecting state.
1597 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1598 mImpl->mModel->mLogicalModel,
1599 startOfSelectedText,
1600 lengthOfSelectedText );
1602 fontDescriptionRun.weight = weight;
1603 fontDescriptionRun.weightDefined = true;
1605 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1606 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1607 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1611 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
1612 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
1613 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
1616 // Request to relayout.
1617 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1622 UPDATE_LAYOUT_SIZE |
1625 mImpl->mRecalculateNaturalSize = true;
1626 mImpl->RequestRelayout();
1628 // As the font might change, recalculate the handle positions is needed.
1629 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1630 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1631 mImpl->mEventData->mUpdateHighlightBox = true;
1632 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1637 bool Controller::IsInputFontWeightDefined() const
1639 bool defined = false;
1641 if( NULL != mImpl->mEventData )
1643 defined = mImpl->mEventData->mInputStyle.isWeightDefined;
1649 FontWeight Controller::GetInputFontWeight() const
1651 if( NULL != mImpl->mEventData )
1653 return mImpl->mEventData->mInputStyle.weight;
1656 return GetDefaultFontWeight();
1659 void Controller::SetInputFontWidth( FontWidth width )
1661 if( NULL != mImpl->mEventData )
1663 mImpl->mEventData->mInputStyle.width = width;
1664 mImpl->mEventData->mInputStyle.isWidthDefined = true;
1666 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1668 CharacterIndex startOfSelectedText = 0u;
1669 Length lengthOfSelectedText = 0u;
1671 if( EventData::SELECTING == mImpl->mEventData->mState )
1673 // Update a font description run for the selecting state.
1674 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1675 mImpl->mModel->mLogicalModel,
1676 startOfSelectedText,
1677 lengthOfSelectedText );
1679 fontDescriptionRun.width = width;
1680 fontDescriptionRun.widthDefined = true;
1682 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1683 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1684 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1688 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
1689 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
1690 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
1693 // Request to relayout.
1694 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1699 UPDATE_LAYOUT_SIZE |
1702 mImpl->mRecalculateNaturalSize = true;
1703 mImpl->RequestRelayout();
1705 // As the font might change, recalculate the handle positions is needed.
1706 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1707 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1708 mImpl->mEventData->mUpdateHighlightBox = true;
1709 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1714 bool Controller::IsInputFontWidthDefined() const
1716 bool defined = false;
1718 if( NULL != mImpl->mEventData )
1720 defined = mImpl->mEventData->mInputStyle.isWidthDefined;
1726 FontWidth Controller::GetInputFontWidth() const
1728 if( NULL != mImpl->mEventData )
1730 return mImpl->mEventData->mInputStyle.width;
1733 return GetDefaultFontWidth();
1736 void Controller::SetInputFontSlant( FontSlant slant )
1738 if( NULL != mImpl->mEventData )
1740 mImpl->mEventData->mInputStyle.slant = slant;
1741 mImpl->mEventData->mInputStyle.isSlantDefined = true;
1743 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1745 CharacterIndex startOfSelectedText = 0u;
1746 Length lengthOfSelectedText = 0u;
1748 if( EventData::SELECTING == mImpl->mEventData->mState )
1750 // Update a font description run for the selecting state.
1751 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1752 mImpl->mModel->mLogicalModel,
1753 startOfSelectedText,
1754 lengthOfSelectedText );
1756 fontDescriptionRun.slant = slant;
1757 fontDescriptionRun.slantDefined = true;
1759 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1760 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1761 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1765 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
1766 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
1767 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
1770 // Request to relayout.
1771 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1776 UPDATE_LAYOUT_SIZE |
1779 mImpl->mRecalculateNaturalSize = true;
1780 mImpl->RequestRelayout();
1782 // As the font might change, recalculate the handle positions is needed.
1783 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1784 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1785 mImpl->mEventData->mUpdateHighlightBox = true;
1786 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1791 bool Controller::IsInputFontSlantDefined() const
1793 bool defined = false;
1795 if( NULL != mImpl->mEventData )
1797 defined = mImpl->mEventData->mInputStyle.isSlantDefined;
1803 FontSlant Controller::GetInputFontSlant() const
1805 if( NULL != mImpl->mEventData )
1807 return mImpl->mEventData->mInputStyle.slant;
1810 return GetDefaultFontSlant();
1813 void Controller::SetInputFontPointSize( float size )
1815 if( NULL != mImpl->mEventData )
1817 mImpl->mEventData->mInputStyle.size = size;
1818 mImpl->mEventData->mInputStyle.isSizeDefined = true;
1820 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1822 CharacterIndex startOfSelectedText = 0u;
1823 Length lengthOfSelectedText = 0u;
1825 if( EventData::SELECTING == mImpl->mEventData->mState )
1827 // Update a font description run for the selecting state.
1828 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1829 mImpl->mModel->mLogicalModel,
1830 startOfSelectedText,
1831 lengthOfSelectedText );
1833 fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
1834 fontDescriptionRun.sizeDefined = true;
1836 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1837 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1838 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1842 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
1843 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
1844 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
1847 // Request to relayout.
1848 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1853 UPDATE_LAYOUT_SIZE |
1856 mImpl->mRecalculateNaturalSize = true;
1857 mImpl->RequestRelayout();
1859 // As the font might change, recalculate the handle positions is needed.
1860 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1861 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1862 mImpl->mEventData->mUpdateHighlightBox = true;
1863 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1868 float Controller::GetInputFontPointSize() const
1870 if( NULL != mImpl->mEventData )
1872 return mImpl->mEventData->mInputStyle.size;
1875 // Return the default font's point size if there is no EventData.
1876 return GetDefaultFontSize( Text::Controller::POINT_SIZE );
1879 void Controller::SetInputLineSpacing( float lineSpacing )
1881 if( NULL != mImpl->mEventData )
1883 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1884 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1888 float Controller::GetInputLineSpacing() const
1890 if( NULL != mImpl->mEventData )
1892 return mImpl->mEventData->mInputStyle.lineSpacing;
1898 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1900 if( NULL != mImpl->mEventData )
1902 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1906 const std::string& Controller::GetInputShadowProperties() const
1908 if( NULL != mImpl->mEventData )
1910 return mImpl->mEventData->mInputStyle.shadowProperties;
1913 return EMPTY_STRING;
1916 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1918 if( NULL != mImpl->mEventData )
1920 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1924 const std::string& Controller::GetInputUnderlineProperties() const
1926 if( NULL != mImpl->mEventData )
1928 return mImpl->mEventData->mInputStyle.underlineProperties;
1931 return EMPTY_STRING;
1934 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
1936 if( NULL != mImpl->mEventData )
1938 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1942 const std::string& Controller::GetInputEmbossProperties() const
1944 if( NULL != mImpl->mEventData )
1946 return mImpl->mEventData->mInputStyle.embossProperties;
1949 return GetDefaultEmbossProperties();
1952 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
1954 if( NULL != mImpl->mEventData )
1956 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1960 const std::string& Controller::GetInputOutlineProperties() const
1962 if( NULL != mImpl->mEventData )
1964 return mImpl->mEventData->mInputStyle.outlineProperties;
1967 return GetDefaultOutlineProperties();
1970 void Controller::SetInputModePassword( bool passwordInput )
1972 if( NULL != mImpl->mEventData )
1974 mImpl->mEventData->mPasswordInput = passwordInput;
1978 bool Controller::IsInputModePassword()
1980 if( NULL != mImpl->mEventData )
1982 return mImpl->mEventData->mPasswordInput;
1987 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
1989 if( NULL != mImpl->mEventData )
1991 mImpl->mEventData->mDoubleTapAction = action;
1995 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1997 NoTextTap::Action action = NoTextTap::NO_ACTION;
1999 if( NULL != mImpl->mEventData )
2001 action = mImpl->mEventData->mDoubleTapAction;
2007 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
2009 if( NULL != mImpl->mEventData )
2011 mImpl->mEventData->mLongPressAction = action;
2015 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
2017 NoTextTap::Action action = NoTextTap::NO_ACTION;
2019 if( NULL != mImpl->mEventData )
2021 action = mImpl->mEventData->mLongPressAction;
2027 bool Controller::IsUnderlineSetByString()
2029 return mImpl->mUnderlineSetByString;
2032 void Controller::UnderlineSetByString( bool setByString )
2034 mImpl->mUnderlineSetByString = setByString;
2037 bool Controller::IsShadowSetByString()
2039 return mImpl->mShadowSetByString;
2042 void Controller::ShadowSetByString( bool setByString )
2044 mImpl->mShadowSetByString = setByString;
2047 bool Controller::IsOutlineSetByString()
2049 return mImpl->mOutlineSetByString;
2052 void Controller::OutlineSetByString( bool setByString )
2054 mImpl->mOutlineSetByString = setByString;
2057 bool Controller::IsFontStyleSetByString()
2059 return mImpl->mFontStyleSetByString;
2062 void Controller::FontStyleSetByString( bool setByString )
2064 mImpl->mFontStyleSetByString = setByString;
2067 // public : Queries & retrieves.
2069 Layout::Engine& Controller::GetLayoutEngine()
2071 return mImpl->mLayoutEngine;
2074 View& Controller::GetView()
2076 return mImpl->mView;
2079 Vector3 Controller::GetNaturalSize()
2081 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
2082 Vector3 naturalSize;
2084 // Make sure the model is up-to-date before layouting
2085 ProcessModifyEvents();
2087 if( mImpl->mRecalculateNaturalSize )
2089 // Operations that can be done only once until the text changes.
2090 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2096 GET_GLYPH_METRICS );
2098 // Set the update info to relayout the whole text.
2099 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2100 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2102 // Make sure the model is up-to-date before layouting
2103 mImpl->UpdateModel( onlyOnceOperations );
2105 // Layout the text for the new width.
2106 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT | REORDER );
2108 // Store the actual control's size to restore later.
2109 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
2111 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
2112 static_cast<OperationsMask>( onlyOnceOperations |
2114 naturalSize.GetVectorXY() );
2116 // Do not do again the only once operations.
2117 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2119 // Do the size related operations again.
2120 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
2123 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
2125 // Stores the natural size to avoid recalculate it again
2126 // unless the text/style changes.
2127 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
2129 mImpl->mRecalculateNaturalSize = false;
2131 // Clear the update info. This info will be set the next time the text is updated.
2132 mImpl->mTextUpdateInfo.Clear();
2133 mImpl->mTextUpdateInfo.mClearAll = true;
2135 // Restore the actual control's size.
2136 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
2138 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
2142 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
2144 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
2147 naturalSize.x = ConvertToEven( naturalSize.x );
2148 naturalSize.y = ConvertToEven( naturalSize.y );
2153 bool Controller::CheckForTextFit( float pointSize, Size& layoutSize )
2156 mImpl->mFontDefaults->mFitPointSize = pointSize;
2157 mImpl->mFontDefaults->sizeDefined = true;
2160 // Operations that can be done only once until the text changes.
2161 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2167 GET_GLYPH_METRICS );
2169 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2170 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2172 // Make sure the model is up-to-date before layouting
2173 mImpl->UpdateModel( onlyOnceOperations );
2175 DoRelayout( Size( layoutSize.width, MAX_FLOAT ),
2176 static_cast<OperationsMask>( onlyOnceOperations | LAYOUT),
2179 // Clear the update info. This info will be set the next time the text is updated.
2180 mImpl->mTextUpdateInfo.Clear();
2181 mImpl->mTextUpdateInfo.mClearAll = true;
2183 if( textSize.width > layoutSize.width || textSize.height > layoutSize.height )
2190 void Controller::FitPointSizeforLayout( Size layoutSize )
2192 const OperationsMask operations = mImpl->mOperationsPending;
2193 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) || mImpl->mTextFitContentSize != layoutSize )
2195 bool actualellipsis = mImpl->mModel->mElideEnabled;
2196 float minPointSize = mImpl->mTextFitMinSize;
2197 float maxPointSize = mImpl->mTextFitMaxSize;
2198 float pointInterval = mImpl->mTextFitStepSize;
2200 mImpl->mModel->mElideEnabled = false;
2201 Vector<float> pointSizeArray;
2204 if( pointInterval < 1.f )
2206 mImpl->mTextFitStepSize = pointInterval = 1.0f;
2209 pointSizeArray.Reserve( static_cast< unsigned int >( ceil( ( maxPointSize - minPointSize ) / pointInterval ) ) );
2211 for( float i = minPointSize; i < maxPointSize; i += pointInterval )
2213 pointSizeArray.PushBack( i );
2216 pointSizeArray.PushBack( maxPointSize );
2218 int bestSizeIndex = 0;
2219 int min = bestSizeIndex + 1;
2220 int max = pointSizeArray.Size() - 1;
2223 int destI = ( min + max ) / 2;
2225 if( CheckForTextFit( pointSizeArray[destI], layoutSize ) )
2227 bestSizeIndex = min;
2233 bestSizeIndex = max;
2237 mImpl->mModel->mElideEnabled = actualellipsis;
2238 mImpl->mFontDefaults->mFitPointSize = pointSizeArray[bestSizeIndex];
2239 mImpl->mFontDefaults->sizeDefined = true;
2244 float Controller::GetHeightForWidth( float width )
2246 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
2247 // Make sure the model is up-to-date before layouting
2248 ProcessModifyEvents();
2251 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ||
2252 mImpl->mTextUpdateInfo.mFullRelayoutNeeded ||
2253 mImpl->mTextUpdateInfo.mClearAll )
2255 // Operations that can be done only once until the text changes.
2256 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2262 GET_GLYPH_METRICS );
2264 // Set the update info to relayout the whole text.
2265 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2266 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2268 // Make sure the model is up-to-date before layouting
2269 mImpl->UpdateModel( onlyOnceOperations );
2272 // Layout the text for the new width.
2273 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
2275 // Store the actual control's width.
2276 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
2278 DoRelayout( Size( width, MAX_FLOAT ),
2279 static_cast<OperationsMask>( onlyOnceOperations |
2283 // Do not do again the only once operations.
2284 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2286 // Do the size related operations again.
2287 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
2291 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
2293 // Clear the update info. This info will be set the next time the text is updated.
2294 mImpl->mTextUpdateInfo.Clear();
2295 mImpl->mTextUpdateInfo.mClearAll = true;
2297 // Restore the actual control's width.
2298 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
2300 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
2304 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
2305 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
2308 return layoutSize.height;
2311 int Controller::GetLineCount( float width )
2313 GetHeightForWidth( width );
2314 int numberofLines = mImpl->mModel->GetNumberOfLines();
2315 return numberofLines;
2318 const ModelInterface* const Controller::GetTextModel() const
2320 return mImpl->mModel.Get();
2323 float Controller::GetScrollAmountByUserInput()
2325 float scrollAmount = 0.0f;
2327 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
2329 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
2330 mImpl->mEventData->mCheckScrollAmount = false;
2332 return scrollAmount;
2335 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
2337 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
2340 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
2341 layoutHeight = layout.height;
2342 scrollPosition = mImpl->mModel->mScrollPosition.y;
2343 isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
2347 void Controller::SetHiddenInputOption(const Property::Map& options )
2349 if( NULL == mImpl->mHiddenInput )
2351 mImpl->mHiddenInput = new HiddenText( this );
2353 mImpl->mHiddenInput->SetProperties(options);
2356 void Controller::GetHiddenInputOption(Property::Map& options )
2358 if( NULL != mImpl->mHiddenInput )
2360 mImpl->mHiddenInput->GetProperties(options);
2364 void Controller::SetPlaceholderProperty( const Property::Map& map )
2366 const Property::Map::SizeType count = map.Count();
2368 for( Property::Map::SizeType position = 0; position < count; ++position )
2370 KeyValuePair keyValue = map.GetKeyValue( position );
2371 Property::Key& key = keyValue.first;
2372 Property::Value& value = keyValue.second;
2374 if( key == Toolkit::Text::PlaceHolder::Property::TEXT || key == PLACEHOLDER_TEXT )
2376 std::string text = "";
2378 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
2380 else if( key == Toolkit::Text::PlaceHolder::Property::TEXT_FOCUSED || key == PLACEHOLDER_TEXT_FOCUSED )
2382 std::string text = "";
2384 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
2386 else if( key == Toolkit::Text::PlaceHolder::Property::COLOR || key == PLACEHOLDER_COLOR )
2389 value.Get( textColor );
2390 if( GetPlaceholderTextColor() != textColor )
2392 SetPlaceholderTextColor( textColor );
2395 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_FAMILY || key == PLACEHOLDER_FONT_FAMILY )
2397 std::string fontFamily = "";
2398 value.Get( fontFamily );
2399 SetPlaceholderFontFamily( fontFamily );
2401 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_STYLE || key == PLACEHOLDER_FONT_STYLE )
2403 SetFontStyleProperty( this, value, Text::FontStyle::PLACEHOLDER );
2405 else if( key == Toolkit::Text::PlaceHolder::Property::POINT_SIZE || key == PLACEHOLDER_POINT_SIZE )
2408 value.Get( pointSize );
2409 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
2411 SetPlaceholderTextFontSize( pointSize, Text::Controller::POINT_SIZE );
2414 else if( key == Toolkit::Text::PlaceHolder::Property::PIXEL_SIZE || key == PLACEHOLDER_PIXEL_SIZE )
2417 value.Get( pixelSize );
2418 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
2420 SetPlaceholderTextFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
2423 else if( key == Toolkit::Text::PlaceHolder::Property::ELLIPSIS || key == PLACEHOLDER_ELLIPSIS )
2426 value.Get( ellipsis );
2427 SetPlaceholderTextElideEnabled( ellipsis );
2432 void Controller::GetPlaceholderProperty( Property::Map& map )
2434 if( NULL != mImpl->mEventData )
2436 if( !mImpl->mEventData->mPlaceholderTextActive.empty() )
2438 map[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = mImpl->mEventData->mPlaceholderTextActive;
2440 if( !mImpl->mEventData->mPlaceholderTextInactive.empty() )
2442 map[ Text::PlaceHolder::Property::TEXT ] = mImpl->mEventData->mPlaceholderTextInactive;
2445 map[ Text::PlaceHolder::Property::COLOR ] = mImpl->mEventData->mPlaceholderTextColor;
2446 map[ Text::PlaceHolder::Property::FONT_FAMILY ] = GetPlaceholderFontFamily();
2448 Property::Value fontStyleMapGet;
2449 GetFontStyleProperty( this, fontStyleMapGet, Text::FontStyle::PLACEHOLDER );
2450 map[ Text::PlaceHolder::Property::FONT_STYLE ] = fontStyleMapGet;
2452 // Choose font size : POINT_SIZE or PIXEL_SIZE
2453 if( !mImpl->mEventData->mIsPlaceholderPixelSize )
2455 map[ Text::PlaceHolder::Property::POINT_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE );
2459 map[ Text::PlaceHolder::Property::PIXEL_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE );
2462 if( mImpl->mEventData->mPlaceholderEllipsisFlag )
2464 map[ Text::PlaceHolder::Property::ELLIPSIS ] = IsPlaceholderTextElideEnabled();
2469 Toolkit::DevelText::TextDirection::Type Controller::GetTextDirection()
2471 // Make sure the model is up-to-date before layouting
2472 ProcessModifyEvents();
2474 if ( mImpl->mUpdateTextDirection )
2476 // Operations that can be done only once until the text changes.
2477 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2483 GET_GLYPH_METRICS );
2485 // Set the update info to relayout the whole text.
2486 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2487 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2489 // Make sure the model is up-to-date before layouting
2490 mImpl->UpdateModel( onlyOnceOperations );
2492 Vector3 naturalSize;
2493 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
2494 static_cast<OperationsMask>( onlyOnceOperations |
2495 LAYOUT | REORDER | UPDATE_DIRECTION ),
2496 naturalSize.GetVectorXY() );
2498 // Do not do again the only once operations.
2499 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2501 // Clear the update info. This info will be set the next time the text is updated.
2502 mImpl->mTextUpdateInfo.Clear();
2504 // FullRelayoutNeeded should be true because DoRelayout is MAX_FLOAT, MAX_FLOAT.
2505 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2507 mImpl->mUpdateTextDirection = false;
2510 return mImpl->mIsTextDirectionRTL ? Toolkit::DevelText::TextDirection::RIGHT_TO_LEFT : Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT;
2513 Toolkit::DevelText::VerticalLineAlignment::Type Controller::GetVerticalLineAlignment() const
2515 return mImpl->mModel->GetVerticalLineAlignment();
2518 void Controller::SetVerticalLineAlignment( Toolkit::DevelText::VerticalLineAlignment::Type alignment )
2520 mImpl->mModel->mVerticalLineAlignment = alignment;
2523 // public : Relayout.
2525 Controller::UpdateTextType Controller::Relayout( const Size& size, Dali::LayoutDirection::Type layoutDirection )
2527 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
2529 UpdateTextType updateTextType = NONE_UPDATED;
2531 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
2533 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
2535 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
2536 updateTextType = MODEL_UPDATED;
2539 // Clear the update info. This info will be set the next time the text is updated.
2540 mImpl->mTextUpdateInfo.Clear();
2542 // Not worth to relayout if width or height is equal to zero.
2543 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
2545 return updateTextType;
2548 // Whether a new size has been set.
2549 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
2553 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
2555 if( ( 0 == mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd ) &&
2556 ( 0 == mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) &&
2557 ( ( mImpl->mModel->mVisualModel->mControlSize.width < Math::MACHINE_EPSILON_1000 ) || ( mImpl->mModel->mVisualModel->mControlSize.height < Math::MACHINE_EPSILON_1000 ) ) )
2559 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
2562 // Layout operations that need to be done if the size changes.
2563 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2566 UPDATE_LAYOUT_SIZE |
2568 // Set the update info to relayout the whole text.
2569 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2570 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2572 // Store the size used to layout the text.
2573 mImpl->mModel->mVisualModel->mControlSize = size;
2576 // Whether there are modify events.
2577 if( 0u != mImpl->mModifyEvents.Count() )
2579 // Style operations that need to be done if the text is modified.
2580 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2584 // Set the update info to elide the text.
2585 if( mImpl->mModel->mElideEnabled ||
2586 ( ( NULL != mImpl->mEventData ) && mImpl->mEventData->mIsPlaceholderElideEnabled ) )
2588 // Update Text layout for applying elided
2589 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2592 UPDATE_LAYOUT_SIZE |
2594 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2595 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2598 if( mImpl->mModel->mMatchSystemLanguageDirection && mImpl->mLayoutDirection != layoutDirection )
2600 // Clear the update info. This info will be set the next time the text is updated.
2601 mImpl->mTextUpdateInfo.mClearAll = true;
2602 // Apply modifications to the model
2603 // Shape the text again is needed because characters like '()[]{}' have to be mirrored and the glyphs generated again.
2604 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2611 mImpl->mLayoutDirection = layoutDirection;
2614 // Make sure the model is up-to-date before layouting.
2615 ProcessModifyEvents();
2616 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
2620 updated = DoRelayout( size,
2621 mImpl->mOperationsPending,
2622 layoutSize ) || updated;
2627 updateTextType = MODEL_UPDATED;
2630 // Do not re-do any operation until something changes.
2631 mImpl->mOperationsPending = NO_OPERATION;
2632 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
2634 // Whether the text control is editable
2635 const bool isEditable = NULL != mImpl->mEventData;
2637 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
2639 if( newSize && isEditable )
2641 offset = mImpl->mModel->mScrollPosition;
2644 if( !isEditable || !IsMultiLineEnabled() )
2646 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
2647 CalculateVerticalOffset( size );
2654 // If there is a new size, the scroll position needs to be clamped.
2655 mImpl->ClampHorizontalScroll( layoutSize );
2657 // Update the decorator's positions is needed if there is a new size.
2658 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
2661 // Move the cursor, grab handle etc.
2662 if( mImpl->ProcessInputEvents() )
2664 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
2668 // Clear the update info. This info will be set the next time the text is updated.
2669 mImpl->mTextUpdateInfo.Clear();
2670 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
2672 return updateTextType;
2675 void Controller::RequestRelayout()
2677 mImpl->RequestRelayout();
2680 // public : Input style change signals.
2682 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
2684 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
2687 void Controller::ProcessInputStyleChangedSignals()
2689 if( NULL == mImpl->mEventData )
2695 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
2696 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
2700 const InputStyle::Mask mask = *it;
2702 if( NULL != mImpl->mEditableControlInterface )
2704 // Emit the input style changed signal.
2705 mImpl->mEditableControlInterface->InputStyleChanged( mask );
2709 mImpl->mEventData->mInputStyleChangedQueue.Clear();
2712 // public : Text-input Event Queuing.
2714 void Controller::KeyboardFocusGainEvent()
2716 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
2718 if( NULL != mImpl->mEventData )
2720 if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
2721 ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
2723 mImpl->ChangeState( EventData::EDITING );
2724 mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
2725 mImpl->mEventData->mUpdateInputStyle = true;
2726 mImpl->mEventData->mScrollAfterUpdatePosition = true;
2728 mImpl->NotifyInputMethodContextMultiLineStatus();
2729 if( mImpl->IsShowingPlaceholderText() )
2731 // Show alternative placeholder-text when editing
2732 ShowPlaceholderText();
2735 mImpl->RequestRelayout();
2739 void Controller::KeyboardFocusLostEvent()
2741 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
2743 if( NULL != mImpl->mEventData )
2745 if( EventData::INTERRUPTED != mImpl->mEventData->mState )
2747 mImpl->ChangeState( EventData::INACTIVE );
2749 if( !mImpl->IsShowingRealText() )
2751 // Revert to regular placeholder-text when not editing
2752 ShowPlaceholderText();
2756 mImpl->RequestRelayout();
2759 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
2761 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
2763 bool textChanged = false;
2764 bool relayoutNeeded = false;
2766 if( ( NULL != mImpl->mEventData ) &&
2767 ( keyEvent.state == KeyEvent::Down ) )
2769 int keyCode = keyEvent.keyCode;
2770 const std::string& keyString = keyEvent.keyPressed;
2771 const std::string keyName = keyEvent.keyPressedName;
2773 const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
2775 // Pre-process to separate modifying events from non-modifying input events.
2778 // In some platforms arrive key events with no key code.
2782 else if( Dali::DALI_KEY_ESCAPE == keyCode || Dali::DALI_KEY_BACK == keyCode || Dali::DALI_KEY_SEARCH == keyCode )
2787 else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) ||
2788 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
2789 ( Dali::DALI_KEY_CURSOR_UP == keyCode ) ||
2790 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) )
2792 // If don't have any text, do nothing.
2793 if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
2798 uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition;
2799 uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2800 uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition );
2801 uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines();
2803 // Logic to determine whether this text control will lose focus or not.
2804 if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2805 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2806 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) ||
2807 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) ||
2808 ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) ||
2809 ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) )
2811 // Release the active highlight.
2812 if( mImpl->mEventData->mState == EventData::SELECTING )
2814 mImpl->ChangeState( EventData::EDITING );
2816 // Update selection position.
2817 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2818 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2819 mImpl->mEventData->mUpdateCursorPosition = true;
2820 mImpl->RequestRelayout();
2825 mImpl->mEventData->mCheckScrollAmount = true;
2826 Event event( Event::CURSOR_KEY_EVENT );
2827 event.p1.mInt = keyCode;
2828 event.p2.mBool = keyEvent.IsShiftModifier();
2829 mImpl->mEventData->mEventQueue.push_back( event );
2831 // Will request for relayout.
2832 relayoutNeeded = true;
2834 else if ( Dali::DevelKey::DALI_KEY_CONTROL_LEFT == keyCode || Dali::DevelKey::DALI_KEY_CONTROL_RIGHT == keyCode )
2836 // Left or Right Control key event is received before Ctrl-C/V/X key event is received
2837 // If not handle it here, any selected text will be deleted
2842 else if ( keyEvent.IsCtrlModifier() )
2844 bool consumed = false;
2845 if (keyName == KEY_C_NAME)
2847 // Ctrl-C to copy the selected text
2848 TextPopupButtonTouched( Toolkit::TextSelectionPopup::COPY );
2851 else if (keyName == KEY_V_NAME)
2853 // Ctrl-V to paste the copied text
2854 TextPopupButtonTouched( Toolkit::TextSelectionPopup::PASTE );
2857 else if (keyName == KEY_X_NAME)
2859 // Ctrl-X to cut the selected text
2860 TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
2865 else if( ( Dali::DALI_KEY_BACKSPACE == keyCode ) ||
2866 ( Dali::DevelKey::DALI_KEY_DELETE == keyCode ) )
2868 textChanged = DeleteEvent( keyCode );
2870 // Will request for relayout.
2871 relayoutNeeded = true;
2873 else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
2874 IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
2875 IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
2877 // Power key/Menu/Home key behaviour does not allow edit mode to resume.
2878 mImpl->ChangeState( EventData::INACTIVE );
2880 // Will request for relayout.
2881 relayoutNeeded = true;
2883 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2885 else if( ( Dali::DALI_KEY_SHIFT_LEFT == keyCode ) || ( Dali::DALI_KEY_SHIFT_RIGHT == keyCode ) )
2887 // 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
2888 // and a character is typed after the type of a upper case latin character.
2893 else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
2895 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2901 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
2903 if( !keyString.empty() )
2905 // InputMethodContext is no longer handling key-events
2906 mImpl->ClearPreEditFlag();
2908 InsertText( keyString, COMMIT );
2912 // Will request for relayout.
2913 relayoutNeeded = true;
2918 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
2919 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
2921 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
2922 ( Dali::DALI_KEY_SHIFT_RIGHT != keyCode ) &&
2923 ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
2924 ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
2926 // Should not change the state if the key is the shift send by the InputMethodContext.
2927 // Otherwise, when the state is SELECTING the text controller can't send the right
2928 // surrounding info to the InputMethodContext.
2929 mImpl->ChangeState( EventData::EDITING );
2931 // Will request for relayout.
2932 relayoutNeeded = true;
2935 if( relayoutNeeded )
2937 mImpl->RequestRelayout();
2942 ( NULL != mImpl->mEditableControlInterface ) )
2944 // Do this last since it provides callbacks into application code
2945 mImpl->mEditableControlInterface->TextChanged();
2951 void Controller::TapEvent( unsigned int tapCount, float x, float y )
2953 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
2955 if( NULL != mImpl->mEventData )
2957 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
2958 EventData::State state( mImpl->mEventData->mState );
2959 bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
2961 if( mImpl->IsClipboardVisible() )
2963 if( EventData::INACTIVE == state || EventData::EDITING == state)
2965 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2967 relayoutNeeded = true;
2969 else if( 1u == tapCount )
2971 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
2973 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
2976 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
2978 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2979 relayoutNeeded = true;
2983 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
2985 // Hide placeholder text
2989 if( EventData::INACTIVE == state )
2991 mImpl->ChangeState( EventData::EDITING );
2993 else if( !mImpl->IsClipboardEmpty() )
2995 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
2997 relayoutNeeded = true;
3000 else if( 2u == tapCount )
3002 if( mImpl->mEventData->mSelectionEnabled &&
3003 mImpl->IsShowingRealText() )
3005 relayoutNeeded = true;
3006 mImpl->mEventData->mIsLeftHandleSelected = true;
3007 mImpl->mEventData->mIsRightHandleSelected = true;
3011 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
3012 if( relayoutNeeded )
3014 Event event( Event::TAP_EVENT );
3015 event.p1.mUint = tapCount;
3016 event.p2.mFloat = x;
3017 event.p3.mFloat = y;
3018 mImpl->mEventData->mEventQueue.push_back( event );
3020 mImpl->RequestRelayout();
3024 // Reset keyboard as tap event has occurred.
3025 mImpl->ResetInputMethodContext();
3028 void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
3030 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
3032 if( NULL != mImpl->mEventData )
3034 Event event( Event::PAN_EVENT );
3035 event.p1.mInt = state;
3036 event.p2.mFloat = displacement.x;
3037 event.p3.mFloat = displacement.y;
3038 mImpl->mEventData->mEventQueue.push_back( event );
3040 mImpl->RequestRelayout();
3044 void Controller::LongPressEvent( Gesture::State state, float x, float y )
3046 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
3048 if( ( state == Gesture::Started ) &&
3049 ( NULL != mImpl->mEventData ) )
3051 // The 1st long-press on inactive text-field is treated as tap
3052 if( EventData::INACTIVE == mImpl->mEventData->mState )
3054 mImpl->ChangeState( EventData::EDITING );
3056 Event event( Event::TAP_EVENT );
3058 event.p2.mFloat = x;
3059 event.p3.mFloat = y;
3060 mImpl->mEventData->mEventQueue.push_back( event );
3062 mImpl->RequestRelayout();
3064 else if( !mImpl->IsShowingRealText() )
3066 Event event( Event::LONG_PRESS_EVENT );
3067 event.p1.mInt = state;
3068 event.p2.mFloat = x;
3069 event.p3.mFloat = y;
3070 mImpl->mEventData->mEventQueue.push_back( event );
3071 mImpl->RequestRelayout();
3073 else if( !mImpl->IsClipboardVisible() )
3075 // Reset the InputMethodContext to commit the pre-edit before selecting the text.
3076 mImpl->ResetInputMethodContext();
3078 Event event( Event::LONG_PRESS_EVENT );
3079 event.p1.mInt = state;
3080 event.p2.mFloat = x;
3081 event.p3.mFloat = y;
3082 mImpl->mEventData->mEventQueue.push_back( event );
3083 mImpl->RequestRelayout();
3085 mImpl->mEventData->mIsLeftHandleSelected = true;
3086 mImpl->mEventData->mIsRightHandleSelected = true;
3091 void Controller::SelectEvent( float x, float y, SelectionType selectType )
3093 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
3095 if( NULL != mImpl->mEventData )
3097 if( selectType == SelectionType::ALL )
3099 Event event( Event::SELECT_ALL );
3100 mImpl->mEventData->mEventQueue.push_back( event );
3102 else if( selectType == SelectionType::NONE )
3104 Event event( Event::SELECT_NONE );
3105 mImpl->mEventData->mEventQueue.push_back( event );
3109 Event event( Event::SELECT );
3110 event.p2.mFloat = x;
3111 event.p3.mFloat = y;
3112 mImpl->mEventData->mEventQueue.push_back( event );
3115 mImpl->mEventData->mCheckScrollAmount = true;
3116 mImpl->mEventData->mIsLeftHandleSelected = true;
3117 mImpl->mEventData->mIsRightHandleSelected = true;
3118 mImpl->RequestRelayout();
3122 InputMethodContext::CallbackData Controller::OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
3124 // Whether the text needs to be relaid-out.
3125 bool requestRelayout = false;
3127 // Whether to retrieve the text and cursor position to be sent to the InputMethodContext.
3128 bool retrieveText = false;
3129 bool retrieveCursor = false;
3131 switch( inputMethodContextEvent.eventName )
3133 case InputMethodContext::COMMIT:
3135 InsertText( inputMethodContextEvent.predictiveString, Text::Controller::COMMIT );
3136 requestRelayout = true;
3137 retrieveCursor = true;
3140 case InputMethodContext::PRE_EDIT:
3142 InsertText( inputMethodContextEvent.predictiveString, Text::Controller::PRE_EDIT );
3143 requestRelayout = true;
3144 retrieveCursor = true;
3147 case InputMethodContext::DELETE_SURROUNDING:
3149 const bool textDeleted = RemoveText( inputMethodContextEvent.cursorOffset,
3150 inputMethodContextEvent.numberOfChars,
3151 DONT_UPDATE_INPUT_STYLE );
3155 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3156 !mImpl->IsPlaceholderAvailable() )
3158 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3162 ShowPlaceholderText();
3164 mImpl->mEventData->mUpdateCursorPosition = true;
3165 mImpl->mEventData->mScrollAfterDelete = true;
3167 requestRelayout = true;
3171 case InputMethodContext::GET_SURROUNDING:
3173 retrieveText = true;
3174 retrieveCursor = true;
3177 case InputMethodContext::PRIVATE_COMMAND:
3179 // PRIVATECOMMAND event is just for getting the private command message
3180 retrieveText = true;
3181 retrieveCursor = true;
3184 case InputMethodContext::VOID:
3191 if( requestRelayout )
3193 mImpl->mOperationsPending = ALL_OPERATIONS;
3194 mImpl->RequestRelayout();
3198 CharacterIndex cursorPosition = 0u;
3199 Length numberOfWhiteSpaces = 0u;
3201 if( retrieveCursor )
3203 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
3205 cursorPosition = mImpl->GetLogicalCursorPosition();
3207 if( cursorPosition < numberOfWhiteSpaces )
3209 cursorPosition = 0u;
3213 cursorPosition -= numberOfWhiteSpaces;
3219 if( !mImpl->IsShowingPlaceholderText() )
3221 // Retrieves the normal text string.
3222 mImpl->GetText( numberOfWhiteSpaces, text );
3226 // When the current text is Placeholder Text, the surrounding text should be empty string.
3227 // It means DALi should send empty string ("") to IME.
3232 InputMethodContext::CallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
3234 if( requestRelayout &&
3235 ( NULL != mImpl->mEditableControlInterface ) )
3237 // Do this last since it provides callbacks into application code
3238 mImpl->mEditableControlInterface->TextChanged();
3241 return callbackData;
3244 void Controller::PasteClipboardItemEvent()
3246 // Retrieve the clipboard contents first
3247 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
3248 std::string stringToPaste( notifier.GetContent() );
3250 // Commit the current pre-edit text; the contents of the clipboard should be appended
3251 mImpl->ResetInputMethodContext();
3253 // Temporary disable hiding clipboard
3254 mImpl->SetClipboardHideEnable( false );
3257 PasteText( stringToPaste );
3259 mImpl->SetClipboardHideEnable( true );
3262 // protected : Inherit from Text::Decorator::ControllerInterface.
3264 void Controller::GetTargetSize( Vector2& targetSize )
3266 targetSize = mImpl->mModel->mVisualModel->mControlSize;
3269 void Controller::AddDecoration( Actor& actor, bool needsClipping )
3271 if( NULL != mImpl->mEditableControlInterface )
3273 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
3277 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
3279 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
3281 if( NULL != mImpl->mEventData )
3283 switch( handleType )
3287 Event event( Event::GRAB_HANDLE_EVENT );
3288 event.p1.mUint = state;
3289 event.p2.mFloat = x;
3290 event.p3.mFloat = y;
3292 mImpl->mEventData->mEventQueue.push_back( event );
3295 case LEFT_SELECTION_HANDLE:
3297 Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
3298 event.p1.mUint = state;
3299 event.p2.mFloat = x;
3300 event.p3.mFloat = y;
3302 mImpl->mEventData->mEventQueue.push_back( event );
3305 case RIGHT_SELECTION_HANDLE:
3307 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
3308 event.p1.mUint = state;
3309 event.p2.mFloat = x;
3310 event.p3.mFloat = y;
3312 mImpl->mEventData->mEventQueue.push_back( event );
3315 case LEFT_SELECTION_HANDLE_MARKER:
3316 case RIGHT_SELECTION_HANDLE_MARKER:
3318 // Markers do not move the handles.
3321 case HANDLE_TYPE_COUNT:
3323 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
3327 mImpl->RequestRelayout();
3331 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
3333 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
3335 if( NULL == mImpl->mEventData )
3342 case Toolkit::TextSelectionPopup::CUT:
3344 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
3345 mImpl->mOperationsPending = ALL_OPERATIONS;
3347 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3348 !mImpl->IsPlaceholderAvailable() )
3350 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3354 ShowPlaceholderText();
3357 mImpl->mEventData->mUpdateCursorPosition = true;
3358 mImpl->mEventData->mScrollAfterDelete = true;
3360 mImpl->RequestRelayout();
3362 if( NULL != mImpl->mEditableControlInterface )
3364 mImpl->mEditableControlInterface->TextChanged();
3368 case Toolkit::TextSelectionPopup::COPY:
3370 mImpl->SendSelectionToClipboard( false ); // Text not modified
3372 mImpl->mEventData->mUpdateCursorPosition = true;
3374 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
3377 case Toolkit::TextSelectionPopup::PASTE:
3379 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
3382 case Toolkit::TextSelectionPopup::SELECT:
3384 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
3386 if( mImpl->mEventData->mSelectionEnabled )
3388 // Creates a SELECT event.
3389 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, SelectionType::INTERACTIVE );
3393 case Toolkit::TextSelectionPopup::SELECT_ALL:
3395 // Creates a SELECT_ALL event
3396 SelectEvent( 0.f, 0.f, SelectionType::ALL );
3399 case Toolkit::TextSelectionPopup::CLIPBOARD:
3401 mImpl->ShowClipboard();
3404 case Toolkit::TextSelectionPopup::NONE:
3412 void Controller::DisplayTimeExpired()
3414 mImpl->mEventData->mUpdateCursorPosition = true;
3415 // Apply modifications to the model
3416 mImpl->mOperationsPending = ALL_OPERATIONS;
3418 mImpl->RequestRelayout();
3421 // private : Update.
3423 void Controller::InsertText( const std::string& text, Controller::InsertType type )
3425 bool removedPrevious = false;
3426 bool removedSelected = false;
3427 bool maxLengthReached = false;
3429 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
3431 if( NULL == mImpl->mEventData )
3436 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
3437 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
3438 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3440 // TODO: At the moment the underline runs are only for pre-edit.
3441 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
3443 // Remove the previous InputMethodContext pre-edit.
3444 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
3446 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
3447 mImpl->mEventData->mPreEditLength,
3448 DONT_UPDATE_INPUT_STYLE );
3450 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
3451 mImpl->mEventData->mPreEditLength = 0u;
3455 // Remove the previous Selection.
3456 removedSelected = RemoveSelectedText();
3460 Vector<Character> utf32Characters;
3461 Length characterCount = 0u;
3465 // Convert text into UTF-32
3466 utf32Characters.Resize( text.size() );
3468 // This is a bit horrible but std::string returns a (signed) char*
3469 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
3471 // Transform a text array encoded in utf8 into an array encoded in utf32.
3472 // It returns the actual number of characters.
3473 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
3474 utf32Characters.Resize( characterCount );
3476 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
3477 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
3480 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
3482 // The placeholder text is no longer needed
3483 if( mImpl->IsShowingPlaceholderText() )
3488 mImpl->ChangeState( EventData::EDITING );
3490 // Handle the InputMethodContext (predicitive text) state changes
3491 if( COMMIT == type )
3493 // InputMethodContext is no longer handling key-events
3494 mImpl->ClearPreEditFlag();
3498 if( !mImpl->mEventData->mPreEditFlag )
3500 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
3502 // Record the start of the pre-edit text
3503 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
3506 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
3507 mImpl->mEventData->mPreEditFlag = true;
3509 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3512 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
3514 // Restrict new text to fit within Maximum characters setting.
3515 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
3516 maxLengthReached = ( characterCount > maxSizeOfNewText );
3518 // The cursor position.
3519 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3521 // Update the text's style.
3523 // Updates the text style runs by adding characters.
3524 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
3526 // Get the character index from the cursor index.
3527 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
3529 // Retrieve the text's style for the given index.
3531 mImpl->RetrieveDefaultInputStyle( style );
3532 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
3534 // Whether to add a new text color run.
3535 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor ) && !mImpl->mEventData->mInputStyle.isDefaultColor;
3537 // Whether to add a new font run.
3538 const bool addFontNameRun = ( style.familyName != mImpl->mEventData->mInputStyle.familyName ) && mImpl->mEventData->mInputStyle.isFamilyDefined;
3539 const bool addFontWeightRun = ( style.weight != mImpl->mEventData->mInputStyle.weight ) && mImpl->mEventData->mInputStyle.isWeightDefined;
3540 const bool addFontWidthRun = ( style.width != mImpl->mEventData->mInputStyle.width ) && mImpl->mEventData->mInputStyle.isWidthDefined;
3541 const bool addFontSlantRun = ( style.slant != mImpl->mEventData->mInputStyle.slant ) && mImpl->mEventData->mInputStyle.isSlantDefined;
3542 const bool addFontSizeRun = ( style.size != mImpl->mEventData->mInputStyle.size ) && mImpl->mEventData->mInputStyle.isSizeDefined ;
3547 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
3548 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
3550 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
3551 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
3552 colorRun.characterRun.characterIndex = cursorIndex;
3553 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3556 if( addFontNameRun ||
3562 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
3563 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
3565 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
3567 if( addFontNameRun )
3569 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
3570 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
3571 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
3572 fontDescriptionRun.familyDefined = true;
3574 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
3577 if( addFontWeightRun )
3579 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
3580 fontDescriptionRun.weightDefined = true;
3583 if( addFontWidthRun )
3585 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
3586 fontDescriptionRun.widthDefined = true;
3589 if( addFontSlantRun )
3591 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
3592 fontDescriptionRun.slantDefined = true;
3595 if( addFontSizeRun )
3597 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
3598 fontDescriptionRun.sizeDefined = true;
3601 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
3602 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3605 // Insert at current cursor position.
3606 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
3608 if( cursorIndex < numberOfCharactersInModel )
3610 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3614 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3617 // Mark the first paragraph to be updated.
3618 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3620 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3621 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3622 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
3623 mImpl->mTextUpdateInfo.mClearAll = true;
3627 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3628 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
3631 // Update the cursor index.
3632 cursorIndex += maxSizeOfNewText;
3634 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 );
3637 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
3638 mImpl->IsPlaceholderAvailable() )
3640 // Show place-holder if empty after removing the pre-edit text
3641 ShowPlaceholderText();
3642 mImpl->mEventData->mUpdateCursorPosition = true;
3643 mImpl->ClearPreEditFlag();
3645 else if( removedPrevious ||
3647 ( 0 != utf32Characters.Count() ) )
3649 // Queue an inserted event
3650 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
3652 mImpl->mEventData->mUpdateCursorPosition = true;
3653 if( removedSelected )
3655 mImpl->mEventData->mScrollAfterDelete = true;
3659 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3663 if( maxLengthReached )
3665 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
3667 mImpl->ResetInputMethodContext();
3669 if( NULL != mImpl->mEditableControlInterface )
3671 // Do this last since it provides callbacks into application code
3672 mImpl->mEditableControlInterface->MaxLengthReached();
3677 void Controller::PasteText( const std::string& stringToPaste )
3679 InsertText( stringToPaste, Text::Controller::COMMIT );
3680 mImpl->ChangeState( EventData::EDITING );
3681 mImpl->RequestRelayout();
3683 if( NULL != mImpl->mEditableControlInterface )
3685 // Do this last since it provides callbacks into application code
3686 mImpl->mEditableControlInterface->TextChanged();
3690 bool Controller::RemoveText( int cursorOffset,
3691 int numberOfCharacters,
3692 UpdateInputStyleType type )
3694 bool removed = false;
3696 if( NULL == mImpl->mEventData )
3701 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
3702 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
3704 if( !mImpl->IsShowingPlaceholderText() )
3706 // Delete at current cursor position
3707 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
3708 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3710 CharacterIndex cursorIndex = 0;
3712 // Validate the cursor position & number of characters
3713 if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
3715 cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
3718 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
3720 numberOfCharacters = currentText.Count() - cursorIndex;
3723 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.
3724 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
3726 // Mark the paragraphs to be updated.
3727 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3729 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3730 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3731 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
3732 mImpl->mTextUpdateInfo.mClearAll = true;
3736 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3737 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
3740 // Update the input style and remove the text's style before removing the text.
3742 if( UPDATE_INPUT_STYLE == type )
3744 // Keep a copy of the current input style.
3745 InputStyle currentInputStyle;
3746 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
3748 // Set first the default input style.
3749 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
3751 // Update the input style.
3752 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
3754 // Compare if the input style has changed.
3755 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
3757 if( hasInputStyleChanged )
3759 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
3760 // Queue the input style changed signal.
3761 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
3765 // If the number of current text and the number of characters to be deleted are same,
3766 // it means all texts should be removed and all Preedit variables should be initialized.
3767 if( ( currentText.Count() - numberOfCharacters == 0 ) && ( cursorIndex == 0 ) )
3769 mImpl->ClearPreEditFlag();
3772 // Updates the text style runs by removing characters. Runs with no characters are removed.
3773 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
3775 // Remove the characters.
3776 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
3777 Vector<Character>::Iterator last = first + numberOfCharacters;
3779 currentText.Erase( first, last );
3781 // Cursor position retreat
3782 oldCursorIndex = cursorIndex;
3784 mImpl->mEventData->mScrollAfterDelete = true;
3786 if( EventData::INACTIVE == mImpl->mEventData->mState )
3788 mImpl->ChangeState( EventData::EDITING );
3791 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
3799 bool Controller::RemoveSelectedText()
3801 bool textRemoved( false );
3803 if( EventData::SELECTING == mImpl->mEventData->mState )
3805 std::string removedString;
3806 mImpl->RetrieveSelection( removedString, true );
3808 if( !removedString.empty() )
3811 mImpl->ChangeState( EventData::EDITING );
3818 std::string Controller::GetSelectedText()
3821 if( EventData::SELECTING == mImpl->mEventData->mState )
3823 mImpl->RetrieveSelection( text, false );
3828 // private : Relayout.
3830 bool Controller::DoRelayout( const Size& size,
3831 OperationsMask operationsRequired,
3834 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
3835 bool viewUpdated( false );
3837 // Calculate the operations to be done.
3838 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
3840 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
3841 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
3843 // Get the current layout size.
3844 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3846 if( NO_OPERATION != ( LAYOUT & operations ) )
3848 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
3850 // Some vectors with data needed to layout and reorder may be void
3851 // after the first time the text has been laid out.
3852 // Fill the vectors again.
3854 // Calculate the number of glyphs to layout.
3855 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
3856 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
3857 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
3858 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
3860 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
3861 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
3863 // Make sure the index is not out of bound
3864 if ( charactersToGlyph.Count() != glyphsPerCharacter.Count() ||
3865 requestedNumberOfCharacters > charactersToGlyph.Count() ||
3866 ( lastIndex > charactersToGlyph.Count() && charactersToGlyph.Count() > 0u ) )
3868 std::string currentText;
3869 GetText( currentText );
3871 DALI_LOG_ERROR( "Controller::DoRelayout: Attempting to access invalid buffer\n" );
3872 DALI_LOG_ERROR( "Current text is: %s\n", currentText.c_str() );
3873 DALI_LOG_ERROR( "startIndex: %u, lastIndex: %u, requestedNumberOfCharacters: %u, charactersToGlyph.Count = %lu, glyphsPerCharacter.Count = %lu\n", startIndex, lastIndex, requestedNumberOfCharacters, charactersToGlyph.Count(), glyphsPerCharacter.Count());
3878 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
3879 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
3881 if( 0u == totalNumberOfGlyphs )
3883 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3885 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
3888 // Nothing else to do if there is no glyphs.
3889 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
3893 // Set the layout parameters.
3894 Layout::Parameters layoutParameters( size,
3897 // Resize the vector of positions to have the same size than the vector of glyphs.
3898 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
3899 glyphPositions.Resize( totalNumberOfGlyphs );
3901 // Whether the last character is a new paragraph character.
3902 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
3903 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
3904 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
3906 // The initial glyph and the number of glyphs to layout.
3907 layoutParameters.startGlyphIndex = startGlyphIndex;
3908 layoutParameters.numberOfGlyphs = numberOfGlyphs;
3909 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
3910 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
3912 // Update the ellipsis
3913 bool elideTextEnabled = mImpl->mModel->mElideEnabled;
3915 if( NULL != mImpl->mEventData )
3917 if( mImpl->mEventData->mPlaceholderEllipsisFlag && mImpl->IsShowingPlaceholderText() )
3919 elideTextEnabled = mImpl->mEventData->mIsPlaceholderElideEnabled;
3921 else if( EventData::INACTIVE != mImpl->mEventData->mState )
3923 // Disable ellipsis when editing
3924 elideTextEnabled = false;
3927 // Reset the scroll position in inactive state
3928 if( elideTextEnabled && ( mImpl->mEventData->mState == EventData::INACTIVE ) )
3930 ResetScrollPosition();
3934 // Update the visual model.
3935 bool isAutoScrollEnabled = mImpl->mIsAutoScrollEnabled;
3937 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
3940 isAutoScrollEnabled );
3941 mImpl->mIsAutoScrollEnabled = isAutoScrollEnabled;
3943 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
3947 layoutSize = newLayoutSize;
3949 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
3951 mImpl->mIsTextDirectionRTL = false;
3954 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && !mImpl->mModel->mVisualModel->mLines.Empty() )
3956 mImpl->mIsTextDirectionRTL = mImpl->mModel->mVisualModel->mLines[0u].direction;
3959 // Sets the layout size.
3960 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3962 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
3967 if( NO_OPERATION != ( ALIGN & operations ) )
3969 // The laid-out lines.
3970 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
3972 CharacterIndex alignStartIndex = startIndex;
3973 Length alignRequestedNumberOfCharacters = requestedNumberOfCharacters;
3975 // the whole text needs to be full aligned.
3976 // If you do not do a full aligned, only the last line of the multiline input is aligned.
3977 if( mImpl->mEventData && mImpl->mEventData->mUpdateAlignment )
3979 alignStartIndex = 0u;
3980 alignRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
3981 mImpl->mEventData->mUpdateAlignment = false;
3984 // Need to align with the control's size as the text may contain lines
3985 // starting either with left to right text or right to left.
3986 mImpl->mLayoutEngine.Align( size,
3988 alignRequestedNumberOfCharacters,
3989 mImpl->mModel->mHorizontalAlignment,
3991 mImpl->mModel->mAlignmentOffset,
3992 mImpl->mLayoutDirection,
3993 mImpl->mModel->mMatchSystemLanguageDirection );
3997 #if defined(DEBUG_ENABLED)
3998 std::string currentText;
3999 GetText( currentText );
4000 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mIsTextDirectionRTL[%s] [%s]\n", this, (mImpl->mIsTextDirectionRTL)?"true":"false", currentText.c_str() );
4002 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
4006 void Controller::CalculateVerticalOffset( const Size& controlSize )
4008 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
4010 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
4012 // Get the line height of the default font.
4013 layoutSize.height = mImpl->GetDefaultFontLineHeight();
4016 switch( mImpl->mModel->mVerticalAlignment )
4018 case VerticalAlignment::TOP:
4020 mImpl->mModel->mScrollPosition.y = 0.f;
4023 case VerticalAlignment::CENTER:
4025 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
4028 case VerticalAlignment::BOTTOM:
4030 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
4036 // private : Events.
4038 void Controller::ProcessModifyEvents()
4040 Vector<ModifyEvent>& events = mImpl->mModifyEvents;
4042 if( 0u == events.Count() )
4048 for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
4049 endIt = events.End();
4053 const ModifyEvent& event = *it;
4055 if( ModifyEvent::TEXT_REPLACED == event.type )
4057 // A (single) replace event should come first, otherwise we wasted time processing NOOP events
4058 DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
4060 TextReplacedEvent();
4062 else if( ModifyEvent::TEXT_INSERTED == event.type )
4064 TextInsertedEvent();
4066 else if( ModifyEvent::TEXT_DELETED == event.type )
4068 // Placeholder-text cannot be deleted
4069 if( !mImpl->IsShowingPlaceholderText() )
4076 if( NULL != mImpl->mEventData )
4078 // When the text is being modified, delay cursor blinking
4079 mImpl->mEventData->mDecorator->DelayCursorBlink();
4081 // Update selection position after modifying the text
4082 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
4083 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
4086 // Discard temporary text
4090 void Controller::TextReplacedEvent()
4092 // The natural size needs to be re-calculated.
4093 mImpl->mRecalculateNaturalSize = true;
4095 // The text direction needs to be updated.
4096 mImpl->mUpdateTextDirection = true;
4098 // Apply modifications to the model
4099 mImpl->mOperationsPending = ALL_OPERATIONS;
4102 void Controller::TextInsertedEvent()
4104 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
4106 if( NULL == mImpl->mEventData )
4111 mImpl->mEventData->mCheckScrollAmount = true;
4113 // The natural size needs to be re-calculated.
4114 mImpl->mRecalculateNaturalSize = true;
4116 // The text direction needs to be updated.
4117 mImpl->mUpdateTextDirection = true;
4119 // Apply modifications to the model; TODO - Optimize this
4120 mImpl->mOperationsPending = ALL_OPERATIONS;
4123 void Controller::TextDeletedEvent()
4125 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
4127 if( NULL == mImpl->mEventData )
4132 mImpl->mEventData->mCheckScrollAmount = true;
4134 // The natural size needs to be re-calculated.
4135 mImpl->mRecalculateNaturalSize = true;
4137 // The text direction needs to be updated.
4138 mImpl->mUpdateTextDirection = true;
4140 // Apply modifications to the model; TODO - Optimize this
4141 mImpl->mOperationsPending = ALL_OPERATIONS;
4144 bool Controller::DeleteEvent( int keyCode )
4146 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p KeyCode : %d \n", this, keyCode );
4148 bool removed = false;
4150 if( NULL == mImpl->mEventData )
4155 // InputMethodContext is no longer handling key-events
4156 mImpl->ClearPreEditFlag();
4158 if( EventData::SELECTING == mImpl->mEventData->mState )
4160 removed = RemoveSelectedText();
4162 else if( ( mImpl->mEventData->mPrimaryCursorPosition > 0 ) && ( keyCode == Dali::DALI_KEY_BACKSPACE) )
4164 // Remove the character before the current cursor position
4165 removed = RemoveText( -1,
4167 UPDATE_INPUT_STYLE );
4169 else if( keyCode == Dali::DevelKey::DALI_KEY_DELETE )
4171 // Remove the character after the current cursor position
4172 removed = RemoveText( 0,
4174 UPDATE_INPUT_STYLE );
4179 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
4180 !mImpl->IsPlaceholderAvailable() )
4182 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
4186 ShowPlaceholderText();
4188 mImpl->mEventData->mUpdateCursorPosition = true;
4189 mImpl->mEventData->mScrollAfterDelete = true;
4195 // private : Helpers.
4197 void Controller::ResetText()
4200 mImpl->mModel->mLogicalModel->mText.Clear();
4202 // Reset the embedded images buffer.
4203 mImpl->mModel->mLogicalModel->ClearEmbeddedImages();
4205 // We have cleared everything including the placeholder-text
4206 mImpl->PlaceholderCleared();
4208 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4209 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4210 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
4212 // Clear any previous text.
4213 mImpl->mTextUpdateInfo.mClearAll = true;
4215 // The natural size needs to be re-calculated.
4216 mImpl->mRecalculateNaturalSize = true;
4218 // The text direction needs to be updated.
4219 mImpl->mUpdateTextDirection = true;
4221 // Apply modifications to the model
4222 mImpl->mOperationsPending = ALL_OPERATIONS;
4225 void Controller::ShowPlaceholderText()
4227 if( mImpl->IsPlaceholderAvailable() )
4229 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
4231 if( NULL == mImpl->mEventData )
4236 mImpl->mEventData->mIsShowingPlaceholderText = true;
4238 // Disable handles when showing place-holder text
4239 mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
4240 mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
4241 mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
4243 const char* text( NULL );
4246 // TODO - Switch Placeholder text when changing state
4247 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
4248 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
4250 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
4251 size = mImpl->mEventData->mPlaceholderTextActive.size();
4255 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
4256 size = mImpl->mEventData->mPlaceholderTextInactive.size();
4259 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4260 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4262 // Reset model for showing placeholder.
4263 mImpl->mModel->mLogicalModel->mText.Clear();
4264 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
4266 // Convert text into UTF-32
4267 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
4268 utf32Characters.Resize( size );
4270 // This is a bit horrible but std::string returns a (signed) char*
4271 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
4273 // Transform a text array encoded in utf8 into an array encoded in utf32.
4274 // It returns the actual number of characters.
4275 const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
4276 utf32Characters.Resize( characterCount );
4278 // The characters to be added.
4279 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
4281 // Reset the cursor position
4282 mImpl->mEventData->mPrimaryCursorPosition = 0;
4284 // The natural size needs to be re-calculated.
4285 mImpl->mRecalculateNaturalSize = true;
4287 // The text direction needs to be updated.
4288 mImpl->mUpdateTextDirection = true;
4290 // Apply modifications to the model
4291 mImpl->mOperationsPending = ALL_OPERATIONS;
4293 // Update the rest of the model during size negotiation
4294 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
4298 void Controller::ClearFontData()
4300 if( mImpl->mFontDefaults )
4302 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
4305 // Set flags to update the model.
4306 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4307 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4308 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
4310 mImpl->mTextUpdateInfo.mClearAll = true;
4311 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
4312 mImpl->mRecalculateNaturalSize = true;
4314 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
4320 UPDATE_LAYOUT_SIZE |
4325 void Controller::ClearStyleData()
4327 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
4328 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
4331 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
4333 // Reset the cursor position
4334 if( NULL != mImpl->mEventData )
4336 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
4338 // Update the cursor if it's in editing mode.
4339 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
4341 mImpl->mEventData->mUpdateCursorPosition = true;
4346 void Controller::ResetScrollPosition()
4348 if( NULL != mImpl->mEventData )
4350 // Reset the scroll position.
4351 mImpl->mModel->mScrollPosition = Vector2::ZERO;
4352 mImpl->mEventData->mScrollAfterUpdatePosition = true;
4356 void Controller::SetControlInterface( ControlInterface* controlInterface )
4358 mImpl->mControlInterface = controlInterface;
4361 bool Controller::ShouldClearFocusOnEscape() const
4363 return mImpl->mShouldClearFocusOnEscape;
4366 Actor Controller::CreateBackgroundActor()
4368 return mImpl->CreateBackgroundActor();
4371 // private : Private contructors & copy operator.
4373 Controller::Controller()
4376 mImpl = new Controller::Impl( NULL, NULL );
4379 Controller::Controller( ControlInterface* controlInterface )
4381 mImpl = new Controller::Impl( controlInterface, NULL );
4384 Controller::Controller( ControlInterface* controlInterface,
4385 EditableControlInterface* editableControlInterface )
4387 mImpl = new Controller::Impl( controlInterface,
4388 editableControlInterface );
4391 // The copy constructor and operator are left unimplemented.
4393 // protected : Destructor.
4395 Controller::~Controller()
4402 } // namespace Toolkit