2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/text/text-controller.h>
25 #include <dali/public-api/adaptor-framework/key.h>
26 #include <dali/integration-api/debug.h>
27 #include <dali/devel-api/adaptor-framework/clipboard-event-notifier.h>
28 #include <dali/devel-api/text-abstraction/font-client.h>
29 #include <dali/devel-api/adaptor-framework/key-devel.h>
32 #include <dali-toolkit/public-api/controls/text-controls/placeholder-properties.h>
33 #include <dali-toolkit/internal/text/bidirectional-support.h>
34 #include <dali-toolkit/internal/text/character-set-conversion.h>
35 #include <dali-toolkit/internal/text/layouts/layout-parameters.h>
36 #include <dali-toolkit/internal/text/markup-processor.h>
37 #include <dali-toolkit/internal/text/multi-language-support.h>
38 #include <dali-toolkit/internal/text/text-controller-impl.h>
39 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
40 #include <dali-toolkit/internal/text/text-font-style.h>
45 #if defined(DEBUG_ENABLED)
46 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
49 const float MAX_FLOAT = std::numeric_limits<float>::max();
51 const std::string EMPTY_STRING("");
53 const std::string KEY_C_NAME = "c";
54 const std::string KEY_V_NAME = "v";
55 const std::string KEY_X_NAME = "x";
57 const char * const PLACEHOLDER_TEXT = "text";
58 const char * const PLACEHOLDER_TEXT_FOCUSED = "textFocused";
59 const char * const PLACEHOLDER_COLOR = "color";
60 const char * const PLACEHOLDER_FONT_FAMILY = "fontFamily";
61 const char * const PLACEHOLDER_FONT_STYLE = "fontStyle";
62 const char * const PLACEHOLDER_POINT_SIZE = "pointSize";
63 const char * const PLACEHOLDER_PIXEL_SIZE = "pixelSize";
64 const char * const PLACEHOLDER_ELLIPSIS = "ellipsis";
65 const unsigned int MAX_TEXT_LENGTH = 1024u * 32u;
67 float ConvertToEven( float value )
69 int intValue(static_cast<int>( value ));
70 return static_cast<float>( intValue + ( intValue & 1 ) );
73 int ConvertPixelToPint( float pixel )
75 unsigned int horizontalDpi = 0u;
76 unsigned int verticalDpi = 0u;
77 Dali::TextAbstraction::FontClient fontClient = Dali::TextAbstraction::FontClient::Get();
78 fontClient.GetDpi( horizontalDpi, verticalDpi );
80 return ( pixel * 72.f ) / static_cast< float >( horizontalDpi );
96 * @brief Adds a new font description run for the selected text.
98 * The new font parameters are added after the call to this method.
100 * @param[in] eventData The event data pointer.
101 * @param[in] logicalModel The logical model where to add the new font description run.
102 * @param[out] startOfSelectedText Index to the first selected character.
103 * @param[out] lengthOfSelectedText Number of selected characters.
105 FontDescriptionRun& UpdateSelectionFontStyleRun( EventData* eventData,
106 LogicalModelPtr logicalModel,
107 CharacterIndex& startOfSelectedText,
108 Length& lengthOfSelectedText )
110 const bool handlesCrossed = eventData->mLeftSelectionPosition > eventData->mRightSelectionPosition;
112 // Get start and end position of selection
113 startOfSelectedText = handlesCrossed ? eventData->mRightSelectionPosition : eventData->mLeftSelectionPosition;
114 lengthOfSelectedText = ( handlesCrossed ? eventData->mLeftSelectionPosition : eventData->mRightSelectionPosition ) - startOfSelectedText;
117 const VectorBase::SizeType numberOfRuns = logicalModel->mFontDescriptionRuns.Count();
118 logicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
120 FontDescriptionRun& fontDescriptionRun = *( logicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
122 fontDescriptionRun.characterRun.characterIndex = startOfSelectedText;
123 fontDescriptionRun.characterRun.numberOfCharacters = lengthOfSelectedText;
125 // Recalculate the selection highlight as the metrics may have changed.
126 eventData->mUpdateLeftSelectionPosition = true;
127 eventData->mUpdateRightSelectionPosition = true;
128 eventData->mUpdateHighlightBox = true;
130 return fontDescriptionRun;
133 // public : Constructor.
135 ControllerPtr Controller::New()
137 return ControllerPtr( new Controller() );
140 ControllerPtr Controller::New( ControlInterface* controlInterface )
142 return ControllerPtr( new Controller( controlInterface ) );
145 ControllerPtr Controller::New( ControlInterface* controlInterface,
146 EditableControlInterface* editableControlInterface )
148 return ControllerPtr( new Controller( controlInterface,
149 editableControlInterface ) );
152 // public : Configure the text controller.
154 void Controller::EnableTextInput( DecoratorPtr decorator, InputMethodContext& inputMethodContext )
158 delete mImpl->mEventData;
159 mImpl->mEventData = NULL;
161 // Nothing else to do.
165 if( NULL == mImpl->mEventData )
167 mImpl->mEventData = new EventData( decorator, inputMethodContext );
171 void Controller::SetGlyphType( TextAbstraction::GlyphType glyphType )
173 // Metrics for bitmap & vector based glyphs are different
174 mImpl->mMetrics->SetGlyphType( glyphType );
176 // Clear the font-specific data
179 mImpl->RequestRelayout();
182 void Controller::SetMarkupProcessorEnabled( bool enable )
184 if( enable != mImpl->mMarkupProcessorEnabled )
186 //If Text was already set, call the SetText again for enabling or disabling markup
187 mImpl->mMarkupProcessorEnabled = enable;
194 bool Controller::IsMarkupProcessorEnabled() const
196 return mImpl->mMarkupProcessorEnabled;
199 void Controller::SetAutoScrollEnabled( bool enable )
201 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled[%s] SingleBox[%s]-> [%p]\n", (enable)?"true":"false", ( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX)?"true":"false", this );
203 if( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX )
207 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled for SINGLE_LINE_BOX\n" );
208 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
218 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled Disabling autoscroll\n");
219 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
226 mImpl->mIsAutoScrollEnabled = enable;
227 mImpl->RequestRelayout();
231 DALI_LOG_WARNING( "Attempted AutoScrolling on a non SINGLE_LINE_BOX, request ignored\n" );
232 mImpl->mIsAutoScrollEnabled = false;
236 bool Controller::IsAutoScrollEnabled() const
238 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::IsAutoScrollEnabled[%s]\n", mImpl->mIsAutoScrollEnabled?"true":"false" );
240 return mImpl->mIsAutoScrollEnabled;
243 CharacterDirection Controller::GetAutoScrollDirection() const
245 return mImpl->mIsTextDirectionRTL;
248 float Controller::GetAutoScrollLineAlignment() const
252 if( mImpl->mModel->mVisualModel &&
253 ( 0u != mImpl->mModel->mVisualModel->mLines.Count() ) )
255 offset = ( *mImpl->mModel->mVisualModel->mLines.Begin() ).alignmentOffset;
261 void Controller::SetHorizontalScrollEnabled( bool enable )
263 if( ( NULL != mImpl->mEventData ) &&
264 mImpl->mEventData->mDecorator )
266 mImpl->mEventData->mDecorator->SetHorizontalScrollEnabled( enable );
269 bool Controller::IsHorizontalScrollEnabled() const
271 if( ( NULL != mImpl->mEventData ) &&
272 mImpl->mEventData->mDecorator )
274 return mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
280 void Controller::SetVerticalScrollEnabled( bool enable )
282 if( ( NULL != mImpl->mEventData ) &&
283 mImpl->mEventData->mDecorator )
285 if( mImpl->mEventData->mDecorator )
287 mImpl->mEventData->mDecorator->SetVerticalScrollEnabled( enable );
292 bool Controller::IsVerticalScrollEnabled() const
294 if( ( NULL != mImpl->mEventData ) &&
295 mImpl->mEventData->mDecorator )
297 return mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
303 void Controller::SetSmoothHandlePanEnabled( bool enable )
305 if( ( NULL != mImpl->mEventData ) &&
306 mImpl->mEventData->mDecorator )
308 mImpl->mEventData->mDecorator->SetSmoothHandlePanEnabled( enable );
312 bool Controller::IsSmoothHandlePanEnabled() const
314 if( ( NULL != mImpl->mEventData ) &&
315 mImpl->mEventData->mDecorator )
317 return mImpl->mEventData->mDecorator->IsSmoothHandlePanEnabled();
323 void Controller::SetMaximumNumberOfCharacters( Length maxCharacters )
325 mImpl->mMaximumNumberOfCharacters = std::min( maxCharacters, MAX_TEXT_LENGTH );
328 int Controller::GetMaximumNumberOfCharacters()
330 return mImpl->mMaximumNumberOfCharacters;
333 void Controller::SetEnableCursorBlink( bool enable )
335 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "TextInput disabled" );
337 if( NULL != mImpl->mEventData )
339 mImpl->mEventData->mCursorBlinkEnabled = enable;
342 mImpl->mEventData->mDecorator )
344 mImpl->mEventData->mDecorator->StopCursorBlink();
349 bool Controller::GetEnableCursorBlink() const
351 if( NULL != mImpl->mEventData )
353 return mImpl->mEventData->mCursorBlinkEnabled;
359 void Controller::SetMultiLineEnabled( bool enable )
361 const Layout::Engine::Type layout = enable ? Layout::Engine::MULTI_LINE_BOX : Layout::Engine::SINGLE_LINE_BOX;
363 if( layout != mImpl->mLayoutEngine.GetLayout() )
365 // Set the layout type.
366 mImpl->mLayoutEngine.SetLayout( layout );
368 // Set the flags to redo the layout operations
369 const OperationsMask layoutOperations = static_cast<OperationsMask>( LAYOUT |
374 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
375 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | layoutOperations );
377 // Need to recalculate natural size
378 mImpl->mRecalculateNaturalSize = true;
380 mImpl->RequestRelayout();
384 bool Controller::IsMultiLineEnabled() const
386 return Layout::Engine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
389 void Controller::SetHorizontalAlignment( Text::HorizontalAlignment::Type alignment )
391 if( alignment != mImpl->mModel->mHorizontalAlignment )
393 // Set the alignment.
394 mImpl->mModel->mHorizontalAlignment = alignment;
396 // Set the flag to redo the alignment operation.
397 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
399 if( mImpl->mEventData )
401 mImpl->mEventData->mUpdateAlignment = true;
403 // Update the cursor if it's in editing mode
404 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
406 mImpl->ChangeState( EventData::EDITING );
407 mImpl->mEventData->mUpdateCursorPosition = true;
411 mImpl->RequestRelayout();
415 Text::HorizontalAlignment::Type Controller::GetHorizontalAlignment() const
417 return mImpl->mModel->mHorizontalAlignment;
420 void Controller::SetVerticalAlignment( VerticalAlignment::Type alignment )
422 if( alignment != mImpl->mModel->mVerticalAlignment )
424 // Set the alignment.
425 mImpl->mModel->mVerticalAlignment = alignment;
427 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
429 mImpl->RequestRelayout();
433 VerticalAlignment::Type Controller::GetVerticalAlignment() const
435 return mImpl->mModel->mVerticalAlignment;
438 bool Controller::IsIgnoreSpacesAfterText() const
440 return mImpl->mModel->mIgnoreSpacesAfterText;
443 void Controller::SetIgnoreSpacesAfterText( bool ignore )
445 mImpl->mModel->mIgnoreSpacesAfterText = ignore;
448 bool Controller::IsMatchSystemLanguageDirection() const
450 return mImpl->mModel->mMatchSystemLanguageDirection;
453 void Controller::SetMatchSystemLanguageDirection( bool match )
455 mImpl->mModel->mMatchSystemLanguageDirection = match;
458 void Controller::SetLayoutDirection( Dali::LayoutDirection::Type layoutDirection )
460 mImpl->mLayoutDirection = layoutDirection;
463 bool Controller::IsShowingRealText() const
465 return mImpl->IsShowingRealText();
469 void Controller::SetLineWrapMode( Text::LineWrap::Mode lineWrapMode )
471 if( lineWrapMode != mImpl->mModel->mLineWrapMode )
473 // Set the text wrap mode.
474 mImpl->mModel->mLineWrapMode = lineWrapMode;
477 // Update Text layout for applying wrap mode
478 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
483 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
484 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
485 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
488 mImpl->RequestRelayout();
492 Text::LineWrap::Mode Controller::GetLineWrapMode() const
494 return mImpl->mModel->mLineWrapMode;
497 void Controller::SetTextElideEnabled( bool enabled )
499 mImpl->mModel->mElideEnabled = enabled;
502 bool Controller::IsTextElideEnabled() const
504 return mImpl->mModel->mElideEnabled;
507 void Controller::SetTextFitEnabled(bool enabled)
509 mImpl->mTextFitEnabled = enabled;
512 bool Controller::IsTextFitEnabled() const
514 return mImpl->mTextFitEnabled;
517 void Controller::SetTextFitMinSize( float minSize, FontSizeType type )
523 mImpl->mTextFitMinSize = minSize;
528 mImpl->mTextFitMinSize = ConvertPixelToPint( minSize );
534 float Controller::GetTextFitMinSize() const
536 return mImpl->mTextFitMinSize;
539 void Controller::SetTextFitMaxSize( float maxSize, FontSizeType type )
545 mImpl->mTextFitMaxSize = maxSize;
550 mImpl->mTextFitMaxSize = ConvertPixelToPint( maxSize );
556 float Controller::GetTextFitMaxSize() const
558 return mImpl->mTextFitMaxSize;
561 void Controller::SetTextFitStepSize( float step, FontSizeType type )
567 mImpl->mTextFitStepSize = step;
572 mImpl->mTextFitStepSize = ConvertPixelToPint( step );
578 float Controller::GetTextFitStepSize() const
580 return mImpl->mTextFitStepSize;
583 void Controller::SetTextFitContentSize(Vector2 size)
585 mImpl->mTextFitContentSize = size;
588 Vector2 Controller::GetTextFitContentSize() const
590 return mImpl->mTextFitContentSize;
593 void Controller::SetPlaceholderTextElideEnabled( bool enabled )
595 mImpl->mEventData->mIsPlaceholderElideEnabled = enabled;
596 mImpl->mEventData->mPlaceholderEllipsisFlag = true;
598 // Update placeholder if there is no text
599 if( mImpl->IsShowingPlaceholderText() ||
600 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
602 ShowPlaceholderText();
606 bool Controller::IsPlaceholderTextElideEnabled() const
608 return mImpl->mEventData->mIsPlaceholderElideEnabled;
611 void Controller::SetSelectionEnabled( bool enabled )
613 mImpl->mEventData->mSelectionEnabled = enabled;
616 bool Controller::IsSelectionEnabled() const
618 return mImpl->mEventData->mSelectionEnabled;
621 void Controller::SetShiftSelectionEnabled( bool enabled )
623 mImpl->mEventData->mShiftSelectionFlag = enabled;
626 bool Controller::IsShiftSelectionEnabled() const
628 return mImpl->mEventData->mShiftSelectionFlag;
631 void Controller::SetGrabHandleEnabled( bool enabled )
633 mImpl->mEventData->mGrabHandleEnabled = enabled;
636 bool Controller::IsGrabHandleEnabled() const
638 return mImpl->mEventData->mGrabHandleEnabled;
641 void Controller::SetGrabHandlePopupEnabled(bool enabled)
643 mImpl->mEventData->mGrabHandlePopupEnabled = enabled;
646 bool Controller::IsGrabHandlePopupEnabled() const
648 return mImpl->mEventData->mGrabHandlePopupEnabled;
653 void Controller::SetText( const std::string& text )
655 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" );
657 // Reset keyboard as text changed
658 mImpl->ResetInputMethodContext();
660 // Remove the previously set text and style.
666 CharacterIndex lastCursorIndex = 0u;
668 if( NULL != mImpl->mEventData )
670 // If popup shown then hide it by switching to Editing state
671 if( ( EventData::SELECTING == mImpl->mEventData->mState ) ||
672 ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
673 ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) ||
674 ( EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState ) )
676 mImpl->ChangeState( EventData::EDITING );
682 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mTextColor );
684 MarkupProcessData markupProcessData( mImpl->mModel->mLogicalModel->mColorRuns,
685 mImpl->mModel->mLogicalModel->mFontDescriptionRuns,
686 mImpl->mModel->mLogicalModel->mEmbeddedItems );
688 Length textSize = 0u;
689 const uint8_t* utf8 = NULL;
690 if( mImpl->mMarkupProcessorEnabled )
692 ProcessMarkupString( text, markupProcessData );
693 textSize = markupProcessData.markupProcessedText.size();
695 // This is a bit horrible but std::string returns a (signed) char*
696 utf8 = reinterpret_cast<const uint8_t*>( markupProcessData.markupProcessedText.c_str() );
700 textSize = text.size();
702 // This is a bit horrible but std::string returns a (signed) char*
703 utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
706 // Limit the text size. If the text size is too large, crash or deadlock will occur.
707 if( textSize > MAX_TEXT_LENGTH )
709 DALI_LOG_WARNING( "The text size is too large(%d), limit the length to 32,768u\n", textSize );
710 textSize = MAX_TEXT_LENGTH;
713 // Convert text into UTF-32
714 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
715 utf32Characters.Resize( textSize );
717 // Transform a text array encoded in utf8 into an array encoded in utf32.
718 // It returns the actual number of characters.
719 Length characterCount = Utf8ToUtf32( utf8, textSize, utf32Characters.Begin() );
720 utf32Characters.Resize( characterCount );
722 DALI_ASSERT_DEBUG( textSize >= characterCount && "Invalid UTF32 conversion length" );
723 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", this, textSize, mImpl->mModel->mLogicalModel->mText.Count() );
725 // The characters to be added.
726 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
728 // To reset the cursor position
729 lastCursorIndex = characterCount;
731 // Update the rest of the model during size negotiation
732 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
734 // The natural size needs to be re-calculated.
735 mImpl->mRecalculateNaturalSize = true;
737 // The text direction needs to be updated.
738 mImpl->mUpdateTextDirection = true;
740 // Apply modifications to the model
741 mImpl->mOperationsPending = ALL_OPERATIONS;
745 ShowPlaceholderText();
748 // Resets the cursor position.
749 ResetCursorPosition( lastCursorIndex );
751 // Scrolls the text to make the cursor visible.
752 ResetScrollPosition();
754 mImpl->RequestRelayout();
756 if( NULL != mImpl->mEventData )
758 // Cancel previously queued events
759 mImpl->mEventData->mEventQueue.clear();
762 // Do this last since it provides callbacks into application code.
763 if( NULL != mImpl->mEditableControlInterface )
765 mImpl->mEditableControlInterface->TextChanged();
769 void Controller::GetText( std::string& text ) const
771 if( !mImpl->IsShowingPlaceholderText() )
773 // Retrieves the text string.
774 mImpl->GetText( 0u, text );
778 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this );
782 void Controller::SetPlaceholderText( PlaceholderType type, const std::string& text )
784 if( NULL != mImpl->mEventData )
786 if( PLACEHOLDER_TYPE_INACTIVE == type )
788 mImpl->mEventData->mPlaceholderTextInactive = text;
792 mImpl->mEventData->mPlaceholderTextActive = text;
795 // Update placeholder if there is no text
796 if( mImpl->IsShowingPlaceholderText() ||
797 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
799 ShowPlaceholderText();
804 void Controller::GetPlaceholderText( PlaceholderType type, std::string& text ) const
806 if( NULL != mImpl->mEventData )
808 if( PLACEHOLDER_TYPE_INACTIVE == type )
810 text = mImpl->mEventData->mPlaceholderTextInactive;
814 text = mImpl->mEventData->mPlaceholderTextActive;
819 void Controller::UpdateAfterFontChange( const std::string& newDefaultFont )
821 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
823 if( !mImpl->mFontDefaults->familyDefined ) // If user defined font then should not update when system font changes
825 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
826 mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
830 mImpl->RequestRelayout();
834 // public : Default style & Input style
836 void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
838 if( NULL == mImpl->mFontDefaults )
840 mImpl->mFontDefaults = new FontDefaults();
843 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
844 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
845 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
847 // Clear the font-specific data
850 mImpl->RequestRelayout();
853 const std::string& Controller::GetDefaultFontFamily() const
855 if( NULL != mImpl->mFontDefaults )
857 return mImpl->mFontDefaults->mFontDescription.family;
863 void Controller::SetPlaceholderFontFamily( const std::string& placeholderTextFontFamily )
865 if( NULL != mImpl->mEventData )
867 if( NULL == mImpl->mEventData->mPlaceholderFont )
869 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
872 mImpl->mEventData->mPlaceholderFont->mFontDescription.family = placeholderTextFontFamily;
873 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetPlaceholderFontFamily %s\n", placeholderTextFontFamily.c_str());
874 mImpl->mEventData->mPlaceholderFont->familyDefined = !placeholderTextFontFamily.empty();
876 mImpl->RequestRelayout();
880 const std::string& Controller::GetPlaceholderFontFamily() const
882 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
884 return mImpl->mEventData->mPlaceholderFont->mFontDescription.family;
890 void Controller::SetDefaultFontWeight( FontWeight weight )
892 if( NULL == mImpl->mFontDefaults )
894 mImpl->mFontDefaults = new FontDefaults();
897 mImpl->mFontDefaults->mFontDescription.weight = weight;
898 mImpl->mFontDefaults->weightDefined = true;
900 // Clear the font-specific data
903 mImpl->RequestRelayout();
906 bool Controller::IsDefaultFontWeightDefined() const
908 if( NULL != mImpl->mFontDefaults )
910 return mImpl->mFontDefaults->weightDefined;
916 FontWeight Controller::GetDefaultFontWeight() const
918 if( NULL != mImpl->mFontDefaults )
920 return mImpl->mFontDefaults->mFontDescription.weight;
923 return TextAbstraction::FontWeight::NORMAL;
926 void Controller::SetPlaceholderTextFontWeight( FontWeight weight )
928 if( NULL != mImpl->mEventData )
930 if( NULL == mImpl->mEventData->mPlaceholderFont )
932 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
935 mImpl->mEventData->mPlaceholderFont->mFontDescription.weight = weight;
936 mImpl->mEventData->mPlaceholderFont->weightDefined = true;
938 mImpl->RequestRelayout();
942 bool Controller::IsPlaceholderTextFontWeightDefined() const
944 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
946 return mImpl->mEventData->mPlaceholderFont->weightDefined;
951 FontWeight Controller::GetPlaceholderTextFontWeight() const
953 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
955 return mImpl->mEventData->mPlaceholderFont->mFontDescription.weight;
958 return TextAbstraction::FontWeight::NORMAL;
961 void Controller::SetDefaultFontWidth( FontWidth width )
963 if( NULL == mImpl->mFontDefaults )
965 mImpl->mFontDefaults = new FontDefaults();
968 mImpl->mFontDefaults->mFontDescription.width = width;
969 mImpl->mFontDefaults->widthDefined = true;
971 // Clear the font-specific data
974 mImpl->RequestRelayout();
977 bool Controller::IsDefaultFontWidthDefined() const
979 if( NULL != mImpl->mFontDefaults )
981 return mImpl->mFontDefaults->widthDefined;
987 FontWidth Controller::GetDefaultFontWidth() const
989 if( NULL != mImpl->mFontDefaults )
991 return mImpl->mFontDefaults->mFontDescription.width;
994 return TextAbstraction::FontWidth::NORMAL;
997 void Controller::SetPlaceholderTextFontWidth( FontWidth width )
999 if( NULL != mImpl->mEventData )
1001 if( NULL == mImpl->mEventData->mPlaceholderFont )
1003 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
1006 mImpl->mEventData->mPlaceholderFont->mFontDescription.width = width;
1007 mImpl->mEventData->mPlaceholderFont->widthDefined = true;
1009 mImpl->RequestRelayout();
1013 bool Controller::IsPlaceholderTextFontWidthDefined() const
1015 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1017 return mImpl->mEventData->mPlaceholderFont->widthDefined;
1022 FontWidth Controller::GetPlaceholderTextFontWidth() const
1024 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1026 return mImpl->mEventData->mPlaceholderFont->mFontDescription.width;
1029 return TextAbstraction::FontWidth::NORMAL;
1032 void Controller::SetDefaultFontSlant( FontSlant slant )
1034 if( NULL == mImpl->mFontDefaults )
1036 mImpl->mFontDefaults = new FontDefaults();
1039 mImpl->mFontDefaults->mFontDescription.slant = slant;
1040 mImpl->mFontDefaults->slantDefined = true;
1042 // Clear the font-specific data
1045 mImpl->RequestRelayout();
1048 bool Controller::IsDefaultFontSlantDefined() const
1050 if( NULL != mImpl->mFontDefaults )
1052 return mImpl->mFontDefaults->slantDefined;
1057 FontSlant Controller::GetDefaultFontSlant() const
1059 if( NULL != mImpl->mFontDefaults )
1061 return mImpl->mFontDefaults->mFontDescription.slant;
1064 return TextAbstraction::FontSlant::NORMAL;
1067 void Controller::SetPlaceholderTextFontSlant( FontSlant slant )
1069 if( NULL != mImpl->mEventData )
1071 if( NULL == mImpl->mEventData->mPlaceholderFont )
1073 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
1076 mImpl->mEventData->mPlaceholderFont->mFontDescription.slant = slant;
1077 mImpl->mEventData->mPlaceholderFont->slantDefined = true;
1079 mImpl->RequestRelayout();
1083 bool Controller::IsPlaceholderTextFontSlantDefined() const
1085 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1087 return mImpl->mEventData->mPlaceholderFont->slantDefined;
1092 FontSlant Controller::GetPlaceholderTextFontSlant() const
1094 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1096 return mImpl->mEventData->mPlaceholderFont->mFontDescription.slant;
1099 return TextAbstraction::FontSlant::NORMAL;
1102 void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
1104 if( NULL == mImpl->mFontDefaults )
1106 mImpl->mFontDefaults = new FontDefaults();
1113 mImpl->mFontDefaults->mDefaultPointSize = fontSize;
1114 mImpl->mFontDefaults->sizeDefined = true;
1119 // Point size = Pixel size * 72.f / DPI
1120 unsigned int horizontalDpi = 0u;
1121 unsigned int verticalDpi = 0u;
1122 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1123 fontClient.GetDpi( horizontalDpi, verticalDpi );
1125 mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
1126 mImpl->mFontDefaults->sizeDefined = true;
1131 // Clear the font-specific data
1134 mImpl->RequestRelayout();
1137 float Controller::GetDefaultFontSize( FontSizeType type ) const
1140 if( NULL != mImpl->mFontDefaults )
1146 value = mImpl->mFontDefaults->mDefaultPointSize;
1151 // Pixel size = Point size * DPI / 72.f
1152 unsigned int horizontalDpi = 0u;
1153 unsigned int verticalDpi = 0u;
1154 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1155 fontClient.GetDpi( horizontalDpi, verticalDpi );
1157 value = mImpl->mFontDefaults->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1167 void Controller::SetPlaceholderTextFontSize( float fontSize, FontSizeType type )
1169 if( NULL != mImpl->mEventData )
1171 if( NULL == mImpl->mEventData->mPlaceholderFont )
1173 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
1180 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = fontSize;
1181 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1182 mImpl->mEventData->mIsPlaceholderPixelSize = false; // Font size flag
1187 // Point size = Pixel size * 72.f / DPI
1188 unsigned int horizontalDpi = 0u;
1189 unsigned int verticalDpi = 0u;
1190 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1191 fontClient.GetDpi( horizontalDpi, verticalDpi );
1193 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
1194 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1195 mImpl->mEventData->mIsPlaceholderPixelSize = true; // Font size flag
1200 mImpl->RequestRelayout();
1204 float Controller::GetPlaceholderTextFontSize( FontSizeType type ) const
1207 if( NULL != mImpl->mEventData )
1213 if( NULL != mImpl->mEventData->mPlaceholderFont )
1215 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize;
1219 // If the placeholder text font size is not set, then return the default font size.
1220 value = GetDefaultFontSize( POINT_SIZE );
1226 if( NULL != mImpl->mEventData->mPlaceholderFont )
1228 // Pixel size = Point size * DPI / 72.f
1229 unsigned int horizontalDpi = 0u;
1230 unsigned int verticalDpi = 0u;
1231 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1232 fontClient.GetDpi( horizontalDpi, verticalDpi );
1234 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1238 // If the placeholder text font size is not set, then return the default font size.
1239 value = GetDefaultFontSize( PIXEL_SIZE );
1250 void Controller::SetDefaultColor( const Vector4& color )
1252 mImpl->mTextColor = color;
1254 if( !mImpl->IsShowingPlaceholderText() )
1256 mImpl->mModel->mVisualModel->SetTextColor( color );
1258 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
1260 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1262 mImpl->RequestRelayout();
1266 const Vector4& Controller::GetDefaultColor() const
1268 return mImpl->mTextColor;
1271 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
1273 if( NULL != mImpl->mEventData )
1275 mImpl->mEventData->mPlaceholderTextColor = textColor;
1278 if( mImpl->IsShowingPlaceholderText() )
1280 mImpl->mModel->mVisualModel->SetTextColor( textColor );
1281 mImpl->RequestRelayout();
1285 const Vector4& Controller::GetPlaceholderTextColor() const
1287 if( NULL != mImpl->mEventData )
1289 return mImpl->mEventData->mPlaceholderTextColor;
1292 return Color::BLACK;
1295 void Controller::SetShadowOffset( const Vector2& shadowOffset )
1297 mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
1299 mImpl->RequestRelayout();
1302 const Vector2& Controller::GetShadowOffset() const
1304 return mImpl->mModel->mVisualModel->GetShadowOffset();
1307 void Controller::SetShadowColor( const Vector4& shadowColor )
1309 mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
1311 mImpl->RequestRelayout();
1314 const Vector4& Controller::GetShadowColor() const
1316 return mImpl->mModel->mVisualModel->GetShadowColor();
1319 void Controller::SetShadowBlurRadius( const float& shadowBlurRadius )
1321 if ( fabsf( GetShadowBlurRadius() - shadowBlurRadius ) > Math::MACHINE_EPSILON_1 )
1323 mImpl->mModel->mVisualModel->SetShadowBlurRadius( shadowBlurRadius );
1325 mImpl->RequestRelayout();
1329 const float& Controller::GetShadowBlurRadius() const
1331 return mImpl->mModel->mVisualModel->GetShadowBlurRadius();
1334 void Controller::SetUnderlineColor( const Vector4& color )
1336 mImpl->mModel->mVisualModel->SetUnderlineColor( color );
1338 mImpl->RequestRelayout();
1341 const Vector4& Controller::GetUnderlineColor() const
1343 return mImpl->mModel->mVisualModel->GetUnderlineColor();
1346 void Controller::SetUnderlineEnabled( bool enabled )
1348 mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
1350 mImpl->RequestRelayout();
1353 bool Controller::IsUnderlineEnabled() const
1355 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
1358 void Controller::SetUnderlineHeight( float height )
1360 mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
1362 mImpl->RequestRelayout();
1365 float Controller::GetUnderlineHeight() const
1367 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
1370 void Controller::SetOutlineColor( const Vector4& color )
1372 mImpl->mModel->mVisualModel->SetOutlineColor( color );
1374 mImpl->RequestRelayout();
1377 const Vector4& Controller::GetOutlineColor() const
1379 return mImpl->mModel->mVisualModel->GetOutlineColor();
1382 void Controller::SetOutlineWidth( uint16_t width )
1384 mImpl->mModel->mVisualModel->SetOutlineWidth( width );
1386 mImpl->RequestRelayout();
1389 uint16_t Controller::GetOutlineWidth() const
1391 return mImpl->mModel->mVisualModel->GetOutlineWidth();
1394 void Controller::SetBackgroundColor( const Vector4& color )
1396 mImpl->mModel->mVisualModel->SetBackgroundColor( color );
1398 mImpl->RequestRelayout();
1401 const Vector4& Controller::GetBackgroundColor() const
1403 return mImpl->mModel->mVisualModel->GetBackgroundColor();
1406 void Controller::SetBackgroundEnabled( bool enabled )
1408 mImpl->mModel->mVisualModel->SetBackgroundEnabled( enabled );
1410 mImpl->RequestRelayout();
1413 bool Controller::IsBackgroundEnabled() const
1415 return mImpl->mModel->mVisualModel->IsBackgroundEnabled();
1418 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
1420 if( NULL == mImpl->mEmbossDefaults )
1422 mImpl->mEmbossDefaults = new EmbossDefaults();
1425 mImpl->mEmbossDefaults->properties = embossProperties;
1428 const std::string& Controller::GetDefaultEmbossProperties() const
1430 if( NULL != mImpl->mEmbossDefaults )
1432 return mImpl->mEmbossDefaults->properties;
1435 return EMPTY_STRING;
1438 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
1440 if( NULL == mImpl->mOutlineDefaults )
1442 mImpl->mOutlineDefaults = new OutlineDefaults();
1445 mImpl->mOutlineDefaults->properties = outlineProperties;
1448 const std::string& Controller::GetDefaultOutlineProperties() const
1450 if( NULL != mImpl->mOutlineDefaults )
1452 return mImpl->mOutlineDefaults->properties;
1455 return EMPTY_STRING;
1458 bool Controller::SetDefaultLineSpacing( float lineSpacing )
1460 if( std::fabs( lineSpacing - mImpl->mLayoutEngine.GetDefaultLineSpacing() ) > Math::MACHINE_EPSILON_1000 )
1462 mImpl->mLayoutEngine.SetDefaultLineSpacing(lineSpacing);
1463 mImpl->mRecalculateNaturalSize = true;
1469 float Controller::GetDefaultLineSpacing() const
1471 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
1474 void Controller::SetInputColor( const Vector4& color )
1476 if( NULL != mImpl->mEventData )
1478 mImpl->mEventData->mInputStyle.textColor = color;
1479 mImpl->mEventData->mInputStyle.isDefaultColor = false;
1481 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1483 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
1485 // Get start and end position of selection
1486 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
1487 const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
1489 // Add the color run.
1490 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1491 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
1493 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
1494 colorRun.color = color;
1495 colorRun.characterRun.characterIndex = startOfSelectedText;
1496 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1498 // Request to relayout.
1499 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1500 mImpl->RequestRelayout();
1502 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1503 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1504 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1509 const Vector4& Controller::GetInputColor() const
1511 if( NULL != mImpl->mEventData )
1513 return mImpl->mEventData->mInputStyle.textColor;
1516 // Return the default text's color if there is no EventData.
1517 return mImpl->mTextColor;
1521 void Controller::SetInputFontFamily( const std::string& fontFamily )
1523 if( NULL != mImpl->mEventData )
1525 mImpl->mEventData->mInputStyle.familyName = fontFamily;
1526 mImpl->mEventData->mInputStyle.isFamilyDefined = true;
1528 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1530 CharacterIndex startOfSelectedText = 0u;
1531 Length lengthOfSelectedText = 0u;
1532 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1533 mImpl->mModel->mLogicalModel,
1534 startOfSelectedText,
1535 lengthOfSelectedText );
1537 fontDescriptionRun.familyLength = fontFamily.size();
1538 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
1539 memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength );
1540 fontDescriptionRun.familyDefined = true;
1542 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
1544 // Request to relayout.
1545 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1550 UPDATE_LAYOUT_SIZE |
1553 mImpl->mRecalculateNaturalSize = true;
1554 mImpl->RequestRelayout();
1556 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1557 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1558 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1560 // As the font changes, recalculate the handle positions is needed.
1561 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1562 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1563 mImpl->mEventData->mUpdateHighlightBox = true;
1564 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1569 const std::string& Controller::GetInputFontFamily() const
1571 if( NULL != mImpl->mEventData )
1573 return mImpl->mEventData->mInputStyle.familyName;
1576 // Return the default font's family if there is no EventData.
1577 return GetDefaultFontFamily();
1580 void Controller::SetInputFontWeight( FontWeight weight )
1582 if( NULL != mImpl->mEventData )
1584 mImpl->mEventData->mInputStyle.weight = weight;
1585 mImpl->mEventData->mInputStyle.isWeightDefined = true;
1587 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1589 CharacterIndex startOfSelectedText = 0u;
1590 Length lengthOfSelectedText = 0u;
1591 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1592 mImpl->mModel->mLogicalModel,
1593 startOfSelectedText,
1594 lengthOfSelectedText );
1596 fontDescriptionRun.weight = weight;
1597 fontDescriptionRun.weightDefined = true;
1599 // Request to relayout.
1600 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1605 UPDATE_LAYOUT_SIZE |
1608 mImpl->mRecalculateNaturalSize = true;
1609 mImpl->RequestRelayout();
1611 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1612 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1613 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1615 // As the font might change, recalculate the handle positions is needed.
1616 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1617 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1618 mImpl->mEventData->mUpdateHighlightBox = true;
1619 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1624 bool Controller::IsInputFontWeightDefined() const
1626 bool defined = false;
1628 if( NULL != mImpl->mEventData )
1630 defined = mImpl->mEventData->mInputStyle.isWeightDefined;
1636 FontWeight Controller::GetInputFontWeight() const
1638 if( NULL != mImpl->mEventData )
1640 return mImpl->mEventData->mInputStyle.weight;
1643 return GetDefaultFontWeight();
1646 void Controller::SetInputFontWidth( FontWidth width )
1648 if( NULL != mImpl->mEventData )
1650 mImpl->mEventData->mInputStyle.width = width;
1651 mImpl->mEventData->mInputStyle.isWidthDefined = true;
1653 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1655 CharacterIndex startOfSelectedText = 0u;
1656 Length lengthOfSelectedText = 0u;
1657 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1658 mImpl->mModel->mLogicalModel,
1659 startOfSelectedText,
1660 lengthOfSelectedText );
1662 fontDescriptionRun.width = width;
1663 fontDescriptionRun.widthDefined = true;
1665 // Request to relayout.
1666 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1671 UPDATE_LAYOUT_SIZE |
1674 mImpl->mRecalculateNaturalSize = true;
1675 mImpl->RequestRelayout();
1677 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1678 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1679 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1681 // As the font might change, recalculate the handle positions is needed.
1682 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1683 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1684 mImpl->mEventData->mUpdateHighlightBox = true;
1685 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1690 bool Controller::IsInputFontWidthDefined() const
1692 bool defined = false;
1694 if( NULL != mImpl->mEventData )
1696 defined = mImpl->mEventData->mInputStyle.isWidthDefined;
1702 FontWidth Controller::GetInputFontWidth() const
1704 if( NULL != mImpl->mEventData )
1706 return mImpl->mEventData->mInputStyle.width;
1709 return GetDefaultFontWidth();
1712 void Controller::SetInputFontSlant( FontSlant slant )
1714 if( NULL != mImpl->mEventData )
1716 mImpl->mEventData->mInputStyle.slant = slant;
1717 mImpl->mEventData->mInputStyle.isSlantDefined = true;
1719 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1721 CharacterIndex startOfSelectedText = 0u;
1722 Length lengthOfSelectedText = 0u;
1723 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1724 mImpl->mModel->mLogicalModel,
1725 startOfSelectedText,
1726 lengthOfSelectedText );
1728 fontDescriptionRun.slant = slant;
1729 fontDescriptionRun.slantDefined = true;
1731 // Request to relayout.
1732 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1737 UPDATE_LAYOUT_SIZE |
1740 mImpl->mRecalculateNaturalSize = true;
1741 mImpl->RequestRelayout();
1743 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1744 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1745 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1747 // As the font might change, recalculate the handle positions is needed.
1748 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1749 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1750 mImpl->mEventData->mUpdateHighlightBox = true;
1751 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1756 bool Controller::IsInputFontSlantDefined() const
1758 bool defined = false;
1760 if( NULL != mImpl->mEventData )
1762 defined = mImpl->mEventData->mInputStyle.isSlantDefined;
1768 FontSlant Controller::GetInputFontSlant() const
1770 if( NULL != mImpl->mEventData )
1772 return mImpl->mEventData->mInputStyle.slant;
1775 return GetDefaultFontSlant();
1778 void Controller::SetInputFontPointSize( float size )
1780 if( NULL != mImpl->mEventData )
1782 mImpl->mEventData->mInputStyle.size = size;
1783 mImpl->mEventData->mInputStyle.isSizeDefined = true;
1785 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1787 CharacterIndex startOfSelectedText = 0u;
1788 Length lengthOfSelectedText = 0u;
1789 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1790 mImpl->mModel->mLogicalModel,
1791 startOfSelectedText,
1792 lengthOfSelectedText );
1794 fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
1795 fontDescriptionRun.sizeDefined = true;
1797 // Request to relayout.
1798 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1803 UPDATE_LAYOUT_SIZE |
1806 mImpl->mRecalculateNaturalSize = true;
1807 mImpl->RequestRelayout();
1809 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1810 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1811 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1813 // As the font might change, recalculate the handle positions is needed.
1814 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1815 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1816 mImpl->mEventData->mUpdateHighlightBox = true;
1817 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1822 float Controller::GetInputFontPointSize() const
1824 if( NULL != mImpl->mEventData )
1826 return mImpl->mEventData->mInputStyle.size;
1829 // Return the default font's point size if there is no EventData.
1830 return GetDefaultFontSize( Text::Controller::POINT_SIZE );
1833 void Controller::SetInputLineSpacing( float lineSpacing )
1835 if( NULL != mImpl->mEventData )
1837 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1838 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1842 float Controller::GetInputLineSpacing() const
1844 if( NULL != mImpl->mEventData )
1846 return mImpl->mEventData->mInputStyle.lineSpacing;
1852 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1854 if( NULL != mImpl->mEventData )
1856 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1860 const std::string& Controller::GetInputShadowProperties() const
1862 if( NULL != mImpl->mEventData )
1864 return mImpl->mEventData->mInputStyle.shadowProperties;
1867 return EMPTY_STRING;
1870 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1872 if( NULL != mImpl->mEventData )
1874 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1878 const std::string& Controller::GetInputUnderlineProperties() const
1880 if( NULL != mImpl->mEventData )
1882 return mImpl->mEventData->mInputStyle.underlineProperties;
1885 return EMPTY_STRING;
1888 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
1890 if( NULL != mImpl->mEventData )
1892 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1896 const std::string& Controller::GetInputEmbossProperties() const
1898 if( NULL != mImpl->mEventData )
1900 return mImpl->mEventData->mInputStyle.embossProperties;
1903 return GetDefaultEmbossProperties();
1906 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
1908 if( NULL != mImpl->mEventData )
1910 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1914 const std::string& Controller::GetInputOutlineProperties() const
1916 if( NULL != mImpl->mEventData )
1918 return mImpl->mEventData->mInputStyle.outlineProperties;
1921 return GetDefaultOutlineProperties();
1924 void Controller::SetInputModePassword( bool passwordInput )
1926 if( NULL != mImpl->mEventData )
1928 mImpl->mEventData->mPasswordInput = passwordInput;
1932 bool Controller::IsInputModePassword()
1934 if( NULL != mImpl->mEventData )
1936 return mImpl->mEventData->mPasswordInput;
1941 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
1943 if( NULL != mImpl->mEventData )
1945 mImpl->mEventData->mDoubleTapAction = action;
1949 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1951 NoTextTap::Action action = NoTextTap::NO_ACTION;
1953 if( NULL != mImpl->mEventData )
1955 action = mImpl->mEventData->mDoubleTapAction;
1961 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
1963 if( NULL != mImpl->mEventData )
1965 mImpl->mEventData->mLongPressAction = action;
1969 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1971 NoTextTap::Action action = NoTextTap::NO_ACTION;
1973 if( NULL != mImpl->mEventData )
1975 action = mImpl->mEventData->mLongPressAction;
1981 bool Controller::IsUnderlineSetByString()
1983 return mImpl->mUnderlineSetByString;
1986 void Controller::UnderlineSetByString( bool setByString )
1988 mImpl->mUnderlineSetByString = setByString;
1991 bool Controller::IsShadowSetByString()
1993 return mImpl->mShadowSetByString;
1996 void Controller::ShadowSetByString( bool setByString )
1998 mImpl->mShadowSetByString = setByString;
2001 bool Controller::IsOutlineSetByString()
2003 return mImpl->mOutlineSetByString;
2006 void Controller::OutlineSetByString( bool setByString )
2008 mImpl->mOutlineSetByString = setByString;
2011 bool Controller::IsFontStyleSetByString()
2013 return mImpl->mFontStyleSetByString;
2016 void Controller::FontStyleSetByString( bool setByString )
2018 mImpl->mFontStyleSetByString = setByString;
2021 // public : Queries & retrieves.
2023 Layout::Engine& Controller::GetLayoutEngine()
2025 return mImpl->mLayoutEngine;
2028 View& Controller::GetView()
2030 return mImpl->mView;
2033 Vector3 Controller::GetNaturalSize()
2035 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
2036 Vector3 naturalSize;
2038 // Make sure the model is up-to-date before layouting
2039 ProcessModifyEvents();
2041 if( mImpl->mRecalculateNaturalSize )
2043 // Operations that can be done only once until the text changes.
2044 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2051 GET_GLYPH_METRICS );
2053 // Set the update info to relayout the whole text.
2054 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2055 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2057 // Make sure the model is up-to-date before layouting
2058 mImpl->UpdateModel( onlyOnceOperations );
2060 // Layout the text for the new width.
2061 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT | REORDER );
2063 // Store the actual control's size to restore later.
2064 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
2066 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
2067 static_cast<OperationsMask>( onlyOnceOperations |
2069 naturalSize.GetVectorXY() );
2071 // Do not do again the only once operations.
2072 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2074 // Do the size related operations again.
2075 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
2078 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
2080 // Stores the natural size to avoid recalculate it again
2081 // unless the text/style changes.
2082 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
2084 mImpl->mRecalculateNaturalSize = false;
2086 // Clear the update info. This info will be set the next time the text is updated.
2087 mImpl->mTextUpdateInfo.Clear();
2088 mImpl->mTextUpdateInfo.mClearAll = true;
2090 // Restore the actual control's size.
2091 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
2093 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
2097 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
2099 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
2102 naturalSize.x = ConvertToEven( naturalSize.x );
2103 naturalSize.y = ConvertToEven( naturalSize.y );
2108 bool Controller::CheckForTextFit( float pointSize, Size& layoutSize )
2111 mImpl->mFontDefaults->mFitPointSize = pointSize;
2112 mImpl->mFontDefaults->sizeDefined = true;
2115 // Operations that can be done only once until the text changes.
2116 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2123 GET_GLYPH_METRICS );
2125 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2126 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2128 // Make sure the model is up-to-date before layouting
2129 mImpl->UpdateModel( onlyOnceOperations );
2131 DoRelayout( Size( layoutSize.width, MAX_FLOAT ),
2132 static_cast<OperationsMask>( onlyOnceOperations | LAYOUT),
2135 // Clear the update info. This info will be set the next time the text is updated.
2136 mImpl->mTextUpdateInfo.Clear();
2137 mImpl->mTextUpdateInfo.mClearAll = true;
2139 if( textSize.width > layoutSize.width || textSize.height > layoutSize.height )
2146 void Controller::FitPointSizeforLayout( Size layoutSize )
2148 const OperationsMask operations = mImpl->mOperationsPending;
2149 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
2151 bool actualellipsis = mImpl->mModel->mElideEnabled;
2152 float minPointSize = mImpl->mTextFitMinSize;
2153 float maxPointSize = mImpl->mTextFitMaxSize;
2154 float pointInterval = mImpl->mTextFitStepSize;
2156 mImpl->mModel->mElideEnabled = false;
2157 Vector<float> pointSizeArray;
2160 if( pointInterval < 1.f )
2162 mImpl->mTextFitStepSize = pointInterval = 1.0f;
2165 pointSizeArray.Reserve( static_cast< unsigned int >( ceil( ( maxPointSize - minPointSize ) / pointInterval ) ) );
2167 for( float i = minPointSize; i < maxPointSize; i += pointInterval )
2169 pointSizeArray.PushBack( i );
2172 pointSizeArray.PushBack( maxPointSize );
2174 int bestSizeIndex = 0;
2175 int min = bestSizeIndex + 1;
2176 int max = pointSizeArray.Size() - 1;
2179 int destI = ( min + max ) / 2;
2181 if( CheckForTextFit( pointSizeArray[destI], layoutSize ) )
2183 bestSizeIndex = min;
2189 bestSizeIndex = max;
2193 mImpl->mModel->mElideEnabled = actualellipsis;
2194 mImpl->mFontDefaults->mFitPointSize = pointSizeArray[bestSizeIndex];
2195 mImpl->mFontDefaults->sizeDefined = true;
2200 float Controller::GetHeightForWidth( float width )
2202 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
2203 // Make sure the model is up-to-date before layouting
2204 ProcessModifyEvents();
2207 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ||
2208 mImpl->mTextUpdateInfo.mFullRelayoutNeeded ||
2209 mImpl->mTextUpdateInfo.mClearAll )
2211 // Operations that can be done only once until the text changes.
2212 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2219 GET_GLYPH_METRICS );
2221 // Set the update info to relayout the whole text.
2222 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2223 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2225 // Make sure the model is up-to-date before layouting
2226 mImpl->UpdateModel( onlyOnceOperations );
2229 // Layout the text for the new width.
2230 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
2232 // Store the actual control's width.
2233 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
2235 DoRelayout( Size( width, MAX_FLOAT ),
2236 static_cast<OperationsMask>( onlyOnceOperations |
2240 // Do not do again the only once operations.
2241 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2243 // Do the size related operations again.
2244 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
2248 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
2250 // Clear the update info. This info will be set the next time the text is updated.
2251 mImpl->mTextUpdateInfo.Clear();
2252 mImpl->mTextUpdateInfo.mClearAll = true;
2254 // Restore the actual control's width.
2255 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
2257 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
2261 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
2262 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
2265 return layoutSize.height;
2268 int Controller::GetLineCount( float width )
2270 GetHeightForWidth( width );
2271 int numberofLines = mImpl->mModel->GetNumberOfLines();
2272 return numberofLines;
2275 const ModelInterface* const Controller::GetTextModel() const
2277 return mImpl->mModel.Get();
2280 float Controller::GetScrollAmountByUserInput()
2282 float scrollAmount = 0.0f;
2284 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
2286 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
2287 mImpl->mEventData->mCheckScrollAmount = false;
2289 return scrollAmount;
2292 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
2294 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
2297 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
2298 layoutHeight = layout.height;
2299 scrollPosition = mImpl->mModel->mScrollPosition.y;
2300 isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
2304 void Controller::SetHiddenInputOption(const Property::Map& options )
2306 if( NULL == mImpl->mHiddenInput )
2308 mImpl->mHiddenInput = new HiddenText( this );
2310 mImpl->mHiddenInput->SetProperties(options);
2313 void Controller::GetHiddenInputOption(Property::Map& options )
2315 if( NULL != mImpl->mHiddenInput )
2317 mImpl->mHiddenInput->GetProperties(options);
2321 void Controller::SetPlaceholderProperty( const Property::Map& map )
2323 const Property::Map::SizeType count = map.Count();
2325 for( Property::Map::SizeType position = 0; position < count; ++position )
2327 KeyValuePair keyValue = map.GetKeyValue( position );
2328 Property::Key& key = keyValue.first;
2329 Property::Value& value = keyValue.second;
2331 if( key == Toolkit::Text::PlaceHolder::Property::TEXT || key == PLACEHOLDER_TEXT )
2333 std::string text = "";
2335 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
2337 else if( key == Toolkit::Text::PlaceHolder::Property::TEXT_FOCUSED || key == PLACEHOLDER_TEXT_FOCUSED )
2339 std::string text = "";
2341 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
2343 else if( key == Toolkit::Text::PlaceHolder::Property::COLOR || key == PLACEHOLDER_COLOR )
2346 value.Get( textColor );
2347 if( GetPlaceholderTextColor() != textColor )
2349 SetPlaceholderTextColor( textColor );
2352 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_FAMILY || key == PLACEHOLDER_FONT_FAMILY )
2354 std::string fontFamily = "";
2355 value.Get( fontFamily );
2356 SetPlaceholderFontFamily( fontFamily );
2358 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_STYLE || key == PLACEHOLDER_FONT_STYLE )
2360 SetFontStyleProperty( this, value, Text::FontStyle::PLACEHOLDER );
2362 else if( key == Toolkit::Text::PlaceHolder::Property::POINT_SIZE || key == PLACEHOLDER_POINT_SIZE )
2365 value.Get( pointSize );
2366 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
2368 SetPlaceholderTextFontSize( pointSize, Text::Controller::POINT_SIZE );
2371 else if( key == Toolkit::Text::PlaceHolder::Property::PIXEL_SIZE || key == PLACEHOLDER_PIXEL_SIZE )
2374 value.Get( pixelSize );
2375 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
2377 SetPlaceholderTextFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
2380 else if( key == Toolkit::Text::PlaceHolder::Property::ELLIPSIS || key == PLACEHOLDER_ELLIPSIS )
2383 value.Get( ellipsis );
2384 SetPlaceholderTextElideEnabled( ellipsis );
2389 void Controller::GetPlaceholderProperty( Property::Map& map )
2391 if( NULL != mImpl->mEventData )
2393 if( !mImpl->mEventData->mPlaceholderTextActive.empty() )
2395 map[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = mImpl->mEventData->mPlaceholderTextActive;
2397 if( !mImpl->mEventData->mPlaceholderTextInactive.empty() )
2399 map[ Text::PlaceHolder::Property::TEXT ] = mImpl->mEventData->mPlaceholderTextInactive;
2402 map[ Text::PlaceHolder::Property::COLOR ] = mImpl->mEventData->mPlaceholderTextColor;
2403 map[ Text::PlaceHolder::Property::FONT_FAMILY ] = GetPlaceholderFontFamily();
2405 Property::Value fontStyleMapGet;
2406 GetFontStyleProperty( this, fontStyleMapGet, Text::FontStyle::PLACEHOLDER );
2407 map[ Text::PlaceHolder::Property::FONT_STYLE ] = fontStyleMapGet;
2409 // Choose font size : POINT_SIZE or PIXEL_SIZE
2410 if( !mImpl->mEventData->mIsPlaceholderPixelSize )
2412 map[ Text::PlaceHolder::Property::POINT_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE );
2416 map[ Text::PlaceHolder::Property::PIXEL_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE );
2419 if( mImpl->mEventData->mPlaceholderEllipsisFlag )
2421 map[ Text::PlaceHolder::Property::ELLIPSIS ] = IsPlaceholderTextElideEnabled();
2426 Toolkit::DevelText::TextDirection::Type Controller::GetTextDirection()
2428 // Make sure the model is up-to-date before layouting
2429 ProcessModifyEvents();
2431 if ( mImpl->mUpdateTextDirection )
2433 // Operations that can be done only once until the text changes.
2434 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2441 GET_GLYPH_METRICS );
2443 // Set the update info to relayout the whole text.
2444 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2445 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2447 // Make sure the model is up-to-date before layouting
2448 mImpl->UpdateModel( onlyOnceOperations );
2450 Vector3 naturalSize;
2451 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
2452 static_cast<OperationsMask>( onlyOnceOperations |
2453 LAYOUT | REORDER | UPDATE_DIRECTION ),
2454 naturalSize.GetVectorXY() );
2456 // Do not do again the only once operations.
2457 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2459 // Clear the update info. This info will be set the next time the text is updated.
2460 mImpl->mTextUpdateInfo.Clear();
2462 mImpl->mUpdateTextDirection = false;
2465 return mImpl->mIsTextDirectionRTL ? Toolkit::DevelText::TextDirection::RIGHT_TO_LEFT : Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT;
2468 Toolkit::DevelText::VerticalLineAlignment::Type Controller::GetVerticalLineAlignment() const
2470 return mImpl->mModel->GetVerticalLineAlignment();
2473 void Controller::SetVerticalLineAlignment( Toolkit::DevelText::VerticalLineAlignment::Type alignment )
2475 mImpl->mModel->mVerticalLineAlignment = alignment;
2478 // public : Relayout.
2480 Controller::UpdateTextType Controller::Relayout( const Size& size, Dali::LayoutDirection::Type layoutDirection )
2482 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
2484 UpdateTextType updateTextType = NONE_UPDATED;
2486 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
2488 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
2490 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
2491 updateTextType = MODEL_UPDATED;
2494 // Clear the update info. This info will be set the next time the text is updated.
2495 mImpl->mTextUpdateInfo.Clear();
2497 // Not worth to relayout if width or height is equal to zero.
2498 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
2500 return updateTextType;
2503 // Whether a new size has been set.
2504 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
2508 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
2510 if( ( 0 == mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd ) &&
2511 ( 0 == mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) &&
2512 ( ( mImpl->mModel->mVisualModel->mControlSize.width < Math::MACHINE_EPSILON_1000 ) || ( mImpl->mModel->mVisualModel->mControlSize.height < Math::MACHINE_EPSILON_1000 ) ) )
2514 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
2517 // Layout operations that need to be done if the size changes.
2518 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2521 UPDATE_LAYOUT_SIZE |
2523 // Set the update info to relayout the whole text.
2524 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2525 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2527 // Store the size used to layout the text.
2528 mImpl->mModel->mVisualModel->mControlSize = size;
2531 // Whether there are modify events.
2532 if( 0u != mImpl->mModifyEvents.Count() )
2534 // Style operations that need to be done if the text is modified.
2535 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2539 // Set the update info to elide the text.
2540 if( mImpl->mModel->mElideEnabled ||
2541 ( ( NULL != mImpl->mEventData ) && mImpl->mEventData->mIsPlaceholderElideEnabled ) )
2543 // Update Text layout for applying elided
2544 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2547 UPDATE_LAYOUT_SIZE |
2549 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2550 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2553 if( mImpl->mModel->mMatchSystemLanguageDirection && mImpl->mLayoutDirection != layoutDirection )
2555 // Clear the update info. This info will be set the next time the text is updated.
2556 mImpl->mTextUpdateInfo.mClearAll = true;
2557 // Apply modifications to the model
2558 // Shape the text again is needed because characters like '()[]{}' have to be mirrored and the glyphs generated again.
2559 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2566 mImpl->mLayoutDirection = layoutDirection;
2569 // Make sure the model is up-to-date before layouting.
2570 ProcessModifyEvents();
2571 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
2575 updated = DoRelayout( size,
2576 mImpl->mOperationsPending,
2577 layoutSize ) || updated;
2582 updateTextType = MODEL_UPDATED;
2585 // Do not re-do any operation until something changes.
2586 mImpl->mOperationsPending = NO_OPERATION;
2587 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
2589 // Whether the text control is editable
2590 const bool isEditable = NULL != mImpl->mEventData;
2592 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
2594 if( newSize && isEditable )
2596 offset = mImpl->mModel->mScrollPosition;
2599 if( !isEditable || !IsMultiLineEnabled() )
2601 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
2602 CalculateVerticalOffset( size );
2609 // If there is a new size, the scroll position needs to be clamped.
2610 mImpl->ClampHorizontalScroll( layoutSize );
2612 // Update the decorator's positions is needed if there is a new size.
2613 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
2616 // Move the cursor, grab handle etc.
2617 if( mImpl->ProcessInputEvents() )
2619 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
2623 // Clear the update info. This info will be set the next time the text is updated.
2624 mImpl->mTextUpdateInfo.Clear();
2625 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
2627 return updateTextType;
2630 void Controller::RequestRelayout()
2632 mImpl->RequestRelayout();
2635 // public : Input style change signals.
2637 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
2639 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
2642 void Controller::ProcessInputStyleChangedSignals()
2644 if( NULL == mImpl->mEventData )
2650 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
2651 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
2655 const InputStyle::Mask mask = *it;
2657 if( NULL != mImpl->mEditableControlInterface )
2659 // Emit the input style changed signal.
2660 mImpl->mEditableControlInterface->InputStyleChanged( mask );
2664 mImpl->mEventData->mInputStyleChangedQueue.Clear();
2667 // public : Text-input Event Queuing.
2669 void Controller::KeyboardFocusGainEvent()
2671 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
2673 if( NULL != mImpl->mEventData )
2675 if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
2676 ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
2678 mImpl->ChangeState( EventData::EDITING );
2679 mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
2680 mImpl->mEventData->mUpdateInputStyle = true;
2681 mImpl->mEventData->mScrollAfterUpdatePosition = true;
2683 mImpl->NotifyInputMethodContextMultiLineStatus();
2684 if( mImpl->IsShowingPlaceholderText() )
2686 // Show alternative placeholder-text when editing
2687 ShowPlaceholderText();
2690 mImpl->RequestRelayout();
2694 void Controller::KeyboardFocusLostEvent()
2696 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
2698 if( NULL != mImpl->mEventData )
2700 if( EventData::INTERRUPTED != mImpl->mEventData->mState )
2702 mImpl->ChangeState( EventData::INACTIVE );
2704 if( !mImpl->IsShowingRealText() )
2706 // Revert to regular placeholder-text when not editing
2707 ShowPlaceholderText();
2711 mImpl->RequestRelayout();
2714 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
2716 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
2718 bool textChanged = false;
2719 bool relayoutNeeded = false;
2721 if( ( NULL != mImpl->mEventData ) &&
2722 ( keyEvent.state == KeyEvent::Down ) )
2724 int keyCode = keyEvent.keyCode;
2725 const std::string& keyString = keyEvent.keyPressed;
2726 const std::string keyName = keyEvent.keyPressedName;
2728 const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
2730 // Pre-process to separate modifying events from non-modifying input events.
2733 // In some platforms arrive key events with no key code.
2737 else if( Dali::DALI_KEY_ESCAPE == keyCode || Dali::DALI_KEY_BACK == keyCode || Dali::DALI_KEY_SEARCH == keyCode )
2742 else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) ||
2743 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
2744 ( Dali::DALI_KEY_CURSOR_UP == keyCode ) ||
2745 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) )
2747 // If don't have any text, do nothing.
2748 if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
2753 uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition;
2754 uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2755 uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition );
2756 uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines();
2758 // Logic to determine whether this text control will lose focus or not.
2759 if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2760 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2761 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) ||
2762 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) ||
2763 ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) ||
2764 ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) )
2766 // Release the active highlight.
2767 if( mImpl->mEventData->mState == EventData::SELECTING )
2769 mImpl->ChangeState( EventData::EDITING );
2771 // Update selection position.
2772 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2773 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2774 mImpl->mEventData->mUpdateCursorPosition = true;
2775 mImpl->RequestRelayout();
2780 mImpl->mEventData->mCheckScrollAmount = true;
2781 Event event( Event::CURSOR_KEY_EVENT );
2782 event.p1.mInt = keyCode;
2783 event.p2.mBool = keyEvent.IsShiftModifier();
2784 mImpl->mEventData->mEventQueue.push_back( event );
2786 // Will request for relayout.
2787 relayoutNeeded = true;
2789 else if ( Dali::DevelKey::DALI_KEY_CONTROL_LEFT == keyCode || Dali::DevelKey::DALI_KEY_CONTROL_RIGHT == keyCode )
2791 // Left or Right Control key event is received before Ctrl-C/V/X key event is received
2792 // If not handle it here, any selected text will be deleted
2797 else if ( keyEvent.IsCtrlModifier() )
2799 bool consumed = false;
2800 if (keyName == KEY_C_NAME)
2802 // Ctrl-C to copy the selected text
2803 TextPopupButtonTouched( Toolkit::TextSelectionPopup::COPY );
2806 else if (keyName == KEY_V_NAME)
2808 // Ctrl-V to paste the copied text
2809 TextPopupButtonTouched( Toolkit::TextSelectionPopup::PASTE );
2812 else if (keyName == KEY_X_NAME)
2814 // Ctrl-X to cut the selected text
2815 TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
2820 else if( ( Dali::DALI_KEY_BACKSPACE == keyCode ) ||
2821 ( Dali::DevelKey::DALI_KEY_DELETE == keyCode ) )
2823 textChanged = DeleteEvent( keyCode );
2825 // Will request for relayout.
2826 relayoutNeeded = true;
2828 else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
2829 IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
2830 IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
2832 // Power key/Menu/Home key behaviour does not allow edit mode to resume.
2833 mImpl->ChangeState( EventData::INACTIVE );
2835 // Will request for relayout.
2836 relayoutNeeded = true;
2838 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2840 else if( ( Dali::DALI_KEY_SHIFT_LEFT == keyCode ) || ( Dali::DALI_KEY_SHIFT_RIGHT == keyCode ) )
2842 // 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
2843 // and a character is typed after the type of a upper case latin character.
2848 else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
2850 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2856 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
2858 if( !keyString.empty() )
2860 // InputMethodContext is no longer handling key-events
2861 mImpl->ClearPreEditFlag();
2863 InsertText( keyString, COMMIT );
2867 // Will request for relayout.
2868 relayoutNeeded = true;
2873 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
2874 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
2876 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
2877 ( Dali::DALI_KEY_SHIFT_RIGHT != keyCode ) &&
2878 ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
2879 ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
2881 // Should not change the state if the key is the shift send by the InputMethodContext.
2882 // Otherwise, when the state is SELECTING the text controller can't send the right
2883 // surrounding info to the InputMethodContext.
2884 mImpl->ChangeState( EventData::EDITING );
2886 // Will request for relayout.
2887 relayoutNeeded = true;
2890 if( relayoutNeeded )
2892 mImpl->RequestRelayout();
2897 ( NULL != mImpl->mEditableControlInterface ) )
2899 // Do this last since it provides callbacks into application code
2900 mImpl->mEditableControlInterface->TextChanged();
2906 void Controller::TapEvent( unsigned int tapCount, float x, float y )
2908 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
2910 if( NULL != mImpl->mEventData )
2912 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
2913 EventData::State state( mImpl->mEventData->mState );
2914 bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
2916 if( mImpl->IsClipboardVisible() )
2918 if( EventData::INACTIVE == state || EventData::EDITING == state)
2920 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2922 relayoutNeeded = true;
2924 else if( 1u == tapCount )
2926 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
2928 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
2931 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
2933 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2934 relayoutNeeded = true;
2938 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
2940 // Hide placeholder text
2944 if( EventData::INACTIVE == state )
2946 mImpl->ChangeState( EventData::EDITING );
2948 else if( !mImpl->IsClipboardEmpty() )
2950 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
2952 relayoutNeeded = true;
2955 else if( 2u == tapCount )
2957 if( mImpl->mEventData->mSelectionEnabled &&
2958 mImpl->IsShowingRealText() )
2960 relayoutNeeded = true;
2961 mImpl->mEventData->mIsLeftHandleSelected = true;
2962 mImpl->mEventData->mIsRightHandleSelected = true;
2966 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
2967 if( relayoutNeeded )
2969 Event event( Event::TAP_EVENT );
2970 event.p1.mUint = tapCount;
2971 event.p2.mFloat = x;
2972 event.p3.mFloat = y;
2973 mImpl->mEventData->mEventQueue.push_back( event );
2975 mImpl->RequestRelayout();
2979 // Reset keyboard as tap event has occurred.
2980 mImpl->ResetInputMethodContext();
2983 void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
2985 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
2987 if( NULL != mImpl->mEventData )
2989 Event event( Event::PAN_EVENT );
2990 event.p1.mInt = state;
2991 event.p2.mFloat = displacement.x;
2992 event.p3.mFloat = displacement.y;
2993 mImpl->mEventData->mEventQueue.push_back( event );
2995 mImpl->RequestRelayout();
2999 void Controller::LongPressEvent( Gesture::State state, float x, float y )
3001 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
3003 if( ( state == Gesture::Started ) &&
3004 ( NULL != mImpl->mEventData ) )
3006 // The 1st long-press on inactive text-field is treated as tap
3007 if( EventData::INACTIVE == mImpl->mEventData->mState )
3009 mImpl->ChangeState( EventData::EDITING );
3011 Event event( Event::TAP_EVENT );
3013 event.p2.mFloat = x;
3014 event.p3.mFloat = y;
3015 mImpl->mEventData->mEventQueue.push_back( event );
3017 mImpl->RequestRelayout();
3019 else if( !mImpl->IsShowingRealText() )
3021 Event event( Event::LONG_PRESS_EVENT );
3022 event.p1.mInt = state;
3023 event.p2.mFloat = x;
3024 event.p3.mFloat = y;
3025 mImpl->mEventData->mEventQueue.push_back( event );
3026 mImpl->RequestRelayout();
3028 else if( !mImpl->IsClipboardVisible() )
3030 // Reset the InputMethodContext to commit the pre-edit before selecting the text.
3031 mImpl->ResetInputMethodContext();
3033 Event event( Event::LONG_PRESS_EVENT );
3034 event.p1.mInt = state;
3035 event.p2.mFloat = x;
3036 event.p3.mFloat = y;
3037 mImpl->mEventData->mEventQueue.push_back( event );
3038 mImpl->RequestRelayout();
3040 mImpl->mEventData->mIsLeftHandleSelected = true;
3041 mImpl->mEventData->mIsRightHandleSelected = true;
3046 void Controller::SelectEvent( float x, float y, bool selectAll )
3048 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
3050 if( NULL != mImpl->mEventData )
3054 Event event( Event::SELECT_ALL );
3055 mImpl->mEventData->mEventQueue.push_back( event );
3059 Event event( Event::SELECT );
3060 event.p2.mFloat = x;
3061 event.p3.mFloat = y;
3062 mImpl->mEventData->mEventQueue.push_back( event );
3065 mImpl->mEventData->mCheckScrollAmount = true;
3066 mImpl->mEventData->mIsLeftHandleSelected = true;
3067 mImpl->mEventData->mIsRightHandleSelected = true;
3068 mImpl->RequestRelayout();
3072 InputMethodContext::CallbackData Controller::OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
3074 // Whether the text needs to be relaid-out.
3075 bool requestRelayout = false;
3077 // Whether to retrieve the text and cursor position to be sent to the InputMethodContext.
3078 bool retrieveText = false;
3079 bool retrieveCursor = false;
3081 switch( inputMethodContextEvent.eventName )
3083 case InputMethodContext::COMMIT:
3085 InsertText( inputMethodContextEvent.predictiveString, Text::Controller::COMMIT );
3086 requestRelayout = true;
3087 retrieveCursor = true;
3090 case InputMethodContext::PRE_EDIT:
3092 InsertText( inputMethodContextEvent.predictiveString, Text::Controller::PRE_EDIT );
3093 requestRelayout = true;
3094 retrieveCursor = true;
3097 case InputMethodContext::DELETE_SURROUNDING:
3099 const bool textDeleted = RemoveText( inputMethodContextEvent.cursorOffset,
3100 inputMethodContextEvent.numberOfChars,
3101 DONT_UPDATE_INPUT_STYLE );
3105 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3106 !mImpl->IsPlaceholderAvailable() )
3108 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3112 ShowPlaceholderText();
3114 mImpl->mEventData->mUpdateCursorPosition = true;
3115 mImpl->mEventData->mScrollAfterDelete = true;
3117 requestRelayout = true;
3121 case InputMethodContext::GET_SURROUNDING:
3123 retrieveText = true;
3124 retrieveCursor = true;
3127 case InputMethodContext::PRIVATE_COMMAND:
3129 // PRIVATECOMMAND event is just for getting the private command message
3130 retrieveText = true;
3131 retrieveCursor = true;
3134 case InputMethodContext::VOID:
3141 if( requestRelayout )
3143 mImpl->mOperationsPending = ALL_OPERATIONS;
3144 mImpl->RequestRelayout();
3148 CharacterIndex cursorPosition = 0u;
3149 Length numberOfWhiteSpaces = 0u;
3151 if( retrieveCursor )
3153 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
3155 cursorPosition = mImpl->GetLogicalCursorPosition();
3157 if( cursorPosition < numberOfWhiteSpaces )
3159 cursorPosition = 0u;
3163 cursorPosition -= numberOfWhiteSpaces;
3169 if( !mImpl->IsShowingPlaceholderText() )
3171 // Retrieves the normal text string.
3172 mImpl->GetText( numberOfWhiteSpaces, text );
3176 // When the current text is Placeholder Text, the surrounding text should be empty string.
3177 // It means DALi should send empty string ("") to IME.
3182 InputMethodContext::CallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
3184 if( requestRelayout &&
3185 ( NULL != mImpl->mEditableControlInterface ) )
3187 // Do this last since it provides callbacks into application code
3188 mImpl->mEditableControlInterface->TextChanged();
3191 return callbackData;
3194 void Controller::PasteClipboardItemEvent()
3196 // Retrieve the clipboard contents first
3197 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
3198 std::string stringToPaste( notifier.GetContent() );
3200 // Commit the current pre-edit text; the contents of the clipboard should be appended
3201 mImpl->ResetInputMethodContext();
3203 // Temporary disable hiding clipboard
3204 mImpl->SetClipboardHideEnable( false );
3207 PasteText( stringToPaste );
3209 mImpl->SetClipboardHideEnable( true );
3212 // protected : Inherit from Text::Decorator::ControllerInterface.
3214 void Controller::GetTargetSize( Vector2& targetSize )
3216 targetSize = mImpl->mModel->mVisualModel->mControlSize;
3219 void Controller::AddDecoration( Actor& actor, bool needsClipping )
3221 if( NULL != mImpl->mEditableControlInterface )
3223 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
3227 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
3229 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
3231 if( NULL != mImpl->mEventData )
3233 switch( handleType )
3237 Event event( Event::GRAB_HANDLE_EVENT );
3238 event.p1.mUint = state;
3239 event.p2.mFloat = x;
3240 event.p3.mFloat = y;
3242 mImpl->mEventData->mEventQueue.push_back( event );
3245 case LEFT_SELECTION_HANDLE:
3247 Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
3248 event.p1.mUint = state;
3249 event.p2.mFloat = x;
3250 event.p3.mFloat = y;
3252 mImpl->mEventData->mEventQueue.push_back( event );
3255 case RIGHT_SELECTION_HANDLE:
3257 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
3258 event.p1.mUint = state;
3259 event.p2.mFloat = x;
3260 event.p3.mFloat = y;
3262 mImpl->mEventData->mEventQueue.push_back( event );
3265 case LEFT_SELECTION_HANDLE_MARKER:
3266 case RIGHT_SELECTION_HANDLE_MARKER:
3268 // Markers do not move the handles.
3271 case HANDLE_TYPE_COUNT:
3273 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
3277 mImpl->RequestRelayout();
3281 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
3283 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
3285 if( NULL == mImpl->mEventData )
3292 case Toolkit::TextSelectionPopup::CUT:
3294 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
3295 mImpl->mOperationsPending = ALL_OPERATIONS;
3297 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3298 !mImpl->IsPlaceholderAvailable() )
3300 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3304 ShowPlaceholderText();
3307 mImpl->mEventData->mUpdateCursorPosition = true;
3308 mImpl->mEventData->mScrollAfterDelete = true;
3310 mImpl->RequestRelayout();
3312 if( NULL != mImpl->mEditableControlInterface )
3314 mImpl->mEditableControlInterface->TextChanged();
3318 case Toolkit::TextSelectionPopup::COPY:
3320 mImpl->SendSelectionToClipboard( false ); // Text not modified
3322 mImpl->mEventData->mUpdateCursorPosition = true;
3324 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
3327 case Toolkit::TextSelectionPopup::PASTE:
3329 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
3332 case Toolkit::TextSelectionPopup::SELECT:
3334 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
3336 if( mImpl->mEventData->mSelectionEnabled )
3338 // Creates a SELECT event.
3339 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
3343 case Toolkit::TextSelectionPopup::SELECT_ALL:
3345 // Creates a SELECT_ALL event
3346 SelectEvent( 0.f, 0.f, true );
3349 case Toolkit::TextSelectionPopup::CLIPBOARD:
3351 mImpl->ShowClipboard();
3354 case Toolkit::TextSelectionPopup::NONE:
3362 void Controller::DisplayTimeExpired()
3364 mImpl->mEventData->mUpdateCursorPosition = true;
3365 // Apply modifications to the model
3366 mImpl->mOperationsPending = ALL_OPERATIONS;
3368 mImpl->RequestRelayout();
3371 // private : Update.
3373 void Controller::InsertText( const std::string& text, Controller::InsertType type )
3375 bool removedPrevious = false;
3376 bool removedSelected = false;
3377 bool maxLengthReached = false;
3379 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
3381 if( NULL == mImpl->mEventData )
3386 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
3387 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
3388 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3390 // TODO: At the moment the underline runs are only for pre-edit.
3391 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
3393 // Remove the previous InputMethodContext pre-edit.
3394 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
3396 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
3397 mImpl->mEventData->mPreEditLength,
3398 DONT_UPDATE_INPUT_STYLE );
3400 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
3401 mImpl->mEventData->mPreEditLength = 0u;
3405 // Remove the previous Selection.
3406 removedSelected = RemoveSelectedText();
3410 Vector<Character> utf32Characters;
3411 Length characterCount = 0u;
3415 // Convert text into UTF-32
3416 utf32Characters.Resize( text.size() );
3418 // This is a bit horrible but std::string returns a (signed) char*
3419 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
3421 // Transform a text array encoded in utf8 into an array encoded in utf32.
3422 // It returns the actual number of characters.
3423 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
3424 utf32Characters.Resize( characterCount );
3426 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
3427 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
3430 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
3432 // The placeholder text is no longer needed
3433 if( mImpl->IsShowingPlaceholderText() )
3438 mImpl->ChangeState( EventData::EDITING );
3440 // Handle the InputMethodContext (predicitive text) state changes
3441 if( COMMIT == type )
3443 // InputMethodContext is no longer handling key-events
3444 mImpl->ClearPreEditFlag();
3448 if( !mImpl->mEventData->mPreEditFlag )
3450 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
3452 // Record the start of the pre-edit text
3453 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
3456 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
3457 mImpl->mEventData->mPreEditFlag = true;
3459 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3462 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
3464 // Restrict new text to fit within Maximum characters setting.
3465 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
3466 maxLengthReached = ( characterCount > maxSizeOfNewText );
3468 // The cursor position.
3469 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3471 // Update the text's style.
3473 // Updates the text style runs by adding characters.
3474 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
3476 // Get the character index from the cursor index.
3477 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
3479 // Retrieve the text's style for the given index.
3481 mImpl->RetrieveDefaultInputStyle( style );
3482 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
3484 // Whether to add a new text color run.
3485 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor ) && !mImpl->mEventData->mInputStyle.isDefaultColor;
3487 // Whether to add a new font run.
3488 const bool addFontNameRun = ( style.familyName != mImpl->mEventData->mInputStyle.familyName ) && mImpl->mEventData->mInputStyle.isFamilyDefined;
3489 const bool addFontWeightRun = ( style.weight != mImpl->mEventData->mInputStyle.weight ) && mImpl->mEventData->mInputStyle.isWeightDefined;
3490 const bool addFontWidthRun = ( style.width != mImpl->mEventData->mInputStyle.width ) && mImpl->mEventData->mInputStyle.isWidthDefined;
3491 const bool addFontSlantRun = ( style.slant != mImpl->mEventData->mInputStyle.slant ) && mImpl->mEventData->mInputStyle.isSlantDefined;
3492 const bool addFontSizeRun = ( style.size != mImpl->mEventData->mInputStyle.size ) && mImpl->mEventData->mInputStyle.isSizeDefined ;
3497 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
3498 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
3500 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
3501 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
3502 colorRun.characterRun.characterIndex = cursorIndex;
3503 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3506 if( addFontNameRun ||
3512 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
3513 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
3515 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
3517 if( addFontNameRun )
3519 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
3520 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
3521 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
3522 fontDescriptionRun.familyDefined = true;
3524 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
3527 if( addFontWeightRun )
3529 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
3530 fontDescriptionRun.weightDefined = true;
3533 if( addFontWidthRun )
3535 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
3536 fontDescriptionRun.widthDefined = true;
3539 if( addFontSlantRun )
3541 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
3542 fontDescriptionRun.slantDefined = true;
3545 if( addFontSizeRun )
3547 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
3548 fontDescriptionRun.sizeDefined = true;
3551 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
3552 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3555 // Insert at current cursor position.
3556 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
3558 if( cursorIndex < numberOfCharactersInModel )
3560 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3564 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3567 // Mark the first paragraph to be updated.
3568 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3570 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3571 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3572 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
3573 mImpl->mTextUpdateInfo.mClearAll = true;
3577 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3578 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
3581 // Update the cursor index.
3582 cursorIndex += maxSizeOfNewText;
3584 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 );
3587 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
3588 mImpl->IsPlaceholderAvailable() )
3590 // Show place-holder if empty after removing the pre-edit text
3591 ShowPlaceholderText();
3592 mImpl->mEventData->mUpdateCursorPosition = true;
3593 mImpl->ClearPreEditFlag();
3595 else if( removedPrevious ||
3597 ( 0 != utf32Characters.Count() ) )
3599 // Queue an inserted event
3600 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
3602 mImpl->mEventData->mUpdateCursorPosition = true;
3603 if( removedSelected )
3605 mImpl->mEventData->mScrollAfterDelete = true;
3609 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3613 if( maxLengthReached )
3615 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
3617 mImpl->ResetInputMethodContext();
3619 if( NULL != mImpl->mEditableControlInterface )
3621 // Do this last since it provides callbacks into application code
3622 mImpl->mEditableControlInterface->MaxLengthReached();
3627 void Controller::PasteText( const std::string& stringToPaste )
3629 InsertText( stringToPaste, Text::Controller::COMMIT );
3630 mImpl->ChangeState( EventData::EDITING );
3631 mImpl->RequestRelayout();
3633 if( NULL != mImpl->mEditableControlInterface )
3635 // Do this last since it provides callbacks into application code
3636 mImpl->mEditableControlInterface->TextChanged();
3640 bool Controller::RemoveText( int cursorOffset,
3641 int numberOfCharacters,
3642 UpdateInputStyleType type )
3644 bool removed = false;
3646 if( NULL == mImpl->mEventData )
3651 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
3652 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
3654 if( !mImpl->IsShowingPlaceholderText() )
3656 // Delete at current cursor position
3657 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
3658 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3660 CharacterIndex cursorIndex = 0;
3662 // Validate the cursor position & number of characters
3663 if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
3665 cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
3668 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
3670 numberOfCharacters = currentText.Count() - cursorIndex;
3673 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.
3674 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
3676 // Mark the paragraphs to be updated.
3677 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3679 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3680 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3681 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
3682 mImpl->mTextUpdateInfo.mClearAll = true;
3686 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3687 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
3690 // Update the input style and remove the text's style before removing the text.
3692 if( UPDATE_INPUT_STYLE == type )
3694 // Keep a copy of the current input style.
3695 InputStyle currentInputStyle;
3696 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
3698 // Set first the default input style.
3699 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
3701 // Update the input style.
3702 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
3704 // Compare if the input style has changed.
3705 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
3707 if( hasInputStyleChanged )
3709 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
3710 // Queue the input style changed signal.
3711 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
3715 // If the number of current text and the number of characters to be deleted are same,
3716 // it means all texts should be removed and all Preedit variables should be initialized.
3717 if( ( currentText.Count() - numberOfCharacters == 0 ) && ( cursorIndex == 0 ) )
3719 if( mImpl->mEventData )
3721 mImpl->mEventData->mPreEditStartPosition = 0;
3722 mImpl->mEventData->mPreEditLength = 0;
3726 // Updates the text style runs by removing characters. Runs with no characters are removed.
3727 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
3729 // Remove the characters.
3730 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
3731 Vector<Character>::Iterator last = first + numberOfCharacters;
3733 currentText.Erase( first, last );
3735 // Cursor position retreat
3736 oldCursorIndex = cursorIndex;
3738 mImpl->mEventData->mScrollAfterDelete = true;
3740 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
3748 bool Controller::RemoveSelectedText()
3750 bool textRemoved( false );
3752 if( EventData::SELECTING == mImpl->mEventData->mState )
3754 std::string removedString;
3755 mImpl->RetrieveSelection( removedString, true );
3757 if( !removedString.empty() )
3760 mImpl->ChangeState( EventData::EDITING );
3767 // private : Relayout.
3769 bool Controller::DoRelayout( const Size& size,
3770 OperationsMask operationsRequired,
3773 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
3774 bool viewUpdated( false );
3776 // Calculate the operations to be done.
3777 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
3779 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
3780 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
3782 // Get the current layout size.
3783 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3785 if( NO_OPERATION != ( LAYOUT & operations ) )
3787 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
3789 // Some vectors with data needed to layout and reorder may be void
3790 // after the first time the text has been laid out.
3791 // Fill the vectors again.
3793 // Calculate the number of glyphs to layout.
3794 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
3795 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
3796 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
3797 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
3799 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
3800 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
3802 // Make sure the index is not out of bound
3803 if ( charactersToGlyph.Count() != glyphsPerCharacter.Count() ||
3804 requestedNumberOfCharacters > charactersToGlyph.Count() ||
3805 ( lastIndex > charactersToGlyph.Count() && charactersToGlyph.Count() > 0u ) )
3807 std::string currentText;
3808 GetText( currentText );
3810 DALI_LOG_ERROR( "Controller::DoRelayout: Attempting to access invalid buffer\n" );
3811 DALI_LOG_ERROR( "Current text is: %s\n", currentText.c_str() );
3812 DALI_LOG_ERROR( "startIndex: %u, lastIndex: %u, requestedNumberOfCharacters: %u, charactersToGlyph.Count = %lu, glyphsPerCharacter.Count = %lu\n", startIndex, lastIndex, requestedNumberOfCharacters, charactersToGlyph.Count(), glyphsPerCharacter.Count());
3817 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
3818 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
3820 if( 0u == totalNumberOfGlyphs )
3822 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3824 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
3827 // Nothing else to do if there is no glyphs.
3828 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
3832 const Vector<LineBreakInfo>& lineBreakInfo = mImpl->mModel->mLogicalModel->mLineBreakInfo;
3833 const Vector<WordBreakInfo>& wordBreakInfo = mImpl->mModel->mLogicalModel->mWordBreakInfo;
3834 const Vector<CharacterDirection>& characterDirection = mImpl->mModel->mLogicalModel->mCharacterDirections;
3835 const Vector<GlyphInfo>& glyphs = mImpl->mModel->mVisualModel->mGlyphs;
3836 const Vector<CharacterIndex>& glyphsToCharactersMap = mImpl->mModel->mVisualModel->mGlyphsToCharacters;
3837 const Vector<Length>& charactersPerGlyph = mImpl->mModel->mVisualModel->mCharactersPerGlyph;
3838 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
3839 const float outlineWidth = static_cast<float>( mImpl->mModel->GetOutlineWidth() );
3841 // Set the layout parameters.
3842 Layout::Parameters layoutParameters( size,
3844 lineBreakInfo.Begin(),
3845 wordBreakInfo.Begin(),
3846 ( 0u != characterDirection.Count() ) ? characterDirection.Begin() : NULL,
3848 glyphsToCharactersMap.Begin(),
3849 charactersPerGlyph.Begin(),
3850 charactersToGlyphBuffer,
3851 glyphsPerCharacterBuffer,
3852 totalNumberOfGlyphs,
3853 mImpl->mModel->mHorizontalAlignment,
3854 mImpl->mModel->mLineWrapMode,
3856 mImpl->mModel->mIgnoreSpacesAfterText,
3857 mImpl->mModel->mMatchSystemLanguageDirection );
3859 // Resize the vector of positions to have the same size than the vector of glyphs.
3860 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
3861 glyphPositions.Resize( totalNumberOfGlyphs );
3863 // Whether the last character is a new paragraph character.
3864 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
3865 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
3867 // The initial glyph and the number of glyphs to layout.
3868 layoutParameters.startGlyphIndex = startGlyphIndex;
3869 layoutParameters.numberOfGlyphs = numberOfGlyphs;
3870 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
3871 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
3873 // Update the ellipsis
3874 bool elideTextEnabled = mImpl->mModel->mElideEnabled;
3876 if( NULL != mImpl->mEventData )
3878 if( mImpl->mEventData->mPlaceholderEllipsisFlag && mImpl->IsShowingPlaceholderText() )
3880 elideTextEnabled = mImpl->mEventData->mIsPlaceholderElideEnabled;
3882 else if( EventData::INACTIVE != mImpl->mEventData->mState )
3884 // Disable ellipsis when editing
3885 elideTextEnabled = false;
3888 // Reset the scroll position in inactive state
3889 if( elideTextEnabled && ( mImpl->mEventData->mState == EventData::INACTIVE ) )
3891 ResetScrollPosition();
3895 // Update the visual model.
3896 bool isAutoScrollEnabled = mImpl->mIsAutoScrollEnabled;
3898 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
3900 mImpl->mModel->mVisualModel->mLines,
3903 isAutoScrollEnabled );
3904 mImpl->mIsAutoScrollEnabled = isAutoScrollEnabled;
3906 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
3910 layoutSize = newLayoutSize;
3912 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
3914 mImpl->mIsTextDirectionRTL = false;
3917 // Reorder the lines
3918 if( NO_OPERATION != ( REORDER & operations ) )
3920 Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = mImpl->mModel->mLogicalModel->mBidirectionalParagraphInfo;
3921 Vector<BidirectionalLineInfoRun>& bidirectionalLineInfo = mImpl->mModel->mLogicalModel->mBidirectionalLineInfo;
3923 // Check first if there are paragraphs with bidirectional info.
3924 if( 0u != bidirectionalInfo.Count() )
3927 const Length numberOfLines = mImpl->mModel->mVisualModel->mLines.Count();
3929 // Reorder the lines.
3930 bidirectionalLineInfo.Reserve( numberOfLines ); // Reserve because is not known yet how many lines have right to left characters.
3931 ReorderLines( bidirectionalInfo,
3933 requestedNumberOfCharacters,
3934 mImpl->mModel->mVisualModel->mLines,
3935 bidirectionalLineInfo );
3937 // Set the bidirectional info per line into the layout parameters.
3938 layoutParameters.lineBidirectionalInfoRunsBuffer = bidirectionalLineInfo.Begin();
3939 layoutParameters.numberOfBidirectionalInfoRuns = bidirectionalLineInfo.Count();
3941 // Re-layout the text. Reorder those lines with right to left characters.
3942 mImpl->mLayoutEngine.ReLayoutRightToLeftLines( layoutParameters,
3944 requestedNumberOfCharacters,
3947 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && ( numberOfLines > 0 ) )
3949 const LineRun* const firstline = mImpl->mModel->mVisualModel->mLines.Begin();
3952 mImpl->mIsTextDirectionRTL = firstline->direction;
3958 // Sets the layout size.
3959 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3961 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
3966 if( NO_OPERATION != ( ALIGN & operations ) )
3968 // The laid-out lines.
3969 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
3971 CharacterIndex alignStartIndex = startIndex;
3972 Length alignRequestedNumberOfCharacters = requestedNumberOfCharacters;
3974 // the whole text needs to be full aligned.
3975 // If you do not do a full aligned, only the last line of the multiline input is aligned.
3976 if( mImpl->mEventData && mImpl->mEventData->mUpdateAlignment )
3978 alignStartIndex = 0u;
3979 alignRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
3980 mImpl->mEventData->mUpdateAlignment = false;
3983 // Need to align with the control's size as the text may contain lines
3984 // starting either with left to right text or right to left.
3985 mImpl->mLayoutEngine.Align( size,
3987 alignRequestedNumberOfCharacters,
3988 mImpl->mModel->mHorizontalAlignment,
3990 mImpl->mModel->mAlignmentOffset,
3991 mImpl->mLayoutDirection,
3992 mImpl->mModel->mMatchSystemLanguageDirection );
3996 #if defined(DEBUG_ENABLED)
3997 std::string currentText;
3998 GetText( currentText );
3999 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mIsTextDirectionRTL[%s] [%s]\n", this, (mImpl->mIsTextDirectionRTL)?"true":"false", currentText.c_str() );
4001 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
4005 void Controller::CalculateVerticalOffset( const Size& controlSize )
4007 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
4009 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
4011 // Get the line height of the default font.
4012 layoutSize.height = mImpl->GetDefaultFontLineHeight();
4015 switch( mImpl->mModel->mVerticalAlignment )
4017 case VerticalAlignment::TOP:
4019 mImpl->mModel->mScrollPosition.y = 0.f;
4022 case VerticalAlignment::CENTER:
4024 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
4027 case VerticalAlignment::BOTTOM:
4029 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
4035 // private : Events.
4037 void Controller::ProcessModifyEvents()
4039 Vector<ModifyEvent>& events = mImpl->mModifyEvents;
4041 if( 0u == events.Count() )
4047 for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
4048 endIt = events.End();
4052 const ModifyEvent& event = *it;
4054 if( ModifyEvent::TEXT_REPLACED == event.type )
4056 // A (single) replace event should come first, otherwise we wasted time processing NOOP events
4057 DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
4059 TextReplacedEvent();
4061 else if( ModifyEvent::TEXT_INSERTED == event.type )
4063 TextInsertedEvent();
4065 else if( ModifyEvent::TEXT_DELETED == event.type )
4067 // Placeholder-text cannot be deleted
4068 if( !mImpl->IsShowingPlaceholderText() )
4075 if( NULL != mImpl->mEventData )
4077 // When the text is being modified, delay cursor blinking
4078 mImpl->mEventData->mDecorator->DelayCursorBlink();
4080 // Update selection position after modifying the text
4081 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
4082 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
4085 // Discard temporary text
4089 void Controller::TextReplacedEvent()
4091 // The natural size needs to be re-calculated.
4092 mImpl->mRecalculateNaturalSize = true;
4094 // The text direction needs to be updated.
4095 mImpl->mUpdateTextDirection = true;
4097 // Apply modifications to the model
4098 mImpl->mOperationsPending = ALL_OPERATIONS;
4101 void Controller::TextInsertedEvent()
4103 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
4105 if( NULL == mImpl->mEventData )
4110 mImpl->mEventData->mCheckScrollAmount = true;
4112 // The natural size needs to be re-calculated.
4113 mImpl->mRecalculateNaturalSize = true;
4115 // The text direction needs to be updated.
4116 mImpl->mUpdateTextDirection = true;
4118 // Apply modifications to the model; TODO - Optimize this
4119 mImpl->mOperationsPending = ALL_OPERATIONS;
4122 void Controller::TextDeletedEvent()
4124 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
4126 if( NULL == mImpl->mEventData )
4131 mImpl->mEventData->mCheckScrollAmount = true;
4133 // The natural size needs to be re-calculated.
4134 mImpl->mRecalculateNaturalSize = true;
4136 // The text direction needs to be updated.
4137 mImpl->mUpdateTextDirection = true;
4139 // Apply modifications to the model; TODO - Optimize this
4140 mImpl->mOperationsPending = ALL_OPERATIONS;
4143 bool Controller::DeleteEvent( int keyCode )
4145 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p KeyCode : %d \n", this, keyCode );
4147 bool removed = false;
4149 if( NULL == mImpl->mEventData )
4154 // InputMethodContext is no longer handling key-events
4155 mImpl->ClearPreEditFlag();
4157 if( EventData::SELECTING == mImpl->mEventData->mState )
4159 removed = RemoveSelectedText();
4161 else if( ( mImpl->mEventData->mPrimaryCursorPosition > 0 ) && ( keyCode == Dali::DALI_KEY_BACKSPACE) )
4163 // Remove the character before the current cursor position
4164 removed = RemoveText( -1,
4166 UPDATE_INPUT_STYLE );
4168 else if( keyCode == Dali::DevelKey::DALI_KEY_DELETE )
4170 // Remove the character after the current cursor position
4171 removed = RemoveText( 0,
4173 UPDATE_INPUT_STYLE );
4178 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
4179 !mImpl->IsPlaceholderAvailable() )
4181 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
4185 ShowPlaceholderText();
4187 mImpl->mEventData->mUpdateCursorPosition = true;
4188 mImpl->mEventData->mScrollAfterDelete = true;
4194 // private : Helpers.
4196 void Controller::ResetText()
4199 mImpl->mModel->mLogicalModel->mText.Clear();
4201 // Reset the embedded images buffer.
4202 mImpl->mModel->mLogicalModel->ClearEmbeddedImages();
4204 // We have cleared everything including the placeholder-text
4205 mImpl->PlaceholderCleared();
4207 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4208 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4209 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
4211 // Clear any previous text.
4212 mImpl->mTextUpdateInfo.mClearAll = true;
4214 // The natural size needs to be re-calculated.
4215 mImpl->mRecalculateNaturalSize = true;
4217 // The text direction needs to be updated.
4218 mImpl->mUpdateTextDirection = true;
4220 // Apply modifications to the model
4221 mImpl->mOperationsPending = ALL_OPERATIONS;
4224 void Controller::ShowPlaceholderText()
4226 if( mImpl->IsPlaceholderAvailable() )
4228 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
4230 if( NULL == mImpl->mEventData )
4235 mImpl->mEventData->mIsShowingPlaceholderText = true;
4237 // Disable handles when showing place-holder text
4238 mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
4239 mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
4240 mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
4242 const char* text( NULL );
4245 // TODO - Switch Placeholder text when changing state
4246 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
4247 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
4249 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
4250 size = mImpl->mEventData->mPlaceholderTextActive.size();
4254 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
4255 size = mImpl->mEventData->mPlaceholderTextInactive.size();
4258 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4259 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4261 // Reset model for showing placeholder.
4262 mImpl->mModel->mLogicalModel->mText.Clear();
4263 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
4265 // Convert text into UTF-32
4266 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
4267 utf32Characters.Resize( size );
4269 // This is a bit horrible but std::string returns a (signed) char*
4270 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
4272 // Transform a text array encoded in utf8 into an array encoded in utf32.
4273 // It returns the actual number of characters.
4274 const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
4275 utf32Characters.Resize( characterCount );
4277 // The characters to be added.
4278 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
4280 // Reset the cursor position
4281 mImpl->mEventData->mPrimaryCursorPosition = 0;
4283 // The natural size needs to be re-calculated.
4284 mImpl->mRecalculateNaturalSize = true;
4286 // The text direction needs to be updated.
4287 mImpl->mUpdateTextDirection = true;
4289 // Apply modifications to the model
4290 mImpl->mOperationsPending = ALL_OPERATIONS;
4292 // Update the rest of the model during size negotiation
4293 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
4297 void Controller::ClearFontData()
4299 if( mImpl->mFontDefaults )
4301 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
4304 // Set flags to update the model.
4305 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4306 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4307 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
4309 mImpl->mTextUpdateInfo.mClearAll = true;
4310 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
4311 mImpl->mRecalculateNaturalSize = true;
4313 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
4319 UPDATE_LAYOUT_SIZE |
4324 void Controller::ClearStyleData()
4326 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
4327 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
4330 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
4332 // Reset the cursor position
4333 if( NULL != mImpl->mEventData )
4335 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
4337 // Update the cursor if it's in editing mode.
4338 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
4340 mImpl->mEventData->mUpdateCursorPosition = true;
4345 void Controller::ResetScrollPosition()
4347 if( NULL != mImpl->mEventData )
4349 // Reset the scroll position.
4350 mImpl->mModel->mScrollPosition = Vector2::ZERO;
4351 mImpl->mEventData->mScrollAfterUpdatePosition = true;
4355 void Controller::SetControlInterface( ControlInterface* controlInterface )
4357 mImpl->mControlInterface = controlInterface;
4360 bool Controller::ShouldClearFocusOnEscape() const
4362 return mImpl->mShouldClearFocusOnEscape;
4365 // private : Private contructors & copy operator.
4367 Controller::Controller()
4370 mImpl = new Controller::Impl( NULL, NULL );
4373 Controller::Controller( ControlInterface* controlInterface )
4375 mImpl = new Controller::Impl( controlInterface, NULL );
4378 Controller::Controller( ControlInterface* controlInterface,
4379 EditableControlInterface* editableControlInterface )
4381 mImpl = new Controller::Impl( controlInterface,
4382 editableControlInterface );
4385 // The copy constructor and operator are left unimplemented.
4387 // protected : Destructor.
4389 Controller::~Controller()
4396 } // namespace Toolkit