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 |
2050 GET_GLYPH_METRICS );
2052 // Set the update info to relayout the whole text.
2053 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2054 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2056 // Make sure the model is up-to-date before layouting
2057 mImpl->UpdateModel( onlyOnceOperations );
2059 // Layout the text for the new width.
2060 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT | REORDER );
2062 // Store the actual control's size to restore later.
2063 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
2065 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
2066 static_cast<OperationsMask>( onlyOnceOperations |
2068 naturalSize.GetVectorXY() );
2070 // Do not do again the only once operations.
2071 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2073 // Do the size related operations again.
2074 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
2077 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
2079 // Stores the natural size to avoid recalculate it again
2080 // unless the text/style changes.
2081 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
2083 mImpl->mRecalculateNaturalSize = false;
2085 // Clear the update info. This info will be set the next time the text is updated.
2086 mImpl->mTextUpdateInfo.Clear();
2087 mImpl->mTextUpdateInfo.mClearAll = true;
2089 // Restore the actual control's size.
2090 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
2092 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
2096 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
2098 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
2101 naturalSize.x = ConvertToEven( naturalSize.x );
2102 naturalSize.y = ConvertToEven( naturalSize.y );
2107 bool Controller::CheckForTextFit( float pointSize, Size& layoutSize )
2110 mImpl->mFontDefaults->mFitPointSize = pointSize;
2111 mImpl->mFontDefaults->sizeDefined = true;
2114 // Operations that can be done only once until the text changes.
2115 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2121 GET_GLYPH_METRICS );
2123 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2124 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2126 // Make sure the model is up-to-date before layouting
2127 mImpl->UpdateModel( onlyOnceOperations );
2129 DoRelayout( Size( layoutSize.width, MAX_FLOAT ),
2130 static_cast<OperationsMask>( onlyOnceOperations | LAYOUT),
2133 // Clear the update info. This info will be set the next time the text is updated.
2134 mImpl->mTextUpdateInfo.Clear();
2135 mImpl->mTextUpdateInfo.mClearAll = true;
2137 if( textSize.width > layoutSize.width || textSize.height > layoutSize.height )
2144 void Controller::FitPointSizeforLayout( Size layoutSize )
2146 const OperationsMask operations = mImpl->mOperationsPending;
2147 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
2149 bool actualellipsis = mImpl->mModel->mElideEnabled;
2150 float minPointSize = mImpl->mTextFitMinSize;
2151 float maxPointSize = mImpl->mTextFitMaxSize;
2152 float pointInterval = mImpl->mTextFitStepSize;
2154 mImpl->mModel->mElideEnabled = false;
2155 Vector<float> pointSizeArray;
2158 if( pointInterval < 1.f )
2160 mImpl->mTextFitStepSize = pointInterval = 1.0f;
2163 pointSizeArray.Reserve( static_cast< unsigned int >( ceil( ( maxPointSize - minPointSize ) / pointInterval ) ) );
2165 for( float i = minPointSize; i < maxPointSize; i += pointInterval )
2167 pointSizeArray.PushBack( i );
2170 pointSizeArray.PushBack( maxPointSize );
2172 int bestSizeIndex = 0;
2173 int min = bestSizeIndex + 1;
2174 int max = pointSizeArray.Size() - 1;
2177 int destI = ( min + max ) / 2;
2179 if( CheckForTextFit( pointSizeArray[destI], layoutSize ) )
2181 bestSizeIndex = min;
2187 bestSizeIndex = max;
2191 mImpl->mModel->mElideEnabled = actualellipsis;
2192 mImpl->mFontDefaults->mFitPointSize = pointSizeArray[bestSizeIndex];
2193 mImpl->mFontDefaults->sizeDefined = true;
2198 float Controller::GetHeightForWidth( float width )
2200 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
2201 // Make sure the model is up-to-date before layouting
2202 ProcessModifyEvents();
2205 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ||
2206 mImpl->mTextUpdateInfo.mFullRelayoutNeeded ||
2207 mImpl->mTextUpdateInfo.mClearAll )
2209 // Operations that can be done only once until the text changes.
2210 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2216 GET_GLYPH_METRICS );
2218 // Set the update info to relayout the whole text.
2219 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2220 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2222 // Make sure the model is up-to-date before layouting
2223 mImpl->UpdateModel( onlyOnceOperations );
2226 // Layout the text for the new width.
2227 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
2229 // Store the actual control's width.
2230 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
2232 DoRelayout( Size( width, MAX_FLOAT ),
2233 static_cast<OperationsMask>( onlyOnceOperations |
2237 // Do not do again the only once operations.
2238 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2240 // Do the size related operations again.
2241 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
2245 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
2247 // Clear the update info. This info will be set the next time the text is updated.
2248 mImpl->mTextUpdateInfo.Clear();
2249 mImpl->mTextUpdateInfo.mClearAll = true;
2251 // Restore the actual control's width.
2252 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
2254 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
2258 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
2259 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
2262 return layoutSize.height;
2265 int Controller::GetLineCount( float width )
2267 GetHeightForWidth( width );
2268 int numberofLines = mImpl->mModel->GetNumberOfLines();
2269 return numberofLines;
2272 const ModelInterface* const Controller::GetTextModel() const
2274 return mImpl->mModel.Get();
2277 float Controller::GetScrollAmountByUserInput()
2279 float scrollAmount = 0.0f;
2281 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
2283 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
2284 mImpl->mEventData->mCheckScrollAmount = false;
2286 return scrollAmount;
2289 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
2291 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
2294 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
2295 layoutHeight = layout.height;
2296 scrollPosition = mImpl->mModel->mScrollPosition.y;
2297 isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
2301 void Controller::SetHiddenInputOption(const Property::Map& options )
2303 if( NULL == mImpl->mHiddenInput )
2305 mImpl->mHiddenInput = new HiddenText( this );
2307 mImpl->mHiddenInput->SetProperties(options);
2310 void Controller::GetHiddenInputOption(Property::Map& options )
2312 if( NULL != mImpl->mHiddenInput )
2314 mImpl->mHiddenInput->GetProperties(options);
2318 void Controller::SetPlaceholderProperty( const Property::Map& map )
2320 const Property::Map::SizeType count = map.Count();
2322 for( Property::Map::SizeType position = 0; position < count; ++position )
2324 KeyValuePair keyValue = map.GetKeyValue( position );
2325 Property::Key& key = keyValue.first;
2326 Property::Value& value = keyValue.second;
2328 if( key == Toolkit::Text::PlaceHolder::Property::TEXT || key == PLACEHOLDER_TEXT )
2330 std::string text = "";
2332 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
2334 else if( key == Toolkit::Text::PlaceHolder::Property::TEXT_FOCUSED || key == PLACEHOLDER_TEXT_FOCUSED )
2336 std::string text = "";
2338 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
2340 else if( key == Toolkit::Text::PlaceHolder::Property::COLOR || key == PLACEHOLDER_COLOR )
2343 value.Get( textColor );
2344 if( GetPlaceholderTextColor() != textColor )
2346 SetPlaceholderTextColor( textColor );
2349 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_FAMILY || key == PLACEHOLDER_FONT_FAMILY )
2351 std::string fontFamily = "";
2352 value.Get( fontFamily );
2353 SetPlaceholderFontFamily( fontFamily );
2355 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_STYLE || key == PLACEHOLDER_FONT_STYLE )
2357 SetFontStyleProperty( this, value, Text::FontStyle::PLACEHOLDER );
2359 else if( key == Toolkit::Text::PlaceHolder::Property::POINT_SIZE || key == PLACEHOLDER_POINT_SIZE )
2362 value.Get( pointSize );
2363 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
2365 SetPlaceholderTextFontSize( pointSize, Text::Controller::POINT_SIZE );
2368 else if( key == Toolkit::Text::PlaceHolder::Property::PIXEL_SIZE || key == PLACEHOLDER_PIXEL_SIZE )
2371 value.Get( pixelSize );
2372 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
2374 SetPlaceholderTextFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
2377 else if( key == Toolkit::Text::PlaceHolder::Property::ELLIPSIS || key == PLACEHOLDER_ELLIPSIS )
2380 value.Get( ellipsis );
2381 SetPlaceholderTextElideEnabled( ellipsis );
2386 void Controller::GetPlaceholderProperty( Property::Map& map )
2388 if( NULL != mImpl->mEventData )
2390 if( !mImpl->mEventData->mPlaceholderTextActive.empty() )
2392 map[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = mImpl->mEventData->mPlaceholderTextActive;
2394 if( !mImpl->mEventData->mPlaceholderTextInactive.empty() )
2396 map[ Text::PlaceHolder::Property::TEXT ] = mImpl->mEventData->mPlaceholderTextInactive;
2399 map[ Text::PlaceHolder::Property::COLOR ] = mImpl->mEventData->mPlaceholderTextColor;
2400 map[ Text::PlaceHolder::Property::FONT_FAMILY ] = GetPlaceholderFontFamily();
2402 Property::Value fontStyleMapGet;
2403 GetFontStyleProperty( this, fontStyleMapGet, Text::FontStyle::PLACEHOLDER );
2404 map[ Text::PlaceHolder::Property::FONT_STYLE ] = fontStyleMapGet;
2406 // Choose font size : POINT_SIZE or PIXEL_SIZE
2407 if( !mImpl->mEventData->mIsPlaceholderPixelSize )
2409 map[ Text::PlaceHolder::Property::POINT_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE );
2413 map[ Text::PlaceHolder::Property::PIXEL_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE );
2416 if( mImpl->mEventData->mPlaceholderEllipsisFlag )
2418 map[ Text::PlaceHolder::Property::ELLIPSIS ] = IsPlaceholderTextElideEnabled();
2423 Toolkit::DevelText::TextDirection::Type Controller::GetTextDirection()
2425 // Make sure the model is up-to-date before layouting
2426 ProcessModifyEvents();
2428 if ( mImpl->mUpdateTextDirection )
2430 // Operations that can be done only once until the text changes.
2431 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2437 GET_GLYPH_METRICS );
2439 // Set the update info to relayout the whole text.
2440 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2441 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2443 // Make sure the model is up-to-date before layouting
2444 mImpl->UpdateModel( onlyOnceOperations );
2446 Vector3 naturalSize;
2447 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
2448 static_cast<OperationsMask>( onlyOnceOperations |
2449 LAYOUT | REORDER | UPDATE_DIRECTION ),
2450 naturalSize.GetVectorXY() );
2452 // Do not do again the only once operations.
2453 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2455 // Clear the update info. This info will be set the next time the text is updated.
2456 mImpl->mTextUpdateInfo.Clear();
2458 mImpl->mUpdateTextDirection = false;
2461 return mImpl->mIsTextDirectionRTL ? Toolkit::DevelText::TextDirection::RIGHT_TO_LEFT : Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT;
2464 Toolkit::DevelText::VerticalLineAlignment::Type Controller::GetVerticalLineAlignment() const
2466 return mImpl->mModel->GetVerticalLineAlignment();
2469 void Controller::SetVerticalLineAlignment( Toolkit::DevelText::VerticalLineAlignment::Type alignment )
2471 mImpl->mModel->mVerticalLineAlignment = alignment;
2474 // public : Relayout.
2476 Controller::UpdateTextType Controller::Relayout( const Size& size, Dali::LayoutDirection::Type layoutDirection )
2478 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
2480 UpdateTextType updateTextType = NONE_UPDATED;
2482 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
2484 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
2486 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
2487 updateTextType = MODEL_UPDATED;
2490 // Clear the update info. This info will be set the next time the text is updated.
2491 mImpl->mTextUpdateInfo.Clear();
2493 // Not worth to relayout if width or height is equal to zero.
2494 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
2496 return updateTextType;
2499 // Whether a new size has been set.
2500 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
2504 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
2506 if( ( 0 == mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd ) &&
2507 ( 0 == mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) &&
2508 ( ( mImpl->mModel->mVisualModel->mControlSize.width < Math::MACHINE_EPSILON_1000 ) || ( mImpl->mModel->mVisualModel->mControlSize.height < Math::MACHINE_EPSILON_1000 ) ) )
2510 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
2513 // Layout operations that need to be done if the size changes.
2514 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2517 UPDATE_LAYOUT_SIZE |
2519 // Set the update info to relayout the whole text.
2520 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2521 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2523 // Store the size used to layout the text.
2524 mImpl->mModel->mVisualModel->mControlSize = size;
2527 // Whether there are modify events.
2528 if( 0u != mImpl->mModifyEvents.Count() )
2530 // Style operations that need to be done if the text is modified.
2531 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2535 // Set the update info to elide the text.
2536 if( mImpl->mModel->mElideEnabled ||
2537 ( ( NULL != mImpl->mEventData ) && mImpl->mEventData->mIsPlaceholderElideEnabled ) )
2539 // Update Text layout for applying elided
2540 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2543 UPDATE_LAYOUT_SIZE |
2545 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2546 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2549 if( mImpl->mModel->mMatchSystemLanguageDirection && mImpl->mLayoutDirection != layoutDirection )
2551 // Clear the update info. This info will be set the next time the text is updated.
2552 mImpl->mTextUpdateInfo.mClearAll = true;
2553 // Apply modifications to the model
2554 // Shape the text again is needed because characters like '()[]{}' have to be mirrored and the glyphs generated again.
2555 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2562 mImpl->mLayoutDirection = layoutDirection;
2565 // Make sure the model is up-to-date before layouting.
2566 ProcessModifyEvents();
2567 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
2571 updated = DoRelayout( size,
2572 mImpl->mOperationsPending,
2573 layoutSize ) || updated;
2578 updateTextType = MODEL_UPDATED;
2581 // Do not re-do any operation until something changes.
2582 mImpl->mOperationsPending = NO_OPERATION;
2583 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
2585 // Whether the text control is editable
2586 const bool isEditable = NULL != mImpl->mEventData;
2588 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
2590 if( newSize && isEditable )
2592 offset = mImpl->mModel->mScrollPosition;
2595 if( !isEditable || !IsMultiLineEnabled() )
2597 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
2598 CalculateVerticalOffset( size );
2605 // If there is a new size, the scroll position needs to be clamped.
2606 mImpl->ClampHorizontalScroll( layoutSize );
2608 // Update the decorator's positions is needed if there is a new size.
2609 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
2612 // Move the cursor, grab handle etc.
2613 if( mImpl->ProcessInputEvents() )
2615 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
2619 // Clear the update info. This info will be set the next time the text is updated.
2620 mImpl->mTextUpdateInfo.Clear();
2621 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
2623 return updateTextType;
2626 void Controller::RequestRelayout()
2628 mImpl->RequestRelayout();
2631 // public : Input style change signals.
2633 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
2635 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
2638 void Controller::ProcessInputStyleChangedSignals()
2640 if( NULL == mImpl->mEventData )
2646 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
2647 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
2651 const InputStyle::Mask mask = *it;
2653 if( NULL != mImpl->mEditableControlInterface )
2655 // Emit the input style changed signal.
2656 mImpl->mEditableControlInterface->InputStyleChanged( mask );
2660 mImpl->mEventData->mInputStyleChangedQueue.Clear();
2663 // public : Text-input Event Queuing.
2665 void Controller::KeyboardFocusGainEvent()
2667 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
2669 if( NULL != mImpl->mEventData )
2671 if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
2672 ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
2674 mImpl->ChangeState( EventData::EDITING );
2675 mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
2676 mImpl->mEventData->mUpdateInputStyle = true;
2677 mImpl->mEventData->mScrollAfterUpdatePosition = true;
2679 mImpl->NotifyInputMethodContextMultiLineStatus();
2680 if( mImpl->IsShowingPlaceholderText() )
2682 // Show alternative placeholder-text when editing
2683 ShowPlaceholderText();
2686 mImpl->RequestRelayout();
2690 void Controller::KeyboardFocusLostEvent()
2692 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
2694 if( NULL != mImpl->mEventData )
2696 if( EventData::INTERRUPTED != mImpl->mEventData->mState )
2698 mImpl->ChangeState( EventData::INACTIVE );
2700 if( !mImpl->IsShowingRealText() )
2702 // Revert to regular placeholder-text when not editing
2703 ShowPlaceholderText();
2707 mImpl->RequestRelayout();
2710 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
2712 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
2714 bool textChanged = false;
2715 bool relayoutNeeded = false;
2717 if( ( NULL != mImpl->mEventData ) &&
2718 ( keyEvent.state == KeyEvent::Down ) )
2720 int keyCode = keyEvent.keyCode;
2721 const std::string& keyString = keyEvent.keyPressed;
2722 const std::string keyName = keyEvent.keyPressedName;
2724 const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
2726 // Pre-process to separate modifying events from non-modifying input events.
2729 // In some platforms arrive key events with no key code.
2733 else if( Dali::DALI_KEY_ESCAPE == keyCode || Dali::DALI_KEY_BACK == keyCode || Dali::DALI_KEY_SEARCH == keyCode )
2738 else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) ||
2739 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
2740 ( Dali::DALI_KEY_CURSOR_UP == keyCode ) ||
2741 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) )
2743 // If don't have any text, do nothing.
2744 if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
2749 uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition;
2750 uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2751 uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition );
2752 uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines();
2754 // Logic to determine whether this text control will lose focus or not.
2755 if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2756 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2757 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) ||
2758 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) ||
2759 ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) ||
2760 ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) )
2762 // Release the active highlight.
2763 if( mImpl->mEventData->mState == EventData::SELECTING )
2765 mImpl->ChangeState( EventData::EDITING );
2767 // Update selection position.
2768 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2769 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2770 mImpl->mEventData->mUpdateCursorPosition = true;
2771 mImpl->RequestRelayout();
2776 mImpl->mEventData->mCheckScrollAmount = true;
2777 Event event( Event::CURSOR_KEY_EVENT );
2778 event.p1.mInt = keyCode;
2779 event.p2.mBool = keyEvent.IsShiftModifier();
2780 mImpl->mEventData->mEventQueue.push_back( event );
2782 // Will request for relayout.
2783 relayoutNeeded = true;
2785 else if ( Dali::DevelKey::DALI_KEY_CONTROL_LEFT == keyCode || Dali::DevelKey::DALI_KEY_CONTROL_RIGHT == keyCode )
2787 // Left or Right Control key event is received before Ctrl-C/V/X key event is received
2788 // If not handle it here, any selected text will be deleted
2793 else if ( keyEvent.IsCtrlModifier() )
2795 bool consumed = false;
2796 if (keyName == KEY_C_NAME)
2798 // Ctrl-C to copy the selected text
2799 TextPopupButtonTouched( Toolkit::TextSelectionPopup::COPY );
2802 else if (keyName == KEY_V_NAME)
2804 // Ctrl-V to paste the copied text
2805 TextPopupButtonTouched( Toolkit::TextSelectionPopup::PASTE );
2808 else if (keyName == KEY_X_NAME)
2810 // Ctrl-X to cut the selected text
2811 TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
2816 else if( ( Dali::DALI_KEY_BACKSPACE == keyCode ) ||
2817 ( Dali::DevelKey::DALI_KEY_DELETE == keyCode ) )
2819 textChanged = DeleteEvent( keyCode );
2821 // Will request for relayout.
2822 relayoutNeeded = true;
2824 else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
2825 IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
2826 IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
2828 // Power key/Menu/Home key behaviour does not allow edit mode to resume.
2829 mImpl->ChangeState( EventData::INACTIVE );
2831 // Will request for relayout.
2832 relayoutNeeded = true;
2834 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2836 else if( ( Dali::DALI_KEY_SHIFT_LEFT == keyCode ) || ( Dali::DALI_KEY_SHIFT_RIGHT == keyCode ) )
2838 // 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
2839 // and a character is typed after the type of a upper case latin character.
2844 else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
2846 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2852 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
2854 if( !keyString.empty() )
2856 // InputMethodContext is no longer handling key-events
2857 mImpl->ClearPreEditFlag();
2859 InsertText( keyString, COMMIT );
2863 // Will request for relayout.
2864 relayoutNeeded = true;
2869 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
2870 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
2872 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
2873 ( Dali::DALI_KEY_SHIFT_RIGHT != keyCode ) &&
2874 ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
2875 ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
2877 // Should not change the state if the key is the shift send by the InputMethodContext.
2878 // Otherwise, when the state is SELECTING the text controller can't send the right
2879 // surrounding info to the InputMethodContext.
2880 mImpl->ChangeState( EventData::EDITING );
2882 // Will request for relayout.
2883 relayoutNeeded = true;
2886 if( relayoutNeeded )
2888 mImpl->RequestRelayout();
2893 ( NULL != mImpl->mEditableControlInterface ) )
2895 // Do this last since it provides callbacks into application code
2896 mImpl->mEditableControlInterface->TextChanged();
2902 void Controller::TapEvent( unsigned int tapCount, float x, float y )
2904 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
2906 if( NULL != mImpl->mEventData )
2908 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
2909 EventData::State state( mImpl->mEventData->mState );
2910 bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
2912 if( mImpl->IsClipboardVisible() )
2914 if( EventData::INACTIVE == state || EventData::EDITING == state)
2916 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2918 relayoutNeeded = true;
2920 else if( 1u == tapCount )
2922 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
2924 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
2927 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
2929 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2930 relayoutNeeded = true;
2934 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
2936 // Hide placeholder text
2940 if( EventData::INACTIVE == state )
2942 mImpl->ChangeState( EventData::EDITING );
2944 else if( !mImpl->IsClipboardEmpty() )
2946 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
2948 relayoutNeeded = true;
2951 else if( 2u == tapCount )
2953 if( mImpl->mEventData->mSelectionEnabled &&
2954 mImpl->IsShowingRealText() )
2956 relayoutNeeded = true;
2957 mImpl->mEventData->mIsLeftHandleSelected = true;
2958 mImpl->mEventData->mIsRightHandleSelected = true;
2962 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
2963 if( relayoutNeeded )
2965 Event event( Event::TAP_EVENT );
2966 event.p1.mUint = tapCount;
2967 event.p2.mFloat = x;
2968 event.p3.mFloat = y;
2969 mImpl->mEventData->mEventQueue.push_back( event );
2971 mImpl->RequestRelayout();
2975 // Reset keyboard as tap event has occurred.
2976 mImpl->ResetInputMethodContext();
2979 void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
2981 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
2983 if( NULL != mImpl->mEventData )
2985 Event event( Event::PAN_EVENT );
2986 event.p1.mInt = state;
2987 event.p2.mFloat = displacement.x;
2988 event.p3.mFloat = displacement.y;
2989 mImpl->mEventData->mEventQueue.push_back( event );
2991 mImpl->RequestRelayout();
2995 void Controller::LongPressEvent( Gesture::State state, float x, float y )
2997 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
2999 if( ( state == Gesture::Started ) &&
3000 ( NULL != mImpl->mEventData ) )
3002 // The 1st long-press on inactive text-field is treated as tap
3003 if( EventData::INACTIVE == mImpl->mEventData->mState )
3005 mImpl->ChangeState( EventData::EDITING );
3007 Event event( Event::TAP_EVENT );
3009 event.p2.mFloat = x;
3010 event.p3.mFloat = y;
3011 mImpl->mEventData->mEventQueue.push_back( event );
3013 mImpl->RequestRelayout();
3015 else if( !mImpl->IsShowingRealText() )
3017 Event event( Event::LONG_PRESS_EVENT );
3018 event.p1.mInt = state;
3019 event.p2.mFloat = x;
3020 event.p3.mFloat = y;
3021 mImpl->mEventData->mEventQueue.push_back( event );
3022 mImpl->RequestRelayout();
3024 else if( !mImpl->IsClipboardVisible() )
3026 // Reset the InputMethodContext to commit the pre-edit before selecting the text.
3027 mImpl->ResetInputMethodContext();
3029 Event event( Event::LONG_PRESS_EVENT );
3030 event.p1.mInt = state;
3031 event.p2.mFloat = x;
3032 event.p3.mFloat = y;
3033 mImpl->mEventData->mEventQueue.push_back( event );
3034 mImpl->RequestRelayout();
3036 mImpl->mEventData->mIsLeftHandleSelected = true;
3037 mImpl->mEventData->mIsRightHandleSelected = true;
3042 void Controller::SelectEvent( float x, float y, bool selectAll )
3044 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
3046 if( NULL != mImpl->mEventData )
3050 Event event( Event::SELECT_ALL );
3051 mImpl->mEventData->mEventQueue.push_back( event );
3055 Event event( Event::SELECT );
3056 event.p2.mFloat = x;
3057 event.p3.mFloat = y;
3058 mImpl->mEventData->mEventQueue.push_back( event );
3061 mImpl->mEventData->mCheckScrollAmount = true;
3062 mImpl->mEventData->mIsLeftHandleSelected = true;
3063 mImpl->mEventData->mIsRightHandleSelected = true;
3064 mImpl->RequestRelayout();
3068 InputMethodContext::CallbackData Controller::OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
3070 // Whether the text needs to be relaid-out.
3071 bool requestRelayout = false;
3073 // Whether to retrieve the text and cursor position to be sent to the InputMethodContext.
3074 bool retrieveText = false;
3075 bool retrieveCursor = false;
3077 switch( inputMethodContextEvent.eventName )
3079 case InputMethodContext::COMMIT:
3081 InsertText( inputMethodContextEvent.predictiveString, Text::Controller::COMMIT );
3082 requestRelayout = true;
3083 retrieveCursor = true;
3086 case InputMethodContext::PRE_EDIT:
3088 InsertText( inputMethodContextEvent.predictiveString, Text::Controller::PRE_EDIT );
3089 requestRelayout = true;
3090 retrieveCursor = true;
3093 case InputMethodContext::DELETE_SURROUNDING:
3095 const bool textDeleted = RemoveText( inputMethodContextEvent.cursorOffset,
3096 inputMethodContextEvent.numberOfChars,
3097 DONT_UPDATE_INPUT_STYLE );
3101 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3102 !mImpl->IsPlaceholderAvailable() )
3104 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3108 ShowPlaceholderText();
3110 mImpl->mEventData->mUpdateCursorPosition = true;
3111 mImpl->mEventData->mScrollAfterDelete = true;
3113 requestRelayout = true;
3117 case InputMethodContext::GET_SURROUNDING:
3119 retrieveText = true;
3120 retrieveCursor = true;
3123 case InputMethodContext::PRIVATE_COMMAND:
3125 // PRIVATECOMMAND event is just for getting the private command message
3126 retrieveText = true;
3127 retrieveCursor = true;
3130 case InputMethodContext::VOID:
3137 if( requestRelayout )
3139 mImpl->mOperationsPending = ALL_OPERATIONS;
3140 mImpl->RequestRelayout();
3144 CharacterIndex cursorPosition = 0u;
3145 Length numberOfWhiteSpaces = 0u;
3147 if( retrieveCursor )
3149 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
3151 cursorPosition = mImpl->GetLogicalCursorPosition();
3153 if( cursorPosition < numberOfWhiteSpaces )
3155 cursorPosition = 0u;
3159 cursorPosition -= numberOfWhiteSpaces;
3165 if( !mImpl->IsShowingPlaceholderText() )
3167 // Retrieves the normal text string.
3168 mImpl->GetText( numberOfWhiteSpaces, text );
3172 // When the current text is Placeholder Text, the surrounding text should be empty string.
3173 // It means DALi should send empty string ("") to IME.
3178 InputMethodContext::CallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
3180 if( requestRelayout &&
3181 ( NULL != mImpl->mEditableControlInterface ) )
3183 // Do this last since it provides callbacks into application code
3184 mImpl->mEditableControlInterface->TextChanged();
3187 return callbackData;
3190 void Controller::PasteClipboardItemEvent()
3192 // Retrieve the clipboard contents first
3193 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
3194 std::string stringToPaste( notifier.GetContent() );
3196 // Commit the current pre-edit text; the contents of the clipboard should be appended
3197 mImpl->ResetInputMethodContext();
3199 // Temporary disable hiding clipboard
3200 mImpl->SetClipboardHideEnable( false );
3203 PasteText( stringToPaste );
3205 mImpl->SetClipboardHideEnable( true );
3208 // protected : Inherit from Text::Decorator::ControllerInterface.
3210 void Controller::GetTargetSize( Vector2& targetSize )
3212 targetSize = mImpl->mModel->mVisualModel->mControlSize;
3215 void Controller::AddDecoration( Actor& actor, bool needsClipping )
3217 if( NULL != mImpl->mEditableControlInterface )
3219 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
3223 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
3225 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
3227 if( NULL != mImpl->mEventData )
3229 switch( handleType )
3233 Event event( Event::GRAB_HANDLE_EVENT );
3234 event.p1.mUint = state;
3235 event.p2.mFloat = x;
3236 event.p3.mFloat = y;
3238 mImpl->mEventData->mEventQueue.push_back( event );
3241 case LEFT_SELECTION_HANDLE:
3243 Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
3244 event.p1.mUint = state;
3245 event.p2.mFloat = x;
3246 event.p3.mFloat = y;
3248 mImpl->mEventData->mEventQueue.push_back( event );
3251 case RIGHT_SELECTION_HANDLE:
3253 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
3254 event.p1.mUint = state;
3255 event.p2.mFloat = x;
3256 event.p3.mFloat = y;
3258 mImpl->mEventData->mEventQueue.push_back( event );
3261 case LEFT_SELECTION_HANDLE_MARKER:
3262 case RIGHT_SELECTION_HANDLE_MARKER:
3264 // Markers do not move the handles.
3267 case HANDLE_TYPE_COUNT:
3269 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
3273 mImpl->RequestRelayout();
3277 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
3279 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
3281 if( NULL == mImpl->mEventData )
3288 case Toolkit::TextSelectionPopup::CUT:
3290 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
3291 mImpl->mOperationsPending = ALL_OPERATIONS;
3293 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3294 !mImpl->IsPlaceholderAvailable() )
3296 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3300 ShowPlaceholderText();
3303 mImpl->mEventData->mUpdateCursorPosition = true;
3304 mImpl->mEventData->mScrollAfterDelete = true;
3306 mImpl->RequestRelayout();
3308 if( NULL != mImpl->mEditableControlInterface )
3310 mImpl->mEditableControlInterface->TextChanged();
3314 case Toolkit::TextSelectionPopup::COPY:
3316 mImpl->SendSelectionToClipboard( false ); // Text not modified
3318 mImpl->mEventData->mUpdateCursorPosition = true;
3320 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
3323 case Toolkit::TextSelectionPopup::PASTE:
3325 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
3328 case Toolkit::TextSelectionPopup::SELECT:
3330 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
3332 if( mImpl->mEventData->mSelectionEnabled )
3334 // Creates a SELECT event.
3335 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
3339 case Toolkit::TextSelectionPopup::SELECT_ALL:
3341 // Creates a SELECT_ALL event
3342 SelectEvent( 0.f, 0.f, true );
3345 case Toolkit::TextSelectionPopup::CLIPBOARD:
3347 mImpl->ShowClipboard();
3350 case Toolkit::TextSelectionPopup::NONE:
3358 void Controller::DisplayTimeExpired()
3360 mImpl->mEventData->mUpdateCursorPosition = true;
3361 // Apply modifications to the model
3362 mImpl->mOperationsPending = ALL_OPERATIONS;
3364 mImpl->RequestRelayout();
3367 // private : Update.
3369 void Controller::InsertText( const std::string& text, Controller::InsertType type )
3371 bool removedPrevious = false;
3372 bool removedSelected = false;
3373 bool maxLengthReached = false;
3375 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
3377 if( NULL == mImpl->mEventData )
3382 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
3383 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
3384 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3386 // TODO: At the moment the underline runs are only for pre-edit.
3387 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
3389 // Remove the previous InputMethodContext pre-edit.
3390 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
3392 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
3393 mImpl->mEventData->mPreEditLength,
3394 DONT_UPDATE_INPUT_STYLE );
3396 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
3397 mImpl->mEventData->mPreEditLength = 0u;
3401 // Remove the previous Selection.
3402 removedSelected = RemoveSelectedText();
3406 Vector<Character> utf32Characters;
3407 Length characterCount = 0u;
3411 // Convert text into UTF-32
3412 utf32Characters.Resize( text.size() );
3414 // This is a bit horrible but std::string returns a (signed) char*
3415 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
3417 // Transform a text array encoded in utf8 into an array encoded in utf32.
3418 // It returns the actual number of characters.
3419 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
3420 utf32Characters.Resize( characterCount );
3422 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
3423 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
3426 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
3428 // The placeholder text is no longer needed
3429 if( mImpl->IsShowingPlaceholderText() )
3434 mImpl->ChangeState( EventData::EDITING );
3436 // Handle the InputMethodContext (predicitive text) state changes
3437 if( COMMIT == type )
3439 // InputMethodContext is no longer handling key-events
3440 mImpl->ClearPreEditFlag();
3444 if( !mImpl->mEventData->mPreEditFlag )
3446 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
3448 // Record the start of the pre-edit text
3449 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
3452 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
3453 mImpl->mEventData->mPreEditFlag = true;
3455 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3458 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
3460 // Restrict new text to fit within Maximum characters setting.
3461 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
3462 maxLengthReached = ( characterCount > maxSizeOfNewText );
3464 // The cursor position.
3465 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3467 // Update the text's style.
3469 // Updates the text style runs by adding characters.
3470 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
3472 // Get the character index from the cursor index.
3473 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
3475 // Retrieve the text's style for the given index.
3477 mImpl->RetrieveDefaultInputStyle( style );
3478 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
3480 // Whether to add a new text color run.
3481 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor ) && !mImpl->mEventData->mInputStyle.isDefaultColor;
3483 // Whether to add a new font run.
3484 const bool addFontNameRun = ( style.familyName != mImpl->mEventData->mInputStyle.familyName ) && mImpl->mEventData->mInputStyle.isFamilyDefined;
3485 const bool addFontWeightRun = ( style.weight != mImpl->mEventData->mInputStyle.weight ) && mImpl->mEventData->mInputStyle.isWeightDefined;
3486 const bool addFontWidthRun = ( style.width != mImpl->mEventData->mInputStyle.width ) && mImpl->mEventData->mInputStyle.isWidthDefined;
3487 const bool addFontSlantRun = ( style.slant != mImpl->mEventData->mInputStyle.slant ) && mImpl->mEventData->mInputStyle.isSlantDefined;
3488 const bool addFontSizeRun = ( style.size != mImpl->mEventData->mInputStyle.size ) && mImpl->mEventData->mInputStyle.isSizeDefined ;
3493 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
3494 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
3496 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
3497 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
3498 colorRun.characterRun.characterIndex = cursorIndex;
3499 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3502 if( addFontNameRun ||
3508 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
3509 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
3511 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
3513 if( addFontNameRun )
3515 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
3516 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
3517 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
3518 fontDescriptionRun.familyDefined = true;
3520 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
3523 if( addFontWeightRun )
3525 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
3526 fontDescriptionRun.weightDefined = true;
3529 if( addFontWidthRun )
3531 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
3532 fontDescriptionRun.widthDefined = true;
3535 if( addFontSlantRun )
3537 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
3538 fontDescriptionRun.slantDefined = true;
3541 if( addFontSizeRun )
3543 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
3544 fontDescriptionRun.sizeDefined = true;
3547 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
3548 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3551 // Insert at current cursor position.
3552 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
3554 if( cursorIndex < numberOfCharactersInModel )
3556 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3560 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3563 // Mark the first paragraph to be updated.
3564 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3566 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3567 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3568 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
3569 mImpl->mTextUpdateInfo.mClearAll = true;
3573 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3574 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
3577 // Update the cursor index.
3578 cursorIndex += maxSizeOfNewText;
3580 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 );
3583 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
3584 mImpl->IsPlaceholderAvailable() )
3586 // Show place-holder if empty after removing the pre-edit text
3587 ShowPlaceholderText();
3588 mImpl->mEventData->mUpdateCursorPosition = true;
3589 mImpl->ClearPreEditFlag();
3591 else if( removedPrevious ||
3593 ( 0 != utf32Characters.Count() ) )
3595 // Queue an inserted event
3596 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
3598 mImpl->mEventData->mUpdateCursorPosition = true;
3599 if( removedSelected )
3601 mImpl->mEventData->mScrollAfterDelete = true;
3605 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3609 if( maxLengthReached )
3611 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
3613 mImpl->ResetInputMethodContext();
3615 if( NULL != mImpl->mEditableControlInterface )
3617 // Do this last since it provides callbacks into application code
3618 mImpl->mEditableControlInterface->MaxLengthReached();
3623 void Controller::PasteText( const std::string& stringToPaste )
3625 InsertText( stringToPaste, Text::Controller::COMMIT );
3626 mImpl->ChangeState( EventData::EDITING );
3627 mImpl->RequestRelayout();
3629 if( NULL != mImpl->mEditableControlInterface )
3631 // Do this last since it provides callbacks into application code
3632 mImpl->mEditableControlInterface->TextChanged();
3636 bool Controller::RemoveText( int cursorOffset,
3637 int numberOfCharacters,
3638 UpdateInputStyleType type )
3640 bool removed = false;
3642 if( NULL == mImpl->mEventData )
3647 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
3648 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
3650 if( !mImpl->IsShowingPlaceholderText() )
3652 // Delete at current cursor position
3653 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
3654 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3656 CharacterIndex cursorIndex = 0;
3658 // Validate the cursor position & number of characters
3659 if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
3661 cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
3664 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
3666 numberOfCharacters = currentText.Count() - cursorIndex;
3669 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.
3670 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
3672 // Mark the paragraphs to be updated.
3673 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3675 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3676 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3677 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
3678 mImpl->mTextUpdateInfo.mClearAll = true;
3682 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3683 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
3686 // Update the input style and remove the text's style before removing the text.
3688 if( UPDATE_INPUT_STYLE == type )
3690 // Keep a copy of the current input style.
3691 InputStyle currentInputStyle;
3692 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
3694 // Set first the default input style.
3695 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
3697 // Update the input style.
3698 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
3700 // Compare if the input style has changed.
3701 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
3703 if( hasInputStyleChanged )
3705 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
3706 // Queue the input style changed signal.
3707 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
3711 // If the number of current text and the number of characters to be deleted are same,
3712 // it means all texts should be removed and all Preedit variables should be initialized.
3713 if( ( currentText.Count() - numberOfCharacters == 0 ) && ( cursorIndex == 0 ) )
3715 if( mImpl->mEventData )
3717 mImpl->mEventData->mPreEditStartPosition = 0;
3718 mImpl->mEventData->mPreEditLength = 0;
3722 // Updates the text style runs by removing characters. Runs with no characters are removed.
3723 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
3725 // Remove the characters.
3726 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
3727 Vector<Character>::Iterator last = first + numberOfCharacters;
3729 currentText.Erase( first, last );
3731 // Cursor position retreat
3732 oldCursorIndex = cursorIndex;
3734 mImpl->mEventData->mScrollAfterDelete = true;
3736 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
3744 bool Controller::RemoveSelectedText()
3746 bool textRemoved( false );
3748 if( EventData::SELECTING == mImpl->mEventData->mState )
3750 std::string removedString;
3751 mImpl->RetrieveSelection( removedString, true );
3753 if( !removedString.empty() )
3756 mImpl->ChangeState( EventData::EDITING );
3763 // private : Relayout.
3765 bool Controller::DoRelayout( const Size& size,
3766 OperationsMask operationsRequired,
3769 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
3770 bool viewUpdated( false );
3772 // Calculate the operations to be done.
3773 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
3775 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
3776 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
3778 // Get the current layout size.
3779 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3781 if( NO_OPERATION != ( LAYOUT & operations ) )
3783 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
3785 // Some vectors with data needed to layout and reorder may be void
3786 // after the first time the text has been laid out.
3787 // Fill the vectors again.
3789 // Calculate the number of glyphs to layout.
3790 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
3791 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
3792 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
3793 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
3795 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
3796 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
3798 // Make sure the index is not out of bound
3799 if ( charactersToGlyph.Count() != glyphsPerCharacter.Count() ||
3800 requestedNumberOfCharacters > charactersToGlyph.Count() ||
3801 ( lastIndex > charactersToGlyph.Count() && charactersToGlyph.Count() > 0u ) )
3803 std::string currentText;
3804 GetText( currentText );
3806 DALI_LOG_ERROR( "Controller::DoRelayout: Attempting to access invalid buffer\n" );
3807 DALI_LOG_ERROR( "Current text is: %s\n", currentText.c_str() );
3808 DALI_LOG_ERROR( "startIndex: %u, lastIndex: %u, requestedNumberOfCharacters: %u, charactersToGlyph.Count = %lu, glyphsPerCharacter.Count = %lu\n", startIndex, lastIndex, requestedNumberOfCharacters, charactersToGlyph.Count(), glyphsPerCharacter.Count());
3813 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
3814 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
3816 if( 0u == totalNumberOfGlyphs )
3818 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3820 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
3823 // Nothing else to do if there is no glyphs.
3824 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
3828 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
3830 // Set the layout parameters.
3831 Layout::Parameters layoutParameters( size,
3834 // Resize the vector of positions to have the same size than the vector of glyphs.
3835 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
3836 glyphPositions.Resize( totalNumberOfGlyphs );
3838 // Whether the last character is a new paragraph character.
3839 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
3840 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
3842 // The initial glyph and the number of glyphs to layout.
3843 layoutParameters.startGlyphIndex = startGlyphIndex;
3844 layoutParameters.numberOfGlyphs = numberOfGlyphs;
3845 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
3846 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
3848 // Update the ellipsis
3849 bool elideTextEnabled = mImpl->mModel->mElideEnabled;
3851 if( NULL != mImpl->mEventData )
3853 if( mImpl->mEventData->mPlaceholderEllipsisFlag && mImpl->IsShowingPlaceholderText() )
3855 elideTextEnabled = mImpl->mEventData->mIsPlaceholderElideEnabled;
3857 else if( EventData::INACTIVE != mImpl->mEventData->mState )
3859 // Disable ellipsis when editing
3860 elideTextEnabled = false;
3863 // Reset the scroll position in inactive state
3864 if( elideTextEnabled && ( mImpl->mEventData->mState == EventData::INACTIVE ) )
3866 ResetScrollPosition();
3870 // Update the visual model.
3871 bool isAutoScrollEnabled = mImpl->mIsAutoScrollEnabled;
3873 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
3875 mImpl->mModel->mVisualModel->mLines,
3878 isAutoScrollEnabled );
3879 mImpl->mIsAutoScrollEnabled = isAutoScrollEnabled;
3881 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
3885 layoutSize = newLayoutSize;
3887 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
3889 mImpl->mIsTextDirectionRTL = false;
3892 // Reorder the lines
3893 if( NO_OPERATION != ( REORDER & operations ) )
3895 Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = mImpl->mModel->mLogicalModel->mBidirectionalParagraphInfo;
3896 Vector<BidirectionalLineInfoRun>& bidirectionalLineInfo = mImpl->mModel->mLogicalModel->mBidirectionalLineInfo;
3898 // Check first if there are paragraphs with bidirectional info.
3899 if( 0u != bidirectionalInfo.Count() )
3902 const Length numberOfLines = mImpl->mModel->mVisualModel->mLines.Count();
3904 // Reorder the lines.
3905 bidirectionalLineInfo.Reserve( numberOfLines ); // Reserve because is not known yet how many lines have right to left characters.
3906 ReorderLines( bidirectionalInfo,
3908 requestedNumberOfCharacters,
3909 mImpl->mModel->mVisualModel->mLines,
3910 bidirectionalLineInfo );
3912 // Set the bidirectional info per line into the layout parameters.
3913 layoutParameters.lineBidirectionalInfoRunsBuffer = bidirectionalLineInfo.Begin();
3914 layoutParameters.numberOfBidirectionalInfoRuns = bidirectionalLineInfo.Count();
3916 // Re-layout the text. Reorder those lines with right to left characters.
3917 mImpl->mLayoutEngine.ReLayoutRightToLeftLines( layoutParameters,
3919 requestedNumberOfCharacters,
3922 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && ( numberOfLines > 0 ) )
3924 const LineRun* const firstline = mImpl->mModel->mVisualModel->mLines.Begin();
3927 mImpl->mIsTextDirectionRTL = firstline->direction;
3933 // Sets the layout size.
3934 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3936 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
3941 if( NO_OPERATION != ( ALIGN & operations ) )
3943 // The laid-out lines.
3944 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
3946 CharacterIndex alignStartIndex = startIndex;
3947 Length alignRequestedNumberOfCharacters = requestedNumberOfCharacters;
3949 // the whole text needs to be full aligned.
3950 // If you do not do a full aligned, only the last line of the multiline input is aligned.
3951 if( mImpl->mEventData && mImpl->mEventData->mUpdateAlignment )
3953 alignStartIndex = 0u;
3954 alignRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
3955 mImpl->mEventData->mUpdateAlignment = false;
3958 // Need to align with the control's size as the text may contain lines
3959 // starting either with left to right text or right to left.
3960 mImpl->mLayoutEngine.Align( size,
3962 alignRequestedNumberOfCharacters,
3963 mImpl->mModel->mHorizontalAlignment,
3965 mImpl->mModel->mAlignmentOffset,
3966 mImpl->mLayoutDirection,
3967 mImpl->mModel->mMatchSystemLanguageDirection );
3971 #if defined(DEBUG_ENABLED)
3972 std::string currentText;
3973 GetText( currentText );
3974 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mIsTextDirectionRTL[%s] [%s]\n", this, (mImpl->mIsTextDirectionRTL)?"true":"false", currentText.c_str() );
3976 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
3980 void Controller::CalculateVerticalOffset( const Size& controlSize )
3982 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3984 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
3986 // Get the line height of the default font.
3987 layoutSize.height = mImpl->GetDefaultFontLineHeight();
3990 switch( mImpl->mModel->mVerticalAlignment )
3992 case VerticalAlignment::TOP:
3994 mImpl->mModel->mScrollPosition.y = 0.f;
3997 case VerticalAlignment::CENTER:
3999 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
4002 case VerticalAlignment::BOTTOM:
4004 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
4010 // private : Events.
4012 void Controller::ProcessModifyEvents()
4014 Vector<ModifyEvent>& events = mImpl->mModifyEvents;
4016 if( 0u == events.Count() )
4022 for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
4023 endIt = events.End();
4027 const ModifyEvent& event = *it;
4029 if( ModifyEvent::TEXT_REPLACED == event.type )
4031 // A (single) replace event should come first, otherwise we wasted time processing NOOP events
4032 DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
4034 TextReplacedEvent();
4036 else if( ModifyEvent::TEXT_INSERTED == event.type )
4038 TextInsertedEvent();
4040 else if( ModifyEvent::TEXT_DELETED == event.type )
4042 // Placeholder-text cannot be deleted
4043 if( !mImpl->IsShowingPlaceholderText() )
4050 if( NULL != mImpl->mEventData )
4052 // When the text is being modified, delay cursor blinking
4053 mImpl->mEventData->mDecorator->DelayCursorBlink();
4055 // Update selection position after modifying the text
4056 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
4057 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
4060 // Discard temporary text
4064 void Controller::TextReplacedEvent()
4066 // The natural size needs to be re-calculated.
4067 mImpl->mRecalculateNaturalSize = true;
4069 // The text direction needs to be updated.
4070 mImpl->mUpdateTextDirection = true;
4072 // Apply modifications to the model
4073 mImpl->mOperationsPending = ALL_OPERATIONS;
4076 void Controller::TextInsertedEvent()
4078 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
4080 if( NULL == mImpl->mEventData )
4085 mImpl->mEventData->mCheckScrollAmount = true;
4087 // The natural size needs to be re-calculated.
4088 mImpl->mRecalculateNaturalSize = true;
4090 // The text direction needs to be updated.
4091 mImpl->mUpdateTextDirection = true;
4093 // Apply modifications to the model; TODO - Optimize this
4094 mImpl->mOperationsPending = ALL_OPERATIONS;
4097 void Controller::TextDeletedEvent()
4099 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
4101 if( NULL == mImpl->mEventData )
4106 mImpl->mEventData->mCheckScrollAmount = true;
4108 // The natural size needs to be re-calculated.
4109 mImpl->mRecalculateNaturalSize = true;
4111 // The text direction needs to be updated.
4112 mImpl->mUpdateTextDirection = true;
4114 // Apply modifications to the model; TODO - Optimize this
4115 mImpl->mOperationsPending = ALL_OPERATIONS;
4118 bool Controller::DeleteEvent( int keyCode )
4120 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p KeyCode : %d \n", this, keyCode );
4122 bool removed = false;
4124 if( NULL == mImpl->mEventData )
4129 // InputMethodContext is no longer handling key-events
4130 mImpl->ClearPreEditFlag();
4132 if( EventData::SELECTING == mImpl->mEventData->mState )
4134 removed = RemoveSelectedText();
4136 else if( ( mImpl->mEventData->mPrimaryCursorPosition > 0 ) && ( keyCode == Dali::DALI_KEY_BACKSPACE) )
4138 // Remove the character before the current cursor position
4139 removed = RemoveText( -1,
4141 UPDATE_INPUT_STYLE );
4143 else if( keyCode == Dali::DevelKey::DALI_KEY_DELETE )
4145 // Remove the character after the current cursor position
4146 removed = RemoveText( 0,
4148 UPDATE_INPUT_STYLE );
4153 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
4154 !mImpl->IsPlaceholderAvailable() )
4156 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
4160 ShowPlaceholderText();
4162 mImpl->mEventData->mUpdateCursorPosition = true;
4163 mImpl->mEventData->mScrollAfterDelete = true;
4169 // private : Helpers.
4171 void Controller::ResetText()
4174 mImpl->mModel->mLogicalModel->mText.Clear();
4176 // Reset the embedded images buffer.
4177 mImpl->mModel->mLogicalModel->ClearEmbeddedImages();
4179 // We have cleared everything including the placeholder-text
4180 mImpl->PlaceholderCleared();
4182 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4183 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4184 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
4186 // Clear any previous text.
4187 mImpl->mTextUpdateInfo.mClearAll = true;
4189 // The natural size needs to be re-calculated.
4190 mImpl->mRecalculateNaturalSize = true;
4192 // The text direction needs to be updated.
4193 mImpl->mUpdateTextDirection = true;
4195 // Apply modifications to the model
4196 mImpl->mOperationsPending = ALL_OPERATIONS;
4199 void Controller::ShowPlaceholderText()
4201 if( mImpl->IsPlaceholderAvailable() )
4203 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
4205 if( NULL == mImpl->mEventData )
4210 mImpl->mEventData->mIsShowingPlaceholderText = true;
4212 // Disable handles when showing place-holder text
4213 mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
4214 mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
4215 mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
4217 const char* text( NULL );
4220 // TODO - Switch Placeholder text when changing state
4221 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
4222 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
4224 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
4225 size = mImpl->mEventData->mPlaceholderTextActive.size();
4229 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
4230 size = mImpl->mEventData->mPlaceholderTextInactive.size();
4233 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4234 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4236 // Reset model for showing placeholder.
4237 mImpl->mModel->mLogicalModel->mText.Clear();
4238 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
4240 // Convert text into UTF-32
4241 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
4242 utf32Characters.Resize( size );
4244 // This is a bit horrible but std::string returns a (signed) char*
4245 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
4247 // Transform a text array encoded in utf8 into an array encoded in utf32.
4248 // It returns the actual number of characters.
4249 const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
4250 utf32Characters.Resize( characterCount );
4252 // The characters to be added.
4253 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
4255 // Reset the cursor position
4256 mImpl->mEventData->mPrimaryCursorPosition = 0;
4258 // The natural size needs to be re-calculated.
4259 mImpl->mRecalculateNaturalSize = true;
4261 // The text direction needs to be updated.
4262 mImpl->mUpdateTextDirection = true;
4264 // Apply modifications to the model
4265 mImpl->mOperationsPending = ALL_OPERATIONS;
4267 // Update the rest of the model during size negotiation
4268 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
4272 void Controller::ClearFontData()
4274 if( mImpl->mFontDefaults )
4276 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
4279 // Set flags to update the model.
4280 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4281 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4282 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
4284 mImpl->mTextUpdateInfo.mClearAll = true;
4285 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
4286 mImpl->mRecalculateNaturalSize = true;
4288 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
4294 UPDATE_LAYOUT_SIZE |
4299 void Controller::ClearStyleData()
4301 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
4302 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
4305 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
4307 // Reset the cursor position
4308 if( NULL != mImpl->mEventData )
4310 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
4312 // Update the cursor if it's in editing mode.
4313 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
4315 mImpl->mEventData->mUpdateCursorPosition = true;
4320 void Controller::ResetScrollPosition()
4322 if( NULL != mImpl->mEventData )
4324 // Reset the scroll position.
4325 mImpl->mModel->mScrollPosition = Vector2::ZERO;
4326 mImpl->mEventData->mScrollAfterUpdatePosition = true;
4330 void Controller::SetControlInterface( ControlInterface* controlInterface )
4332 mImpl->mControlInterface = controlInterface;
4335 bool Controller::ShouldClearFocusOnEscape() const
4337 return mImpl->mShouldClearFocusOnEscape;
4340 // private : Private contructors & copy operator.
4342 Controller::Controller()
4345 mImpl = new Controller::Impl( NULL, NULL );
4348 Controller::Controller( ControlInterface* controlInterface )
4350 mImpl = new Controller::Impl( controlInterface, NULL );
4353 Controller::Controller( ControlInterface* controlInterface,
4354 EditableControlInterface* editableControlInterface )
4356 mImpl = new Controller::Impl( controlInterface,
4357 editableControlInterface );
4360 // The copy constructor and operator are left unimplemented.
4362 // protected : Destructor.
4364 Controller::~Controller()
4371 } // namespace Toolkit