2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/text/text-controller.h>
25 #include <dali/public-api/adaptor-framework/key.h>
26 #include <dali/integration-api/debug.h>
27 #include <dali/devel-api/adaptor-framework/clipboard-event-notifier.h>
28 #include <dali/devel-api/text-abstraction/font-client.h>
29 #include <dali/devel-api/adaptor-framework/key-devel.h>
32 #include <dali-toolkit/public-api/controls/text-controls/placeholder-properties.h>
33 #include <dali-toolkit/internal/text/bidirectional-support.h>
34 #include <dali-toolkit/internal/text/character-set-conversion.h>
35 #include <dali-toolkit/internal/text/layouts/layout-parameters.h>
36 #include <dali-toolkit/internal/text/markup-processor.h>
37 #include <dali-toolkit/internal/text/multi-language-support.h>
38 #include <dali-toolkit/internal/text/text-controller-impl.h>
39 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
40 #include <dali-toolkit/internal/text/text-font-style.h>
45 #if defined(DEBUG_ENABLED)
46 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
49 const float MAX_FLOAT = std::numeric_limits<float>::max();
51 const std::string EMPTY_STRING("");
53 const std::string KEY_C_NAME = "c";
54 const std::string KEY_V_NAME = "v";
55 const std::string KEY_X_NAME = "x";
57 const char * const PLACEHOLDER_TEXT = "text";
58 const char * const PLACEHOLDER_TEXT_FOCUSED = "textFocused";
59 const char * const PLACEHOLDER_COLOR = "color";
60 const char * const PLACEHOLDER_FONT_FAMILY = "fontFamily";
61 const char * const PLACEHOLDER_FONT_STYLE = "fontStyle";
62 const char * const PLACEHOLDER_POINT_SIZE = "pointSize";
63 const char * const PLACEHOLDER_PIXEL_SIZE = "pixelSize";
64 const char * const PLACEHOLDER_ELLIPSIS = "ellipsis";
65 const unsigned int MAX_TEXT_LENGTH = 1024u * 32u;
67 float ConvertToEven( float value )
69 int intValue(static_cast<int>( value ));
70 return static_cast<float>( intValue + ( intValue & 1 ) );
73 int ConvertPixelToPint( float pixel )
75 unsigned int horizontalDpi = 0u;
76 unsigned int verticalDpi = 0u;
77 Dali::TextAbstraction::FontClient fontClient = Dali::TextAbstraction::FontClient::Get();
78 fontClient.GetDpi( horizontalDpi, verticalDpi );
80 return ( pixel * 72.f ) / static_cast< float >( horizontalDpi );
96 * @brief Adds a new font description run for the selected text.
98 * The new font parameters are added after the call to this method.
100 * @param[in] eventData The event data pointer.
101 * @param[in] logicalModel The logical model where to add the new font description run.
102 * @param[out] startOfSelectedText Index to the first selected character.
103 * @param[out] lengthOfSelectedText Number of selected characters.
105 FontDescriptionRun& UpdateSelectionFontStyleRun( EventData* eventData,
106 LogicalModelPtr logicalModel,
107 CharacterIndex& startOfSelectedText,
108 Length& lengthOfSelectedText )
110 const bool handlesCrossed = eventData->mLeftSelectionPosition > eventData->mRightSelectionPosition;
112 // Get start and end position of selection
113 startOfSelectedText = handlesCrossed ? eventData->mRightSelectionPosition : eventData->mLeftSelectionPosition;
114 lengthOfSelectedText = ( handlesCrossed ? eventData->mLeftSelectionPosition : eventData->mRightSelectionPosition ) - startOfSelectedText;
117 const VectorBase::SizeType numberOfRuns = logicalModel->mFontDescriptionRuns.Count();
118 logicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
120 FontDescriptionRun& fontDescriptionRun = *( logicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
122 fontDescriptionRun.characterRun.characterIndex = startOfSelectedText;
123 fontDescriptionRun.characterRun.numberOfCharacters = lengthOfSelectedText;
125 // Recalculate the selection highlight as the metrics may have changed.
126 eventData->mUpdateLeftSelectionPosition = true;
127 eventData->mUpdateRightSelectionPosition = true;
128 eventData->mUpdateHighlightBox = true;
130 return fontDescriptionRun;
133 // public : Constructor.
135 ControllerPtr Controller::New()
137 return ControllerPtr( new Controller() );
140 ControllerPtr Controller::New( ControlInterface* controlInterface )
142 return ControllerPtr( new Controller( controlInterface ) );
145 ControllerPtr Controller::New( ControlInterface* controlInterface,
146 EditableControlInterface* editableControlInterface )
148 return ControllerPtr( new Controller( controlInterface,
149 editableControlInterface ) );
152 // public : Configure the text controller.
154 void Controller::EnableTextInput( DecoratorPtr decorator, InputMethodContext& inputMethodContext )
158 delete mImpl->mEventData;
159 mImpl->mEventData = NULL;
161 // Nothing else to do.
165 if( NULL == mImpl->mEventData )
167 mImpl->mEventData = new EventData( decorator, inputMethodContext );
171 void Controller::SetGlyphType( TextAbstraction::GlyphType glyphType )
173 // Metrics for bitmap & vector based glyphs are different
174 mImpl->mMetrics->SetGlyphType( glyphType );
176 // Clear the font-specific data
179 mImpl->RequestRelayout();
182 void Controller::SetMarkupProcessorEnabled( bool enable )
184 if( enable != mImpl->mMarkupProcessorEnabled )
186 //If Text was already set, call the SetText again for enabling or disabling markup
187 mImpl->mMarkupProcessorEnabled = enable;
194 bool Controller::IsMarkupProcessorEnabled() const
196 return mImpl->mMarkupProcessorEnabled;
199 void Controller::SetAutoScrollEnabled( bool enable )
201 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled[%s] SingleBox[%s]-> [%p]\n", (enable)?"true":"false", ( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX)?"true":"false", this );
203 if( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX )
207 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled for SINGLE_LINE_BOX\n" );
208 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
218 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled Disabling autoscroll\n");
219 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
226 mImpl->mIsAutoScrollEnabled = enable;
227 mImpl->RequestRelayout();
231 DALI_LOG_WARNING( "Attempted AutoScrolling on a non SINGLE_LINE_BOX, request ignored\n" );
232 mImpl->mIsAutoScrollEnabled = false;
236 bool Controller::IsAutoScrollEnabled() const
238 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::IsAutoScrollEnabled[%s]\n", mImpl->mIsAutoScrollEnabled?"true":"false" );
240 return mImpl->mIsAutoScrollEnabled;
243 CharacterDirection Controller::GetAutoScrollDirection() const
245 return mImpl->mIsTextDirectionRTL;
248 float Controller::GetAutoScrollLineAlignment() const
252 if( mImpl->mModel->mVisualModel &&
253 ( 0u != mImpl->mModel->mVisualModel->mLines.Count() ) )
255 offset = ( *mImpl->mModel->mVisualModel->mLines.Begin() ).alignmentOffset;
261 void Controller::SetHorizontalScrollEnabled( bool enable )
263 if( ( NULL != mImpl->mEventData ) &&
264 mImpl->mEventData->mDecorator )
266 mImpl->mEventData->mDecorator->SetHorizontalScrollEnabled( enable );
269 bool Controller::IsHorizontalScrollEnabled() const
271 if( ( NULL != mImpl->mEventData ) &&
272 mImpl->mEventData->mDecorator )
274 return mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
280 void Controller::SetVerticalScrollEnabled( bool enable )
282 if( ( NULL != mImpl->mEventData ) &&
283 mImpl->mEventData->mDecorator )
285 if( mImpl->mEventData->mDecorator )
287 mImpl->mEventData->mDecorator->SetVerticalScrollEnabled( enable );
292 bool Controller::IsVerticalScrollEnabled() const
294 if( ( NULL != mImpl->mEventData ) &&
295 mImpl->mEventData->mDecorator )
297 return mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
303 void Controller::SetSmoothHandlePanEnabled( bool enable )
305 if( ( NULL != mImpl->mEventData ) &&
306 mImpl->mEventData->mDecorator )
308 mImpl->mEventData->mDecorator->SetSmoothHandlePanEnabled( enable );
312 bool Controller::IsSmoothHandlePanEnabled() const
314 if( ( NULL != mImpl->mEventData ) &&
315 mImpl->mEventData->mDecorator )
317 return mImpl->mEventData->mDecorator->IsSmoothHandlePanEnabled();
323 void Controller::SetMaximumNumberOfCharacters( Length maxCharacters )
325 mImpl->mMaximumNumberOfCharacters = std::min( maxCharacters, MAX_TEXT_LENGTH );
328 int Controller::GetMaximumNumberOfCharacters()
330 return mImpl->mMaximumNumberOfCharacters;
333 void Controller::SetEnableCursorBlink( bool enable )
335 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "TextInput disabled" );
337 if( NULL != mImpl->mEventData )
339 mImpl->mEventData->mCursorBlinkEnabled = enable;
342 mImpl->mEventData->mDecorator )
344 mImpl->mEventData->mDecorator->StopCursorBlink();
349 bool Controller::GetEnableCursorBlink() const
351 if( NULL != mImpl->mEventData )
353 return mImpl->mEventData->mCursorBlinkEnabled;
359 void Controller::SetMultiLineEnabled( bool enable )
361 const Layout::Engine::Type layout = enable ? Layout::Engine::MULTI_LINE_BOX : Layout::Engine::SINGLE_LINE_BOX;
363 if( layout != mImpl->mLayoutEngine.GetLayout() )
365 // Set the layout type.
366 mImpl->mLayoutEngine.SetLayout( layout );
368 // Set the flags to redo the layout operations
369 const OperationsMask layoutOperations = static_cast<OperationsMask>( LAYOUT |
374 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
375 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | layoutOperations );
377 // Need to recalculate natural size
378 mImpl->mRecalculateNaturalSize = true;
380 mImpl->RequestRelayout();
384 bool Controller::IsMultiLineEnabled() const
386 return Layout::Engine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
389 void Controller::SetHorizontalAlignment( Text::HorizontalAlignment::Type alignment )
391 if( alignment != mImpl->mModel->mHorizontalAlignment )
393 // Set the alignment.
394 mImpl->mModel->mHorizontalAlignment = alignment;
396 // Set the flag to redo the alignment operation.
397 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
399 if( mImpl->mEventData )
401 mImpl->mEventData->mUpdateAlignment = true;
403 // Update the cursor if it's in editing mode
404 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
406 mImpl->ChangeState( EventData::EDITING );
407 mImpl->mEventData->mUpdateCursorPosition = true;
411 mImpl->RequestRelayout();
415 Text::HorizontalAlignment::Type Controller::GetHorizontalAlignment() const
417 return mImpl->mModel->mHorizontalAlignment;
420 void Controller::SetVerticalAlignment( VerticalAlignment::Type alignment )
422 if( alignment != mImpl->mModel->mVerticalAlignment )
424 // Set the alignment.
425 mImpl->mModel->mVerticalAlignment = alignment;
427 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
429 mImpl->RequestRelayout();
433 VerticalAlignment::Type Controller::GetVerticalAlignment() const
435 return mImpl->mModel->mVerticalAlignment;
438 bool Controller::IsIgnoreSpacesAfterText() const
440 return mImpl->mModel->mIgnoreSpacesAfterText;
443 void Controller::SetIgnoreSpacesAfterText( bool ignore )
445 mImpl->mModel->mIgnoreSpacesAfterText = ignore;
448 bool Controller::IsMatchSystemLanguageDirection() const
450 return mImpl->mModel->mMatchSystemLanguageDirection;
453 void Controller::SetMatchSystemLanguageDirection( bool match )
455 mImpl->mModel->mMatchSystemLanguageDirection = match;
458 void Controller::SetLayoutDirection( Dali::LayoutDirection::Type layoutDirection )
460 mImpl->mLayoutDirection = layoutDirection;
463 bool Controller::IsShowingRealText() const
465 return mImpl->IsShowingRealText();
469 void Controller::SetLineWrapMode( Text::LineWrap::Mode lineWrapMode )
471 if( lineWrapMode != mImpl->mModel->mLineWrapMode )
473 // Set the text wrap mode.
474 mImpl->mModel->mLineWrapMode = lineWrapMode;
477 // Update Text layout for applying wrap mode
478 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
483 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
484 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
485 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
488 mImpl->RequestRelayout();
492 Text::LineWrap::Mode Controller::GetLineWrapMode() const
494 return mImpl->mModel->mLineWrapMode;
497 void Controller::SetTextElideEnabled( bool enabled )
499 mImpl->mModel->mElideEnabled = enabled;
502 bool Controller::IsTextElideEnabled() const
504 return mImpl->mModel->mElideEnabled;
507 void Controller::SetTextFitEnabled(bool enabled)
509 mImpl->mTextFitEnabled = enabled;
512 bool Controller::IsTextFitEnabled() const
514 return mImpl->mTextFitEnabled;
517 void Controller::SetTextFitMinSize( float minSize, FontSizeType type )
523 mImpl->mTextFitMinSize = minSize;
528 mImpl->mTextFitMinSize = ConvertPixelToPint( minSize );
534 float Controller::GetTextFitMinSize() const
536 return mImpl->mTextFitMinSize;
539 void Controller::SetTextFitMaxSize( float maxSize, FontSizeType type )
545 mImpl->mTextFitMaxSize = maxSize;
550 mImpl->mTextFitMaxSize = ConvertPixelToPint( maxSize );
556 float Controller::GetTextFitMaxSize() const
558 return mImpl->mTextFitMaxSize;
561 void Controller::SetTextFitStepSize( float step, FontSizeType type )
567 mImpl->mTextFitStepSize = step;
572 mImpl->mTextFitStepSize = ConvertPixelToPint( step );
578 float Controller::GetTextFitStepSize() const
580 return mImpl->mTextFitStepSize;
583 void Controller::SetTextFitContentSize(Vector2 size)
585 mImpl->mTextFitContentSize = size;
588 Vector2 Controller::GetTextFitContentSize() const
590 return mImpl->mTextFitContentSize;
593 void Controller::SetPlaceholderTextElideEnabled( bool enabled )
595 mImpl->mEventData->mIsPlaceholderElideEnabled = enabled;
596 mImpl->mEventData->mPlaceholderEllipsisFlag = true;
598 // Update placeholder if there is no text
599 if( mImpl->IsShowingPlaceholderText() ||
600 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
602 ShowPlaceholderText();
606 bool Controller::IsPlaceholderTextElideEnabled() const
608 return mImpl->mEventData->mIsPlaceholderElideEnabled;
611 void Controller::SetSelectionEnabled( bool enabled )
613 mImpl->mEventData->mSelectionEnabled = enabled;
616 bool Controller::IsSelectionEnabled() const
618 return mImpl->mEventData->mSelectionEnabled;
621 void Controller::SetShiftSelectionEnabled( bool enabled )
623 mImpl->mEventData->mShiftSelectionFlag = enabled;
626 bool Controller::IsShiftSelectionEnabled() const
628 return mImpl->mEventData->mShiftSelectionFlag;
631 void Controller::SetGrabHandleEnabled( bool enabled )
633 mImpl->mEventData->mGrabHandleEnabled = enabled;
636 bool Controller::IsGrabHandleEnabled() const
638 return mImpl->mEventData->mGrabHandleEnabled;
641 void Controller::SetGrabHandlePopupEnabled(bool enabled)
643 mImpl->mEventData->mGrabHandlePopupEnabled = enabled;
646 bool Controller::IsGrabHandlePopupEnabled() const
648 return mImpl->mEventData->mGrabHandlePopupEnabled;
653 void Controller::SetText( const std::string& text )
655 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" );
657 // Reset keyboard as text changed
658 mImpl->ResetInputMethodContext();
660 // Remove the previously set text and style.
666 CharacterIndex lastCursorIndex = 0u;
668 if( NULL != mImpl->mEventData )
670 // If popup shown then hide it by switching to Editing state
671 if( ( EventData::SELECTING == mImpl->mEventData->mState ) ||
672 ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
673 ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) ||
674 ( EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState ) )
676 mImpl->ChangeState( EventData::EDITING );
682 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mTextColor );
684 MarkupProcessData markupProcessData( mImpl->mModel->mLogicalModel->mColorRuns,
685 mImpl->mModel->mLogicalModel->mFontDescriptionRuns,
686 mImpl->mModel->mLogicalModel->mEmbeddedItems );
688 Length textSize = 0u;
689 const uint8_t* utf8 = NULL;
690 if( mImpl->mMarkupProcessorEnabled )
692 ProcessMarkupString( text, markupProcessData );
693 textSize = markupProcessData.markupProcessedText.size();
695 // This is a bit horrible but std::string returns a (signed) char*
696 utf8 = reinterpret_cast<const uint8_t*>( markupProcessData.markupProcessedText.c_str() );
700 textSize = text.size();
702 // This is a bit horrible but std::string returns a (signed) char*
703 utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
706 // Limit the text size. If the text size is too large, crash or deadlock will occur.
707 if( textSize > MAX_TEXT_LENGTH )
709 DALI_LOG_WARNING( "The text size is too large(%d), limit the length to 32,768u\n", textSize );
710 textSize = MAX_TEXT_LENGTH;
713 // Convert text into UTF-32
714 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
715 utf32Characters.Resize( textSize );
717 // Transform a text array encoded in utf8 into an array encoded in utf32.
718 // It returns the actual number of characters.
719 Length characterCount = Utf8ToUtf32( utf8, textSize, utf32Characters.Begin() );
720 utf32Characters.Resize( characterCount );
722 DALI_ASSERT_DEBUG( textSize >= characterCount && "Invalid UTF32 conversion length" );
723 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", this, textSize, mImpl->mModel->mLogicalModel->mText.Count() );
725 // The characters to be added.
726 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
728 // To reset the cursor position
729 lastCursorIndex = characterCount;
731 // Update the rest of the model during size negotiation
732 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
734 // The natural size needs to be re-calculated.
735 mImpl->mRecalculateNaturalSize = true;
737 // The text direction needs to be updated.
738 mImpl->mUpdateTextDirection = true;
740 // Apply modifications to the model
741 mImpl->mOperationsPending = ALL_OPERATIONS;
745 ShowPlaceholderText();
748 // Resets the cursor position.
749 ResetCursorPosition( lastCursorIndex );
751 // Scrolls the text to make the cursor visible.
752 ResetScrollPosition();
754 mImpl->RequestRelayout();
756 if( NULL != mImpl->mEventData )
758 // Cancel previously queued events
759 mImpl->mEventData->mEventQueue.clear();
762 // Do this last since it provides callbacks into application code.
763 if( NULL != mImpl->mEditableControlInterface )
765 mImpl->mEditableControlInterface->TextChanged();
769 void Controller::GetText( std::string& text ) const
771 if( !mImpl->IsShowingPlaceholderText() )
773 // Retrieves the text string.
774 mImpl->GetText( 0u, text );
778 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this );
782 void Controller::SetPlaceholderText( PlaceholderType type, const std::string& text )
784 if( NULL != mImpl->mEventData )
786 if( PLACEHOLDER_TYPE_INACTIVE == type )
788 mImpl->mEventData->mPlaceholderTextInactive = text;
792 mImpl->mEventData->mPlaceholderTextActive = text;
795 // Update placeholder if there is no text
796 if( mImpl->IsShowingPlaceholderText() ||
797 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
799 ShowPlaceholderText();
804 void Controller::GetPlaceholderText( PlaceholderType type, std::string& text ) const
806 if( NULL != mImpl->mEventData )
808 if( PLACEHOLDER_TYPE_INACTIVE == type )
810 text = mImpl->mEventData->mPlaceholderTextInactive;
814 text = mImpl->mEventData->mPlaceholderTextActive;
819 void Controller::UpdateAfterFontChange( const std::string& newDefaultFont )
821 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
823 if( !mImpl->mFontDefaults->familyDefined ) // If user defined font then should not update when system font changes
825 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
826 mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
830 mImpl->RequestRelayout();
834 // public : Default style & Input style
836 void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
838 if( NULL == mImpl->mFontDefaults )
840 mImpl->mFontDefaults = new FontDefaults();
843 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
844 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
845 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
847 // Clear the font-specific data
850 mImpl->RequestRelayout();
853 const std::string& Controller::GetDefaultFontFamily() const
855 if( NULL != mImpl->mFontDefaults )
857 return mImpl->mFontDefaults->mFontDescription.family;
863 void Controller::SetPlaceholderFontFamily( const std::string& placeholderTextFontFamily )
865 if( NULL != mImpl->mEventData )
867 if( NULL == mImpl->mEventData->mPlaceholderFont )
869 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
872 mImpl->mEventData->mPlaceholderFont->mFontDescription.family = placeholderTextFontFamily;
873 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetPlaceholderFontFamily %s\n", placeholderTextFontFamily.c_str());
874 mImpl->mEventData->mPlaceholderFont->familyDefined = !placeholderTextFontFamily.empty();
876 mImpl->RequestRelayout();
880 const std::string& Controller::GetPlaceholderFontFamily() const
882 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
884 return mImpl->mEventData->mPlaceholderFont->mFontDescription.family;
890 void Controller::SetDefaultFontWeight( FontWeight weight )
892 if( NULL == mImpl->mFontDefaults )
894 mImpl->mFontDefaults = new FontDefaults();
897 mImpl->mFontDefaults->mFontDescription.weight = weight;
898 mImpl->mFontDefaults->weightDefined = true;
900 // Clear the font-specific data
903 mImpl->RequestRelayout();
906 bool Controller::IsDefaultFontWeightDefined() const
908 if( NULL != mImpl->mFontDefaults )
910 return mImpl->mFontDefaults->weightDefined;
916 FontWeight Controller::GetDefaultFontWeight() const
918 if( NULL != mImpl->mFontDefaults )
920 return mImpl->mFontDefaults->mFontDescription.weight;
923 return TextAbstraction::FontWeight::NORMAL;
926 void Controller::SetPlaceholderTextFontWeight( FontWeight weight )
928 if( NULL != mImpl->mEventData )
930 if( NULL == mImpl->mEventData->mPlaceholderFont )
932 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
935 mImpl->mEventData->mPlaceholderFont->mFontDescription.weight = weight;
936 mImpl->mEventData->mPlaceholderFont->weightDefined = true;
938 mImpl->RequestRelayout();
942 bool Controller::IsPlaceholderTextFontWeightDefined() const
944 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
946 return mImpl->mEventData->mPlaceholderFont->weightDefined;
951 FontWeight Controller::GetPlaceholderTextFontWeight() const
953 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
955 return mImpl->mEventData->mPlaceholderFont->mFontDescription.weight;
958 return TextAbstraction::FontWeight::NORMAL;
961 void Controller::SetDefaultFontWidth( FontWidth width )
963 if( NULL == mImpl->mFontDefaults )
965 mImpl->mFontDefaults = new FontDefaults();
968 mImpl->mFontDefaults->mFontDescription.width = width;
969 mImpl->mFontDefaults->widthDefined = true;
971 // Clear the font-specific data
974 mImpl->RequestRelayout();
977 bool Controller::IsDefaultFontWidthDefined() const
979 if( NULL != mImpl->mFontDefaults )
981 return mImpl->mFontDefaults->widthDefined;
987 FontWidth Controller::GetDefaultFontWidth() const
989 if( NULL != mImpl->mFontDefaults )
991 return mImpl->mFontDefaults->mFontDescription.width;
994 return TextAbstraction::FontWidth::NORMAL;
997 void Controller::SetPlaceholderTextFontWidth( FontWidth width )
999 if( NULL != mImpl->mEventData )
1001 if( NULL == mImpl->mEventData->mPlaceholderFont )
1003 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
1006 mImpl->mEventData->mPlaceholderFont->mFontDescription.width = width;
1007 mImpl->mEventData->mPlaceholderFont->widthDefined = true;
1009 mImpl->RequestRelayout();
1013 bool Controller::IsPlaceholderTextFontWidthDefined() const
1015 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1017 return mImpl->mEventData->mPlaceholderFont->widthDefined;
1022 FontWidth Controller::GetPlaceholderTextFontWidth() const
1024 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1026 return mImpl->mEventData->mPlaceholderFont->mFontDescription.width;
1029 return TextAbstraction::FontWidth::NORMAL;
1032 void Controller::SetDefaultFontSlant( FontSlant slant )
1034 if( NULL == mImpl->mFontDefaults )
1036 mImpl->mFontDefaults = new FontDefaults();
1039 mImpl->mFontDefaults->mFontDescription.slant = slant;
1040 mImpl->mFontDefaults->slantDefined = true;
1042 // Clear the font-specific data
1045 mImpl->RequestRelayout();
1048 bool Controller::IsDefaultFontSlantDefined() const
1050 if( NULL != mImpl->mFontDefaults )
1052 return mImpl->mFontDefaults->slantDefined;
1057 FontSlant Controller::GetDefaultFontSlant() const
1059 if( NULL != mImpl->mFontDefaults )
1061 return mImpl->mFontDefaults->mFontDescription.slant;
1064 return TextAbstraction::FontSlant::NORMAL;
1067 void Controller::SetPlaceholderTextFontSlant( FontSlant slant )
1069 if( NULL != mImpl->mEventData )
1071 if( NULL == mImpl->mEventData->mPlaceholderFont )
1073 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
1076 mImpl->mEventData->mPlaceholderFont->mFontDescription.slant = slant;
1077 mImpl->mEventData->mPlaceholderFont->slantDefined = true;
1079 mImpl->RequestRelayout();
1083 bool Controller::IsPlaceholderTextFontSlantDefined() const
1085 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1087 return mImpl->mEventData->mPlaceholderFont->slantDefined;
1092 FontSlant Controller::GetPlaceholderTextFontSlant() const
1094 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1096 return mImpl->mEventData->mPlaceholderFont->mFontDescription.slant;
1099 return TextAbstraction::FontSlant::NORMAL;
1102 void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
1104 if( NULL == mImpl->mFontDefaults )
1106 mImpl->mFontDefaults = new FontDefaults();
1113 mImpl->mFontDefaults->mDefaultPointSize = fontSize;
1114 mImpl->mFontDefaults->sizeDefined = true;
1119 // Point size = Pixel size * 72.f / DPI
1120 unsigned int horizontalDpi = 0u;
1121 unsigned int verticalDpi = 0u;
1122 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1123 fontClient.GetDpi( horizontalDpi, verticalDpi );
1125 mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
1126 mImpl->mFontDefaults->sizeDefined = true;
1131 // Clear the font-specific data
1134 mImpl->RequestRelayout();
1137 float Controller::GetDefaultFontSize( FontSizeType type ) const
1140 if( NULL != mImpl->mFontDefaults )
1146 value = mImpl->mFontDefaults->mDefaultPointSize;
1151 // Pixel size = Point size * DPI / 72.f
1152 unsigned int horizontalDpi = 0u;
1153 unsigned int verticalDpi = 0u;
1154 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1155 fontClient.GetDpi( horizontalDpi, verticalDpi );
1157 value = mImpl->mFontDefaults->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1167 void Controller::SetPlaceholderTextFontSize( float fontSize, FontSizeType type )
1169 if( NULL != mImpl->mEventData )
1171 if( NULL == mImpl->mEventData->mPlaceholderFont )
1173 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
1180 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = fontSize;
1181 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1182 mImpl->mEventData->mIsPlaceholderPixelSize = false; // Font size flag
1187 // Point size = Pixel size * 72.f / DPI
1188 unsigned int horizontalDpi = 0u;
1189 unsigned int verticalDpi = 0u;
1190 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1191 fontClient.GetDpi( horizontalDpi, verticalDpi );
1193 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
1194 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1195 mImpl->mEventData->mIsPlaceholderPixelSize = true; // Font size flag
1200 mImpl->RequestRelayout();
1204 float Controller::GetPlaceholderTextFontSize( FontSizeType type ) const
1207 if( NULL != mImpl->mEventData )
1213 if( NULL != mImpl->mEventData->mPlaceholderFont )
1215 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize;
1219 // If the placeholder text font size is not set, then return the default font size.
1220 value = GetDefaultFontSize( POINT_SIZE );
1226 if( NULL != mImpl->mEventData->mPlaceholderFont )
1228 // Pixel size = Point size * DPI / 72.f
1229 unsigned int horizontalDpi = 0u;
1230 unsigned int verticalDpi = 0u;
1231 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1232 fontClient.GetDpi( horizontalDpi, verticalDpi );
1234 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1238 // If the placeholder text font size is not set, then return the default font size.
1239 value = GetDefaultFontSize( PIXEL_SIZE );
1250 void Controller::SetDefaultColor( const Vector4& color )
1252 mImpl->mTextColor = color;
1254 if( !mImpl->IsShowingPlaceholderText() )
1256 mImpl->mModel->mVisualModel->SetTextColor( color );
1258 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
1260 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1262 mImpl->RequestRelayout();
1266 const Vector4& Controller::GetDefaultColor() const
1268 return mImpl->mTextColor;
1271 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
1273 if( NULL != mImpl->mEventData )
1275 mImpl->mEventData->mPlaceholderTextColor = textColor;
1278 if( mImpl->IsShowingPlaceholderText() )
1280 mImpl->mModel->mVisualModel->SetTextColor( textColor );
1281 mImpl->RequestRelayout();
1285 const Vector4& Controller::GetPlaceholderTextColor() const
1287 if( NULL != mImpl->mEventData )
1289 return mImpl->mEventData->mPlaceholderTextColor;
1292 return Color::BLACK;
1295 void Controller::SetShadowOffset( const Vector2& shadowOffset )
1297 mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
1299 mImpl->RequestRelayout();
1302 const Vector2& Controller::GetShadowOffset() const
1304 return mImpl->mModel->mVisualModel->GetShadowOffset();
1307 void Controller::SetShadowColor( const Vector4& shadowColor )
1309 mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
1311 mImpl->RequestRelayout();
1314 const Vector4& Controller::GetShadowColor() const
1316 return mImpl->mModel->mVisualModel->GetShadowColor();
1319 void Controller::SetShadowBlurRadius( const float& shadowBlurRadius )
1321 if ( fabsf( GetShadowBlurRadius() - shadowBlurRadius ) > Math::MACHINE_EPSILON_1 )
1323 mImpl->mModel->mVisualModel->SetShadowBlurRadius( shadowBlurRadius );
1325 mImpl->RequestRelayout();
1329 const float& Controller::GetShadowBlurRadius() const
1331 return mImpl->mModel->mVisualModel->GetShadowBlurRadius();
1334 void Controller::SetUnderlineColor( const Vector4& color )
1336 mImpl->mModel->mVisualModel->SetUnderlineColor( color );
1338 mImpl->RequestRelayout();
1341 const Vector4& Controller::GetUnderlineColor() const
1343 return mImpl->mModel->mVisualModel->GetUnderlineColor();
1346 void Controller::SetUnderlineEnabled( bool enabled )
1348 mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
1350 mImpl->RequestRelayout();
1353 bool Controller::IsUnderlineEnabled() const
1355 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
1358 void Controller::SetUnderlineHeight( float height )
1360 mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
1362 mImpl->RequestRelayout();
1365 float Controller::GetUnderlineHeight() const
1367 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
1370 void Controller::SetOutlineColor( const Vector4& color )
1372 mImpl->mModel->mVisualModel->SetOutlineColor( color );
1374 mImpl->RequestRelayout();
1377 const Vector4& Controller::GetOutlineColor() const
1379 return mImpl->mModel->mVisualModel->GetOutlineColor();
1382 void Controller::SetOutlineWidth( uint16_t width )
1384 mImpl->mModel->mVisualModel->SetOutlineWidth( width );
1386 mImpl->RequestRelayout();
1389 uint16_t Controller::GetOutlineWidth() const
1391 return mImpl->mModel->mVisualModel->GetOutlineWidth();
1394 void Controller::SetBackgroundColor( const Vector4& color )
1396 mImpl->mModel->mVisualModel->SetBackgroundColor( color );
1398 mImpl->RequestRelayout();
1401 const Vector4& Controller::GetBackgroundColor() const
1403 return mImpl->mModel->mVisualModel->GetBackgroundColor();
1406 void Controller::SetBackgroundEnabled( bool enabled )
1408 mImpl->mModel->mVisualModel->SetBackgroundEnabled( enabled );
1410 mImpl->RequestRelayout();
1413 bool Controller::IsBackgroundEnabled() const
1415 return mImpl->mModel->mVisualModel->IsBackgroundEnabled();
1418 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
1420 if( NULL == mImpl->mEmbossDefaults )
1422 mImpl->mEmbossDefaults = new EmbossDefaults();
1425 mImpl->mEmbossDefaults->properties = embossProperties;
1428 const std::string& Controller::GetDefaultEmbossProperties() const
1430 if( NULL != mImpl->mEmbossDefaults )
1432 return mImpl->mEmbossDefaults->properties;
1435 return EMPTY_STRING;
1438 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
1440 if( NULL == mImpl->mOutlineDefaults )
1442 mImpl->mOutlineDefaults = new OutlineDefaults();
1445 mImpl->mOutlineDefaults->properties = outlineProperties;
1448 const std::string& Controller::GetDefaultOutlineProperties() const
1450 if( NULL != mImpl->mOutlineDefaults )
1452 return mImpl->mOutlineDefaults->properties;
1455 return EMPTY_STRING;
1458 bool Controller::SetDefaultLineSpacing( float lineSpacing )
1460 if( std::fabs( lineSpacing - mImpl->mLayoutEngine.GetDefaultLineSpacing() ) > Math::MACHINE_EPSILON_1000 )
1462 mImpl->mLayoutEngine.SetDefaultLineSpacing(lineSpacing);
1463 mImpl->mRecalculateNaturalSize = true;
1469 float Controller::GetDefaultLineSpacing() const
1471 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
1474 void Controller::SetInputColor( const Vector4& color )
1476 if( NULL != mImpl->mEventData )
1478 mImpl->mEventData->mInputStyle.textColor = color;
1479 mImpl->mEventData->mInputStyle.isDefaultColor = false;
1481 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1483 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
1485 // Get start and end position of selection
1486 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
1487 const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
1489 // Add the color run.
1490 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1491 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
1493 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
1494 colorRun.color = color;
1495 colorRun.characterRun.characterIndex = startOfSelectedText;
1496 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1498 // Request to relayout.
1499 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1500 mImpl->RequestRelayout();
1502 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1503 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1504 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1509 const Vector4& Controller::GetInputColor() const
1511 if( NULL != mImpl->mEventData )
1513 return mImpl->mEventData->mInputStyle.textColor;
1516 // Return the default text's color if there is no EventData.
1517 return mImpl->mTextColor;
1521 void Controller::SetInputFontFamily( const std::string& fontFamily )
1523 if( NULL != mImpl->mEventData )
1525 mImpl->mEventData->mInputStyle.familyName = fontFamily;
1526 mImpl->mEventData->mInputStyle.isFamilyDefined = true;
1528 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1530 CharacterIndex startOfSelectedText = 0u;
1531 Length lengthOfSelectedText = 0u;
1532 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1533 mImpl->mModel->mLogicalModel,
1534 startOfSelectedText,
1535 lengthOfSelectedText );
1537 fontDescriptionRun.familyLength = fontFamily.size();
1538 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
1539 memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength );
1540 fontDescriptionRun.familyDefined = true;
1542 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
1544 // Request to relayout.
1545 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1550 UPDATE_LAYOUT_SIZE |
1553 mImpl->mRecalculateNaturalSize = true;
1554 mImpl->RequestRelayout();
1556 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1557 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1558 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1560 // As the font changes, recalculate the handle positions is needed.
1561 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1562 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1563 mImpl->mEventData->mUpdateHighlightBox = true;
1564 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1569 const std::string& Controller::GetInputFontFamily() const
1571 if( NULL != mImpl->mEventData )
1573 return mImpl->mEventData->mInputStyle.familyName;
1576 // Return the default font's family if there is no EventData.
1577 return GetDefaultFontFamily();
1580 void Controller::SetInputFontWeight( FontWeight weight )
1582 if( NULL != mImpl->mEventData )
1584 mImpl->mEventData->mInputStyle.weight = weight;
1585 mImpl->mEventData->mInputStyle.isWeightDefined = true;
1587 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1589 CharacterIndex startOfSelectedText = 0u;
1590 Length lengthOfSelectedText = 0u;
1591 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1592 mImpl->mModel->mLogicalModel,
1593 startOfSelectedText,
1594 lengthOfSelectedText );
1596 fontDescriptionRun.weight = weight;
1597 fontDescriptionRun.weightDefined = true;
1599 // Request to relayout.
1600 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1605 UPDATE_LAYOUT_SIZE |
1608 mImpl->mRecalculateNaturalSize = true;
1609 mImpl->RequestRelayout();
1611 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1612 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1613 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1615 // As the font might change, recalculate the handle positions is needed.
1616 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1617 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1618 mImpl->mEventData->mUpdateHighlightBox = true;
1619 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1624 bool Controller::IsInputFontWeightDefined() const
1626 bool defined = false;
1628 if( NULL != mImpl->mEventData )
1630 defined = mImpl->mEventData->mInputStyle.isWeightDefined;
1636 FontWeight Controller::GetInputFontWeight() const
1638 if( NULL != mImpl->mEventData )
1640 return mImpl->mEventData->mInputStyle.weight;
1643 return GetDefaultFontWeight();
1646 void Controller::SetInputFontWidth( FontWidth width )
1648 if( NULL != mImpl->mEventData )
1650 mImpl->mEventData->mInputStyle.width = width;
1651 mImpl->mEventData->mInputStyle.isWidthDefined = true;
1653 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1655 CharacterIndex startOfSelectedText = 0u;
1656 Length lengthOfSelectedText = 0u;
1657 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1658 mImpl->mModel->mLogicalModel,
1659 startOfSelectedText,
1660 lengthOfSelectedText );
1662 fontDescriptionRun.width = width;
1663 fontDescriptionRun.widthDefined = true;
1665 // Request to relayout.
1666 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1671 UPDATE_LAYOUT_SIZE |
1674 mImpl->mRecalculateNaturalSize = true;
1675 mImpl->RequestRelayout();
1677 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1678 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1679 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1681 // As the font might change, recalculate the handle positions is needed.
1682 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1683 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1684 mImpl->mEventData->mUpdateHighlightBox = true;
1685 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1690 bool Controller::IsInputFontWidthDefined() const
1692 bool defined = false;
1694 if( NULL != mImpl->mEventData )
1696 defined = mImpl->mEventData->mInputStyle.isWidthDefined;
1702 FontWidth Controller::GetInputFontWidth() const
1704 if( NULL != mImpl->mEventData )
1706 return mImpl->mEventData->mInputStyle.width;
1709 return GetDefaultFontWidth();
1712 void Controller::SetInputFontSlant( FontSlant slant )
1714 if( NULL != mImpl->mEventData )
1716 mImpl->mEventData->mInputStyle.slant = slant;
1717 mImpl->mEventData->mInputStyle.isSlantDefined = true;
1719 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1721 CharacterIndex startOfSelectedText = 0u;
1722 Length lengthOfSelectedText = 0u;
1723 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1724 mImpl->mModel->mLogicalModel,
1725 startOfSelectedText,
1726 lengthOfSelectedText );
1728 fontDescriptionRun.slant = slant;
1729 fontDescriptionRun.slantDefined = true;
1731 // Request to relayout.
1732 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1737 UPDATE_LAYOUT_SIZE |
1740 mImpl->mRecalculateNaturalSize = true;
1741 mImpl->RequestRelayout();
1743 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1744 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1745 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1747 // As the font might change, recalculate the handle positions is needed.
1748 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1749 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1750 mImpl->mEventData->mUpdateHighlightBox = true;
1751 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1756 bool Controller::IsInputFontSlantDefined() const
1758 bool defined = false;
1760 if( NULL != mImpl->mEventData )
1762 defined = mImpl->mEventData->mInputStyle.isSlantDefined;
1768 FontSlant Controller::GetInputFontSlant() const
1770 if( NULL != mImpl->mEventData )
1772 return mImpl->mEventData->mInputStyle.slant;
1775 return GetDefaultFontSlant();
1778 void Controller::SetInputFontPointSize( float size )
1780 if( NULL != mImpl->mEventData )
1782 mImpl->mEventData->mInputStyle.size = size;
1783 mImpl->mEventData->mInputStyle.isSizeDefined = true;
1785 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1787 CharacterIndex startOfSelectedText = 0u;
1788 Length lengthOfSelectedText = 0u;
1789 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1790 mImpl->mModel->mLogicalModel,
1791 startOfSelectedText,
1792 lengthOfSelectedText );
1794 fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
1795 fontDescriptionRun.sizeDefined = true;
1797 // Request to relayout.
1798 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1803 UPDATE_LAYOUT_SIZE |
1806 mImpl->mRecalculateNaturalSize = true;
1807 mImpl->RequestRelayout();
1809 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1810 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1811 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1813 // As the font might change, recalculate the handle positions is needed.
1814 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1815 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1816 mImpl->mEventData->mUpdateHighlightBox = true;
1817 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1822 float Controller::GetInputFontPointSize() const
1824 if( NULL != mImpl->mEventData )
1826 return mImpl->mEventData->mInputStyle.size;
1829 // Return the default font's point size if there is no EventData.
1830 return GetDefaultFontSize( Text::Controller::POINT_SIZE );
1833 void Controller::SetInputLineSpacing( float lineSpacing )
1835 if( NULL != mImpl->mEventData )
1837 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1838 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1842 float Controller::GetInputLineSpacing() const
1844 if( NULL != mImpl->mEventData )
1846 return mImpl->mEventData->mInputStyle.lineSpacing;
1852 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1854 if( NULL != mImpl->mEventData )
1856 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1860 const std::string& Controller::GetInputShadowProperties() const
1862 if( NULL != mImpl->mEventData )
1864 return mImpl->mEventData->mInputStyle.shadowProperties;
1867 return EMPTY_STRING;
1870 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1872 if( NULL != mImpl->mEventData )
1874 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1878 const std::string& Controller::GetInputUnderlineProperties() const
1880 if( NULL != mImpl->mEventData )
1882 return mImpl->mEventData->mInputStyle.underlineProperties;
1885 return EMPTY_STRING;
1888 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
1890 if( NULL != mImpl->mEventData )
1892 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1896 const std::string& Controller::GetInputEmbossProperties() const
1898 if( NULL != mImpl->mEventData )
1900 return mImpl->mEventData->mInputStyle.embossProperties;
1903 return GetDefaultEmbossProperties();
1906 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
1908 if( NULL != mImpl->mEventData )
1910 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1914 const std::string& Controller::GetInputOutlineProperties() const
1916 if( NULL != mImpl->mEventData )
1918 return mImpl->mEventData->mInputStyle.outlineProperties;
1921 return GetDefaultOutlineProperties();
1924 void Controller::SetInputModePassword( bool passwordInput )
1926 if( NULL != mImpl->mEventData )
1928 mImpl->mEventData->mPasswordInput = passwordInput;
1932 bool Controller::IsInputModePassword()
1934 if( NULL != mImpl->mEventData )
1936 return mImpl->mEventData->mPasswordInput;
1941 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
1943 if( NULL != mImpl->mEventData )
1945 mImpl->mEventData->mDoubleTapAction = action;
1949 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1951 NoTextTap::Action action = NoTextTap::NO_ACTION;
1953 if( NULL != mImpl->mEventData )
1955 action = mImpl->mEventData->mDoubleTapAction;
1961 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
1963 if( NULL != mImpl->mEventData )
1965 mImpl->mEventData->mLongPressAction = action;
1969 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1971 NoTextTap::Action action = NoTextTap::NO_ACTION;
1973 if( NULL != mImpl->mEventData )
1975 action = mImpl->mEventData->mLongPressAction;
1981 bool Controller::IsUnderlineSetByString()
1983 return mImpl->mUnderlineSetByString;
1986 void Controller::UnderlineSetByString( bool setByString )
1988 mImpl->mUnderlineSetByString = setByString;
1991 bool Controller::IsShadowSetByString()
1993 return mImpl->mShadowSetByString;
1996 void Controller::ShadowSetByString( bool setByString )
1998 mImpl->mShadowSetByString = setByString;
2001 bool Controller::IsOutlineSetByString()
2003 return mImpl->mOutlineSetByString;
2006 void Controller::OutlineSetByString( bool setByString )
2008 mImpl->mOutlineSetByString = setByString;
2011 bool Controller::IsFontStyleSetByString()
2013 return mImpl->mFontStyleSetByString;
2016 void Controller::FontStyleSetByString( bool setByString )
2018 mImpl->mFontStyleSetByString = setByString;
2021 // public : Queries & retrieves.
2023 Layout::Engine& Controller::GetLayoutEngine()
2025 return mImpl->mLayoutEngine;
2028 View& Controller::GetView()
2030 return mImpl->mView;
2033 Vector3 Controller::GetNaturalSize()
2035 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
2036 Vector3 naturalSize;
2038 // Make sure the model is up-to-date before layouting
2039 ProcessModifyEvents();
2041 if( mImpl->mRecalculateNaturalSize )
2043 // Operations that can be done only once until the text changes.
2044 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2051 GET_GLYPH_METRICS );
2053 // Set the update info to relayout the whole text.
2054 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2055 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2057 // Make sure the model is up-to-date before layouting
2058 mImpl->UpdateModel( onlyOnceOperations );
2060 // Layout the text for the new width.
2061 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT | REORDER );
2063 // Store the actual control's size to restore later.
2064 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
2066 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
2067 static_cast<OperationsMask>( onlyOnceOperations |
2069 naturalSize.GetVectorXY() );
2071 // Do not do again the only once operations.
2072 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2074 // Do the size related operations again.
2075 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
2078 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
2080 // Stores the natural size to avoid recalculate it again
2081 // unless the text/style changes.
2082 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
2084 mImpl->mRecalculateNaturalSize = false;
2086 // Clear the update info. This info will be set the next time the text is updated.
2087 mImpl->mTextUpdateInfo.Clear();
2088 mImpl->mTextUpdateInfo.mClearAll = true;
2090 // Restore the actual control's size.
2091 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
2093 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
2097 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
2099 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
2102 naturalSize.x = ConvertToEven( naturalSize.x );
2103 naturalSize.y = ConvertToEven( naturalSize.y );
2108 bool Controller::CheckForTextFit( float pointSize, Size& layoutSize )
2111 mImpl->mFontDefaults->mFitPointSize = pointSize;
2112 mImpl->mFontDefaults->sizeDefined = true;
2115 // Operations that can be done only once until the text changes.
2116 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2123 GET_GLYPH_METRICS );
2125 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2126 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2128 // Make sure the model is up-to-date before layouting
2129 mImpl->UpdateModel( onlyOnceOperations );
2131 DoRelayout( Size( layoutSize.width, MAX_FLOAT ),
2132 static_cast<OperationsMask>( onlyOnceOperations | LAYOUT),
2135 // Clear the update info. This info will be set the next time the text is updated.
2136 mImpl->mTextUpdateInfo.Clear();
2137 mImpl->mTextUpdateInfo.mClearAll = true;
2139 if( textSize.width > layoutSize.width || textSize.height > layoutSize.height )
2146 void Controller::FitPointSizeforLayout( Size layoutSize )
2148 const OperationsMask operations = mImpl->mOperationsPending;
2149 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
2151 bool actualellipsis = mImpl->mModel->mElideEnabled;
2152 float minPointSize = mImpl->mTextFitMinSize;
2153 float maxPointSize = mImpl->mTextFitMaxSize;
2154 float pointInterval = mImpl->mTextFitStepSize;
2156 mImpl->mModel->mElideEnabled = false;
2157 Vector<float> pointSizeArray;
2160 if( pointInterval < 1.f )
2162 mImpl->mTextFitStepSize = pointInterval = 1.0f;
2165 pointSizeArray.Reserve( static_cast< unsigned int >( ceil( ( maxPointSize - minPointSize ) / pointInterval ) ) );
2167 for( float i = minPointSize; i < maxPointSize; i += pointInterval )
2169 pointSizeArray.PushBack( i );
2172 pointSizeArray.PushBack( maxPointSize );
2174 int bestSizeIndex = 0;
2175 int min = bestSizeIndex + 1;
2176 int max = pointSizeArray.Size() - 1;
2179 int destI = ( min + max ) / 2;
2181 if( CheckForTextFit( pointSizeArray[destI], layoutSize ) )
2183 bestSizeIndex = min;
2189 bestSizeIndex = max;
2193 mImpl->mModel->mElideEnabled = actualellipsis;
2194 mImpl->mFontDefaults->mFitPointSize = pointSizeArray[bestSizeIndex];
2195 mImpl->mFontDefaults->sizeDefined = true;
2200 float Controller::GetHeightForWidth( float width )
2202 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
2203 // Make sure the model is up-to-date before layouting
2204 ProcessModifyEvents();
2207 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ||
2208 mImpl->mTextUpdateInfo.mFullRelayoutNeeded ||
2209 mImpl->mTextUpdateInfo.mClearAll )
2211 // Operations that can be done only once until the text changes.
2212 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2219 GET_GLYPH_METRICS );
2221 // Set the update info to relayout the whole text.
2222 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2223 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2225 // Make sure the model is up-to-date before layouting
2226 mImpl->UpdateModel( onlyOnceOperations );
2229 // Layout the text for the new width.
2230 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
2232 // Store the actual control's width.
2233 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
2235 DoRelayout( Size( width, MAX_FLOAT ),
2236 static_cast<OperationsMask>( onlyOnceOperations |
2240 // Do not do again the only once operations.
2241 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2243 // Do the size related operations again.
2244 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
2248 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
2250 // Clear the update info. This info will be set the next time the text is updated.
2251 mImpl->mTextUpdateInfo.Clear();
2252 mImpl->mTextUpdateInfo.mClearAll = true;
2254 // Restore the actual control's width.
2255 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
2257 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
2261 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
2262 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
2265 return layoutSize.height;
2268 int Controller::GetLineCount( float width )
2270 GetHeightForWidth( width );
2271 int numberofLines = mImpl->mModel->GetNumberOfLines();
2272 return numberofLines;
2275 const ModelInterface* const Controller::GetTextModel() const
2277 return mImpl->mModel.Get();
2280 float Controller::GetScrollAmountByUserInput()
2282 float scrollAmount = 0.0f;
2284 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
2286 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
2287 mImpl->mEventData->mCheckScrollAmount = false;
2289 return scrollAmount;
2292 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
2294 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
2297 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
2298 layoutHeight = layout.height;
2299 scrollPosition = mImpl->mModel->mScrollPosition.y;
2300 isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
2304 void Controller::SetHiddenInputOption(const Property::Map& options )
2306 if( NULL == mImpl->mHiddenInput )
2308 mImpl->mHiddenInput = new HiddenText( this );
2310 mImpl->mHiddenInput->SetProperties(options);
2313 void Controller::GetHiddenInputOption(Property::Map& options )
2315 if( NULL != mImpl->mHiddenInput )
2317 mImpl->mHiddenInput->GetProperties(options);
2321 void Controller::SetPlaceholderProperty( const Property::Map& map )
2323 const Property::Map::SizeType count = map.Count();
2325 for( Property::Map::SizeType position = 0; position < count; ++position )
2327 KeyValuePair keyValue = map.GetKeyValue( position );
2328 Property::Key& key = keyValue.first;
2329 Property::Value& value = keyValue.second;
2331 if( key == Toolkit::Text::PlaceHolder::Property::TEXT || key == PLACEHOLDER_TEXT )
2333 std::string text = "";
2335 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
2337 else if( key == Toolkit::Text::PlaceHolder::Property::TEXT_FOCUSED || key == PLACEHOLDER_TEXT_FOCUSED )
2339 std::string text = "";
2341 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
2343 else if( key == Toolkit::Text::PlaceHolder::Property::COLOR || key == PLACEHOLDER_COLOR )
2346 value.Get( textColor );
2347 if( GetPlaceholderTextColor() != textColor )
2349 SetPlaceholderTextColor( textColor );
2352 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_FAMILY || key == PLACEHOLDER_FONT_FAMILY )
2354 std::string fontFamily = "";
2355 value.Get( fontFamily );
2356 SetPlaceholderFontFamily( fontFamily );
2358 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_STYLE || key == PLACEHOLDER_FONT_STYLE )
2360 SetFontStyleProperty( this, value, Text::FontStyle::PLACEHOLDER );
2362 else if( key == Toolkit::Text::PlaceHolder::Property::POINT_SIZE || key == PLACEHOLDER_POINT_SIZE )
2365 value.Get( pointSize );
2366 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
2368 SetPlaceholderTextFontSize( pointSize, Text::Controller::POINT_SIZE );
2371 else if( key == Toolkit::Text::PlaceHolder::Property::PIXEL_SIZE || key == PLACEHOLDER_PIXEL_SIZE )
2374 value.Get( pixelSize );
2375 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
2377 SetPlaceholderTextFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
2380 else if( key == Toolkit::Text::PlaceHolder::Property::ELLIPSIS || key == PLACEHOLDER_ELLIPSIS )
2383 value.Get( ellipsis );
2384 SetPlaceholderTextElideEnabled( ellipsis );
2389 void Controller::GetPlaceholderProperty( Property::Map& map )
2391 if( NULL != mImpl->mEventData )
2393 if( !mImpl->mEventData->mPlaceholderTextActive.empty() )
2395 map[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = mImpl->mEventData->mPlaceholderTextActive;
2397 if( !mImpl->mEventData->mPlaceholderTextInactive.empty() )
2399 map[ Text::PlaceHolder::Property::TEXT ] = mImpl->mEventData->mPlaceholderTextInactive;
2402 map[ Text::PlaceHolder::Property::COLOR ] = mImpl->mEventData->mPlaceholderTextColor;
2403 map[ Text::PlaceHolder::Property::FONT_FAMILY ] = GetPlaceholderFontFamily();
2405 Property::Value fontStyleMapGet;
2406 GetFontStyleProperty( this, fontStyleMapGet, Text::FontStyle::PLACEHOLDER );
2407 map[ Text::PlaceHolder::Property::FONT_STYLE ] = fontStyleMapGet;
2409 // Choose font size : POINT_SIZE or PIXEL_SIZE
2410 if( !mImpl->mEventData->mIsPlaceholderPixelSize )
2412 map[ Text::PlaceHolder::Property::POINT_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE );
2416 map[ Text::PlaceHolder::Property::PIXEL_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE );
2419 if( mImpl->mEventData->mPlaceholderEllipsisFlag )
2421 map[ Text::PlaceHolder::Property::ELLIPSIS ] = IsPlaceholderTextElideEnabled();
2426 Toolkit::DevelText::TextDirection::Type Controller::GetTextDirection()
2428 // Make sure the model is up-to-date before layouting
2429 ProcessModifyEvents();
2431 if ( mImpl->mUpdateTextDirection )
2433 // Operations that can be done only once until the text changes.
2434 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2441 GET_GLYPH_METRICS );
2443 // Set the update info to relayout the whole text.
2444 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2445 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2447 // Make sure the model is up-to-date before layouting
2448 mImpl->UpdateModel( onlyOnceOperations );
2450 Vector3 naturalSize;
2451 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
2452 static_cast<OperationsMask>( onlyOnceOperations |
2453 LAYOUT | REORDER | UPDATE_DIRECTION ),
2454 naturalSize.GetVectorXY() );
2456 // Do not do again the only once operations.
2457 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2459 // Clear the update info. This info will be set the next time the text is updated.
2460 mImpl->mTextUpdateInfo.Clear();
2462 // FullRelayoutNeeded should be true because DoRelayout is MAX_FLOAT, MAX_FLOAT.
2463 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2465 mImpl->mUpdateTextDirection = false;
2468 return mImpl->mIsTextDirectionRTL ? Toolkit::DevelText::TextDirection::RIGHT_TO_LEFT : Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT;
2471 Toolkit::DevelText::VerticalLineAlignment::Type Controller::GetVerticalLineAlignment() const
2473 return mImpl->mModel->GetVerticalLineAlignment();
2476 void Controller::SetVerticalLineAlignment( Toolkit::DevelText::VerticalLineAlignment::Type alignment )
2478 mImpl->mModel->mVerticalLineAlignment = alignment;
2481 // public : Relayout.
2483 Controller::UpdateTextType Controller::Relayout( const Size& size, Dali::LayoutDirection::Type layoutDirection )
2485 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
2487 UpdateTextType updateTextType = NONE_UPDATED;
2489 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
2491 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
2493 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
2494 updateTextType = MODEL_UPDATED;
2497 // Clear the update info. This info will be set the next time the text is updated.
2498 mImpl->mTextUpdateInfo.Clear();
2500 // Not worth to relayout if width or height is equal to zero.
2501 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
2503 return updateTextType;
2506 // Whether a new size has been set.
2507 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
2511 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
2513 if( ( 0 == mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd ) &&
2514 ( 0 == mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) &&
2515 ( ( mImpl->mModel->mVisualModel->mControlSize.width < Math::MACHINE_EPSILON_1000 ) || ( mImpl->mModel->mVisualModel->mControlSize.height < Math::MACHINE_EPSILON_1000 ) ) )
2517 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
2520 // Layout operations that need to be done if the size changes.
2521 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2524 UPDATE_LAYOUT_SIZE |
2526 // Set the update info to relayout the whole text.
2527 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2528 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2530 // Store the size used to layout the text.
2531 mImpl->mModel->mVisualModel->mControlSize = size;
2534 // Whether there are modify events.
2535 if( 0u != mImpl->mModifyEvents.Count() )
2537 // Style operations that need to be done if the text is modified.
2538 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2542 // Set the update info to elide the text.
2543 if( mImpl->mModel->mElideEnabled ||
2544 ( ( NULL != mImpl->mEventData ) && mImpl->mEventData->mIsPlaceholderElideEnabled ) )
2546 // Update Text layout for applying elided
2547 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2550 UPDATE_LAYOUT_SIZE |
2552 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2553 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2556 if( mImpl->mModel->mMatchSystemLanguageDirection && mImpl->mLayoutDirection != layoutDirection )
2558 // Clear the update info. This info will be set the next time the text is updated.
2559 mImpl->mTextUpdateInfo.mClearAll = true;
2560 // Apply modifications to the model
2561 // Shape the text again is needed because characters like '()[]{}' have to be mirrored and the glyphs generated again.
2562 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2569 mImpl->mLayoutDirection = layoutDirection;
2572 // Make sure the model is up-to-date before layouting.
2573 ProcessModifyEvents();
2574 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
2578 updated = DoRelayout( size,
2579 mImpl->mOperationsPending,
2580 layoutSize ) || updated;
2585 updateTextType = MODEL_UPDATED;
2588 // Do not re-do any operation until something changes.
2589 mImpl->mOperationsPending = NO_OPERATION;
2590 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
2592 // Whether the text control is editable
2593 const bool isEditable = NULL != mImpl->mEventData;
2595 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
2597 if( newSize && isEditable )
2599 offset = mImpl->mModel->mScrollPosition;
2602 if( !isEditable || !IsMultiLineEnabled() )
2604 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
2605 CalculateVerticalOffset( size );
2612 // If there is a new size, the scroll position needs to be clamped.
2613 mImpl->ClampHorizontalScroll( layoutSize );
2615 // Update the decorator's positions is needed if there is a new size.
2616 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
2619 // Move the cursor, grab handle etc.
2620 if( mImpl->ProcessInputEvents() )
2622 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
2626 // Clear the update info. This info will be set the next time the text is updated.
2627 mImpl->mTextUpdateInfo.Clear();
2628 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
2630 return updateTextType;
2633 void Controller::RequestRelayout()
2635 mImpl->RequestRelayout();
2638 // public : Input style change signals.
2640 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
2642 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
2645 void Controller::ProcessInputStyleChangedSignals()
2647 if( NULL == mImpl->mEventData )
2653 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
2654 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
2658 const InputStyle::Mask mask = *it;
2660 if( NULL != mImpl->mEditableControlInterface )
2662 // Emit the input style changed signal.
2663 mImpl->mEditableControlInterface->InputStyleChanged( mask );
2667 mImpl->mEventData->mInputStyleChangedQueue.Clear();
2670 // public : Text-input Event Queuing.
2672 void Controller::KeyboardFocusGainEvent()
2674 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
2676 if( NULL != mImpl->mEventData )
2678 if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
2679 ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
2681 mImpl->ChangeState( EventData::EDITING );
2682 mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
2683 mImpl->mEventData->mUpdateInputStyle = true;
2684 mImpl->mEventData->mScrollAfterUpdatePosition = true;
2686 mImpl->NotifyInputMethodContextMultiLineStatus();
2687 if( mImpl->IsShowingPlaceholderText() )
2689 // Show alternative placeholder-text when editing
2690 ShowPlaceholderText();
2693 mImpl->RequestRelayout();
2697 void Controller::KeyboardFocusLostEvent()
2699 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
2701 if( NULL != mImpl->mEventData )
2703 if( EventData::INTERRUPTED != mImpl->mEventData->mState )
2705 mImpl->ChangeState( EventData::INACTIVE );
2707 if( !mImpl->IsShowingRealText() )
2709 // Revert to regular placeholder-text when not editing
2710 ShowPlaceholderText();
2714 mImpl->RequestRelayout();
2717 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
2719 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
2721 bool textChanged = false;
2722 bool relayoutNeeded = false;
2724 if( ( NULL != mImpl->mEventData ) &&
2725 ( keyEvent.state == KeyEvent::Down ) )
2727 int keyCode = keyEvent.keyCode;
2728 const std::string& keyString = keyEvent.keyPressed;
2729 const std::string keyName = keyEvent.keyPressedName;
2731 const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
2733 // Pre-process to separate modifying events from non-modifying input events.
2736 // In some platforms arrive key events with no key code.
2740 else if( Dali::DALI_KEY_ESCAPE == keyCode || Dali::DALI_KEY_BACK == keyCode || Dali::DALI_KEY_SEARCH == keyCode )
2745 else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) ||
2746 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
2747 ( Dali::DALI_KEY_CURSOR_UP == keyCode ) ||
2748 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) )
2750 // If don't have any text, do nothing.
2751 if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
2756 uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition;
2757 uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2758 uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition );
2759 uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines();
2761 // Logic to determine whether this text control will lose focus or not.
2762 if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2763 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2764 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) ||
2765 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) ||
2766 ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) ||
2767 ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) )
2769 // Release the active highlight.
2770 if( mImpl->mEventData->mState == EventData::SELECTING )
2772 mImpl->ChangeState( EventData::EDITING );
2774 // Update selection position.
2775 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2776 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2777 mImpl->mEventData->mUpdateCursorPosition = true;
2778 mImpl->RequestRelayout();
2783 mImpl->mEventData->mCheckScrollAmount = true;
2784 Event event( Event::CURSOR_KEY_EVENT );
2785 event.p1.mInt = keyCode;
2786 event.p2.mBool = keyEvent.IsShiftModifier();
2787 mImpl->mEventData->mEventQueue.push_back( event );
2789 // Will request for relayout.
2790 relayoutNeeded = true;
2792 else if ( Dali::DevelKey::DALI_KEY_CONTROL_LEFT == keyCode || Dali::DevelKey::DALI_KEY_CONTROL_RIGHT == keyCode )
2794 // Left or Right Control key event is received before Ctrl-C/V/X key event is received
2795 // If not handle it here, any selected text will be deleted
2800 else if ( keyEvent.IsCtrlModifier() )
2802 bool consumed = false;
2803 if (keyName == KEY_C_NAME)
2805 // Ctrl-C to copy the selected text
2806 TextPopupButtonTouched( Toolkit::TextSelectionPopup::COPY );
2809 else if (keyName == KEY_V_NAME)
2811 // Ctrl-V to paste the copied text
2812 TextPopupButtonTouched( Toolkit::TextSelectionPopup::PASTE );
2815 else if (keyName == KEY_X_NAME)
2817 // Ctrl-X to cut the selected text
2818 TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
2823 else if( ( Dali::DALI_KEY_BACKSPACE == keyCode ) ||
2824 ( Dali::DevelKey::DALI_KEY_DELETE == keyCode ) )
2826 textChanged = DeleteEvent( keyCode );
2828 // Will request for relayout.
2829 relayoutNeeded = true;
2831 else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
2832 IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
2833 IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
2835 // Power key/Menu/Home key behaviour does not allow edit mode to resume.
2836 mImpl->ChangeState( EventData::INACTIVE );
2838 // Will request for relayout.
2839 relayoutNeeded = true;
2841 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2843 else if( ( Dali::DALI_KEY_SHIFT_LEFT == keyCode ) || ( Dali::DALI_KEY_SHIFT_RIGHT == keyCode ) )
2845 // 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
2846 // and a character is typed after the type of a upper case latin character.
2851 else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
2853 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2859 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
2861 if( !keyString.empty() )
2863 // InputMethodContext is no longer handling key-events
2864 mImpl->ClearPreEditFlag();
2866 InsertText( keyString, COMMIT );
2870 // Will request for relayout.
2871 relayoutNeeded = true;
2876 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
2877 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
2879 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
2880 ( Dali::DALI_KEY_SHIFT_RIGHT != keyCode ) &&
2881 ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
2882 ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
2884 // Should not change the state if the key is the shift send by the InputMethodContext.
2885 // Otherwise, when the state is SELECTING the text controller can't send the right
2886 // surrounding info to the InputMethodContext.
2887 mImpl->ChangeState( EventData::EDITING );
2889 // Will request for relayout.
2890 relayoutNeeded = true;
2893 if( relayoutNeeded )
2895 mImpl->RequestRelayout();
2900 ( NULL != mImpl->mEditableControlInterface ) )
2902 // Do this last since it provides callbacks into application code
2903 mImpl->mEditableControlInterface->TextChanged();
2909 void Controller::TapEvent( unsigned int tapCount, float x, float y )
2911 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
2913 if( NULL != mImpl->mEventData )
2915 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
2916 EventData::State state( mImpl->mEventData->mState );
2917 bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
2919 if( mImpl->IsClipboardVisible() )
2921 if( EventData::INACTIVE == state || EventData::EDITING == state)
2923 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2925 relayoutNeeded = true;
2927 else if( 1u == tapCount )
2929 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
2931 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
2934 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
2936 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2937 relayoutNeeded = true;
2941 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
2943 // Hide placeholder text
2947 if( EventData::INACTIVE == state )
2949 mImpl->ChangeState( EventData::EDITING );
2951 else if( !mImpl->IsClipboardEmpty() )
2953 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
2955 relayoutNeeded = true;
2958 else if( 2u == tapCount )
2960 if( mImpl->mEventData->mSelectionEnabled &&
2961 mImpl->IsShowingRealText() )
2963 relayoutNeeded = true;
2964 mImpl->mEventData->mIsLeftHandleSelected = true;
2965 mImpl->mEventData->mIsRightHandleSelected = true;
2969 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
2970 if( relayoutNeeded )
2972 Event event( Event::TAP_EVENT );
2973 event.p1.mUint = tapCount;
2974 event.p2.mFloat = x;
2975 event.p3.mFloat = y;
2976 mImpl->mEventData->mEventQueue.push_back( event );
2978 mImpl->RequestRelayout();
2982 // Reset keyboard as tap event has occurred.
2983 mImpl->ResetInputMethodContext();
2986 void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
2988 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
2990 if( NULL != mImpl->mEventData )
2992 Event event( Event::PAN_EVENT );
2993 event.p1.mInt = state;
2994 event.p2.mFloat = displacement.x;
2995 event.p3.mFloat = displacement.y;
2996 mImpl->mEventData->mEventQueue.push_back( event );
2998 mImpl->RequestRelayout();
3002 void Controller::LongPressEvent( Gesture::State state, float x, float y )
3004 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
3006 if( ( state == Gesture::Started ) &&
3007 ( NULL != mImpl->mEventData ) )
3009 // The 1st long-press on inactive text-field is treated as tap
3010 if( EventData::INACTIVE == mImpl->mEventData->mState )
3012 mImpl->ChangeState( EventData::EDITING );
3014 Event event( Event::TAP_EVENT );
3016 event.p2.mFloat = x;
3017 event.p3.mFloat = y;
3018 mImpl->mEventData->mEventQueue.push_back( event );
3020 mImpl->RequestRelayout();
3022 else if( !mImpl->IsShowingRealText() )
3024 Event event( Event::LONG_PRESS_EVENT );
3025 event.p1.mInt = state;
3026 event.p2.mFloat = x;
3027 event.p3.mFloat = y;
3028 mImpl->mEventData->mEventQueue.push_back( event );
3029 mImpl->RequestRelayout();
3031 else if( !mImpl->IsClipboardVisible() )
3033 // Reset the InputMethodContext to commit the pre-edit before selecting the text.
3034 mImpl->ResetInputMethodContext();
3036 Event event( Event::LONG_PRESS_EVENT );
3037 event.p1.mInt = state;
3038 event.p2.mFloat = x;
3039 event.p3.mFloat = y;
3040 mImpl->mEventData->mEventQueue.push_back( event );
3041 mImpl->RequestRelayout();
3043 mImpl->mEventData->mIsLeftHandleSelected = true;
3044 mImpl->mEventData->mIsRightHandleSelected = true;
3049 void Controller::SelectEvent( float x, float y, bool selectAll )
3051 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
3053 if( NULL != mImpl->mEventData )
3057 Event event( Event::SELECT_ALL );
3058 mImpl->mEventData->mEventQueue.push_back( event );
3062 Event event( Event::SELECT );
3063 event.p2.mFloat = x;
3064 event.p3.mFloat = y;
3065 mImpl->mEventData->mEventQueue.push_back( event );
3068 mImpl->mEventData->mCheckScrollAmount = true;
3069 mImpl->mEventData->mIsLeftHandleSelected = true;
3070 mImpl->mEventData->mIsRightHandleSelected = true;
3071 mImpl->RequestRelayout();
3075 InputMethodContext::CallbackData Controller::OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
3077 // Whether the text needs to be relaid-out.
3078 bool requestRelayout = false;
3080 // Whether to retrieve the text and cursor position to be sent to the InputMethodContext.
3081 bool retrieveText = false;
3082 bool retrieveCursor = false;
3084 switch( inputMethodContextEvent.eventName )
3086 case InputMethodContext::COMMIT:
3088 InsertText( inputMethodContextEvent.predictiveString, Text::Controller::COMMIT );
3089 requestRelayout = true;
3090 retrieveCursor = true;
3093 case InputMethodContext::PRE_EDIT:
3095 InsertText( inputMethodContextEvent.predictiveString, Text::Controller::PRE_EDIT );
3096 requestRelayout = true;
3097 retrieveCursor = true;
3100 case InputMethodContext::DELETE_SURROUNDING:
3102 const bool textDeleted = RemoveText( inputMethodContextEvent.cursorOffset,
3103 inputMethodContextEvent.numberOfChars,
3104 DONT_UPDATE_INPUT_STYLE );
3108 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3109 !mImpl->IsPlaceholderAvailable() )
3111 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3115 ShowPlaceholderText();
3117 mImpl->mEventData->mUpdateCursorPosition = true;
3118 mImpl->mEventData->mScrollAfterDelete = true;
3120 requestRelayout = true;
3124 case InputMethodContext::GET_SURROUNDING:
3126 retrieveText = true;
3127 retrieveCursor = true;
3130 case InputMethodContext::PRIVATE_COMMAND:
3132 // PRIVATECOMMAND event is just for getting the private command message
3133 retrieveText = true;
3134 retrieveCursor = true;
3137 case InputMethodContext::VOID:
3144 if( requestRelayout )
3146 mImpl->mOperationsPending = ALL_OPERATIONS;
3147 mImpl->RequestRelayout();
3151 CharacterIndex cursorPosition = 0u;
3152 Length numberOfWhiteSpaces = 0u;
3154 if( retrieveCursor )
3156 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
3158 cursorPosition = mImpl->GetLogicalCursorPosition();
3160 if( cursorPosition < numberOfWhiteSpaces )
3162 cursorPosition = 0u;
3166 cursorPosition -= numberOfWhiteSpaces;
3172 if( !mImpl->IsShowingPlaceholderText() )
3174 // Retrieves the normal text string.
3175 mImpl->GetText( numberOfWhiteSpaces, text );
3179 // When the current text is Placeholder Text, the surrounding text should be empty string.
3180 // It means DALi should send empty string ("") to IME.
3185 InputMethodContext::CallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
3187 if( requestRelayout &&
3188 ( NULL != mImpl->mEditableControlInterface ) )
3190 // Do this last since it provides callbacks into application code
3191 mImpl->mEditableControlInterface->TextChanged();
3194 return callbackData;
3197 void Controller::PasteClipboardItemEvent()
3199 // Retrieve the clipboard contents first
3200 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
3201 std::string stringToPaste( notifier.GetContent() );
3203 // Commit the current pre-edit text; the contents of the clipboard should be appended
3204 mImpl->ResetInputMethodContext();
3206 // Temporary disable hiding clipboard
3207 mImpl->SetClipboardHideEnable( false );
3210 PasteText( stringToPaste );
3212 mImpl->SetClipboardHideEnable( true );
3215 // protected : Inherit from Text::Decorator::ControllerInterface.
3217 void Controller::GetTargetSize( Vector2& targetSize )
3219 targetSize = mImpl->mModel->mVisualModel->mControlSize;
3222 void Controller::AddDecoration( Actor& actor, bool needsClipping )
3224 if( NULL != mImpl->mEditableControlInterface )
3226 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
3230 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
3232 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
3234 if( NULL != mImpl->mEventData )
3236 switch( handleType )
3240 Event event( Event::GRAB_HANDLE_EVENT );
3241 event.p1.mUint = state;
3242 event.p2.mFloat = x;
3243 event.p3.mFloat = y;
3245 mImpl->mEventData->mEventQueue.push_back( event );
3248 case LEFT_SELECTION_HANDLE:
3250 Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
3251 event.p1.mUint = state;
3252 event.p2.mFloat = x;
3253 event.p3.mFloat = y;
3255 mImpl->mEventData->mEventQueue.push_back( event );
3258 case RIGHT_SELECTION_HANDLE:
3260 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
3261 event.p1.mUint = state;
3262 event.p2.mFloat = x;
3263 event.p3.mFloat = y;
3265 mImpl->mEventData->mEventQueue.push_back( event );
3268 case LEFT_SELECTION_HANDLE_MARKER:
3269 case RIGHT_SELECTION_HANDLE_MARKER:
3271 // Markers do not move the handles.
3274 case HANDLE_TYPE_COUNT:
3276 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
3280 mImpl->RequestRelayout();
3284 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
3286 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
3288 if( NULL == mImpl->mEventData )
3295 case Toolkit::TextSelectionPopup::CUT:
3297 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
3298 mImpl->mOperationsPending = ALL_OPERATIONS;
3300 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3301 !mImpl->IsPlaceholderAvailable() )
3303 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3307 ShowPlaceholderText();
3310 mImpl->mEventData->mUpdateCursorPosition = true;
3311 mImpl->mEventData->mScrollAfterDelete = true;
3313 mImpl->RequestRelayout();
3315 if( NULL != mImpl->mEditableControlInterface )
3317 mImpl->mEditableControlInterface->TextChanged();
3321 case Toolkit::TextSelectionPopup::COPY:
3323 mImpl->SendSelectionToClipboard( false ); // Text not modified
3325 mImpl->mEventData->mUpdateCursorPosition = true;
3327 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
3330 case Toolkit::TextSelectionPopup::PASTE:
3332 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
3335 case Toolkit::TextSelectionPopup::SELECT:
3337 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
3339 if( mImpl->mEventData->mSelectionEnabled )
3341 // Creates a SELECT event.
3342 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
3346 case Toolkit::TextSelectionPopup::SELECT_ALL:
3348 // Creates a SELECT_ALL event
3349 SelectEvent( 0.f, 0.f, true );
3352 case Toolkit::TextSelectionPopup::CLIPBOARD:
3354 mImpl->ShowClipboard();
3357 case Toolkit::TextSelectionPopup::NONE:
3365 void Controller::DisplayTimeExpired()
3367 mImpl->mEventData->mUpdateCursorPosition = true;
3368 // Apply modifications to the model
3369 mImpl->mOperationsPending = ALL_OPERATIONS;
3371 mImpl->RequestRelayout();
3374 // private : Update.
3376 void Controller::InsertText( const std::string& text, Controller::InsertType type )
3378 bool removedPrevious = false;
3379 bool removedSelected = false;
3380 bool maxLengthReached = false;
3382 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
3384 if( NULL == mImpl->mEventData )
3389 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
3390 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
3391 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3393 // TODO: At the moment the underline runs are only for pre-edit.
3394 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
3396 // Remove the previous InputMethodContext pre-edit.
3397 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
3399 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
3400 mImpl->mEventData->mPreEditLength,
3401 DONT_UPDATE_INPUT_STYLE );
3403 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
3404 mImpl->mEventData->mPreEditLength = 0u;
3408 // Remove the previous Selection.
3409 removedSelected = RemoveSelectedText();
3413 Vector<Character> utf32Characters;
3414 Length characterCount = 0u;
3418 // Convert text into UTF-32
3419 utf32Characters.Resize( text.size() );
3421 // This is a bit horrible but std::string returns a (signed) char*
3422 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
3424 // Transform a text array encoded in utf8 into an array encoded in utf32.
3425 // It returns the actual number of characters.
3426 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
3427 utf32Characters.Resize( characterCount );
3429 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
3430 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
3433 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
3435 // The placeholder text is no longer needed
3436 if( mImpl->IsShowingPlaceholderText() )
3441 mImpl->ChangeState( EventData::EDITING );
3443 // Handle the InputMethodContext (predicitive text) state changes
3444 if( COMMIT == type )
3446 // InputMethodContext is no longer handling key-events
3447 mImpl->ClearPreEditFlag();
3451 if( !mImpl->mEventData->mPreEditFlag )
3453 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
3455 // Record the start of the pre-edit text
3456 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
3459 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
3460 mImpl->mEventData->mPreEditFlag = true;
3462 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3465 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
3467 // Restrict new text to fit within Maximum characters setting.
3468 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
3469 maxLengthReached = ( characterCount > maxSizeOfNewText );
3471 // The cursor position.
3472 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3474 // Update the text's style.
3476 // Updates the text style runs by adding characters.
3477 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
3479 // Get the character index from the cursor index.
3480 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
3482 // Retrieve the text's style for the given index.
3484 mImpl->RetrieveDefaultInputStyle( style );
3485 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
3487 // Whether to add a new text color run.
3488 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor ) && !mImpl->mEventData->mInputStyle.isDefaultColor;
3490 // Whether to add a new font run.
3491 const bool addFontNameRun = ( style.familyName != mImpl->mEventData->mInputStyle.familyName ) && mImpl->mEventData->mInputStyle.isFamilyDefined;
3492 const bool addFontWeightRun = ( style.weight != mImpl->mEventData->mInputStyle.weight ) && mImpl->mEventData->mInputStyle.isWeightDefined;
3493 const bool addFontWidthRun = ( style.width != mImpl->mEventData->mInputStyle.width ) && mImpl->mEventData->mInputStyle.isWidthDefined;
3494 const bool addFontSlantRun = ( style.slant != mImpl->mEventData->mInputStyle.slant ) && mImpl->mEventData->mInputStyle.isSlantDefined;
3495 const bool addFontSizeRun = ( style.size != mImpl->mEventData->mInputStyle.size ) && mImpl->mEventData->mInputStyle.isSizeDefined ;
3500 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
3501 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
3503 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
3504 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
3505 colorRun.characterRun.characterIndex = cursorIndex;
3506 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3509 if( addFontNameRun ||
3515 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
3516 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
3518 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
3520 if( addFontNameRun )
3522 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
3523 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
3524 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
3525 fontDescriptionRun.familyDefined = true;
3527 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
3530 if( addFontWeightRun )
3532 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
3533 fontDescriptionRun.weightDefined = true;
3536 if( addFontWidthRun )
3538 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
3539 fontDescriptionRun.widthDefined = true;
3542 if( addFontSlantRun )
3544 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
3545 fontDescriptionRun.slantDefined = true;
3548 if( addFontSizeRun )
3550 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
3551 fontDescriptionRun.sizeDefined = true;
3554 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
3555 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3558 // Insert at current cursor position.
3559 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
3561 if( cursorIndex < numberOfCharactersInModel )
3563 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3567 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3570 // Mark the first paragraph to be updated.
3571 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3573 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3574 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3575 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
3576 mImpl->mTextUpdateInfo.mClearAll = true;
3580 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3581 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
3584 // Update the cursor index.
3585 cursorIndex += maxSizeOfNewText;
3587 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 );
3590 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
3591 mImpl->IsPlaceholderAvailable() )
3593 // Show place-holder if empty after removing the pre-edit text
3594 ShowPlaceholderText();
3595 mImpl->mEventData->mUpdateCursorPosition = true;
3596 mImpl->ClearPreEditFlag();
3598 else if( removedPrevious ||
3600 ( 0 != utf32Characters.Count() ) )
3602 // Queue an inserted event
3603 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
3605 mImpl->mEventData->mUpdateCursorPosition = true;
3606 if( removedSelected )
3608 mImpl->mEventData->mScrollAfterDelete = true;
3612 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3616 if( maxLengthReached )
3618 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
3620 mImpl->ResetInputMethodContext();
3622 if( NULL != mImpl->mEditableControlInterface )
3624 // Do this last since it provides callbacks into application code
3625 mImpl->mEditableControlInterface->MaxLengthReached();
3630 void Controller::PasteText( const std::string& stringToPaste )
3632 InsertText( stringToPaste, Text::Controller::COMMIT );
3633 mImpl->ChangeState( EventData::EDITING );
3634 mImpl->RequestRelayout();
3636 if( NULL != mImpl->mEditableControlInterface )
3638 // Do this last since it provides callbacks into application code
3639 mImpl->mEditableControlInterface->TextChanged();
3643 bool Controller::RemoveText( int cursorOffset,
3644 int numberOfCharacters,
3645 UpdateInputStyleType type )
3647 bool removed = false;
3649 if( NULL == mImpl->mEventData )
3654 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
3655 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
3657 if( !mImpl->IsShowingPlaceholderText() )
3659 // Delete at current cursor position
3660 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
3661 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3663 CharacterIndex cursorIndex = 0;
3665 // Validate the cursor position & number of characters
3666 if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
3668 cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
3671 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
3673 numberOfCharacters = currentText.Count() - cursorIndex;
3676 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.
3677 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
3679 // Mark the paragraphs to be updated.
3680 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3682 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3683 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3684 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
3685 mImpl->mTextUpdateInfo.mClearAll = true;
3689 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3690 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
3693 // Update the input style and remove the text's style before removing the text.
3695 if( UPDATE_INPUT_STYLE == type )
3697 // Keep a copy of the current input style.
3698 InputStyle currentInputStyle;
3699 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
3701 // Set first the default input style.
3702 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
3704 // Update the input style.
3705 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
3707 // Compare if the input style has changed.
3708 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
3710 if( hasInputStyleChanged )
3712 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
3713 // Queue the input style changed signal.
3714 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
3718 // Updates the text style runs by removing characters. Runs with no characters are removed.
3719 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
3721 // Remove the characters.
3722 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
3723 Vector<Character>::Iterator last = first + numberOfCharacters;
3725 currentText.Erase( first, last );
3727 // Cursor position retreat
3728 oldCursorIndex = cursorIndex;
3730 mImpl->mEventData->mScrollAfterDelete = true;
3732 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
3740 bool Controller::RemoveSelectedText()
3742 bool textRemoved( false );
3744 if( EventData::SELECTING == mImpl->mEventData->mState )
3746 std::string removedString;
3747 mImpl->RetrieveSelection( removedString, true );
3749 if( !removedString.empty() )
3752 mImpl->ChangeState( EventData::EDITING );
3759 // private : Relayout.
3761 bool Controller::DoRelayout( const Size& size,
3762 OperationsMask operationsRequired,
3765 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
3766 bool viewUpdated( false );
3768 // Calculate the operations to be done.
3769 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
3771 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
3772 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
3774 // Get the current layout size.
3775 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3777 if( NO_OPERATION != ( LAYOUT & operations ) )
3779 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
3781 // Some vectors with data needed to layout and reorder may be void
3782 // after the first time the text has been laid out.
3783 // Fill the vectors again.
3785 // Calculate the number of glyphs to layout.
3786 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
3787 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
3788 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
3789 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
3791 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
3792 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
3794 // Make sure the index is not out of bound
3795 if ( charactersToGlyph.Count() != glyphsPerCharacter.Count() ||
3796 requestedNumberOfCharacters > charactersToGlyph.Count() ||
3797 ( lastIndex > charactersToGlyph.Count() && charactersToGlyph.Count() > 0u ) )
3799 std::string currentText;
3800 GetText( currentText );
3802 DALI_LOG_ERROR( "Controller::DoRelayout: Attempting to access invalid buffer\n" );
3803 DALI_LOG_ERROR( "Current text is: %s\n", currentText.c_str() );
3804 DALI_LOG_ERROR( "startIndex: %u, lastIndex: %u, requestedNumberOfCharacters: %u, charactersToGlyph.Count = %lu, glyphsPerCharacter.Count = %lu\n", startIndex, lastIndex, requestedNumberOfCharacters, charactersToGlyph.Count(), glyphsPerCharacter.Count());
3809 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
3810 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
3812 if( 0u == totalNumberOfGlyphs )
3814 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3816 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
3819 // Nothing else to do if there is no glyphs.
3820 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
3824 const Vector<LineBreakInfo>& lineBreakInfo = mImpl->mModel->mLogicalModel->mLineBreakInfo;
3825 const Vector<WordBreakInfo>& wordBreakInfo = mImpl->mModel->mLogicalModel->mWordBreakInfo;
3826 const Vector<CharacterDirection>& characterDirection = mImpl->mModel->mLogicalModel->mCharacterDirections;
3827 const Vector<GlyphInfo>& glyphs = mImpl->mModel->mVisualModel->mGlyphs;
3828 const Vector<CharacterIndex>& glyphsToCharactersMap = mImpl->mModel->mVisualModel->mGlyphsToCharacters;
3829 const Vector<Length>& charactersPerGlyph = mImpl->mModel->mVisualModel->mCharactersPerGlyph;
3830 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
3831 const float outlineWidth = static_cast<float>( mImpl->mModel->GetOutlineWidth() );
3833 // Set the layout parameters.
3834 Layout::Parameters layoutParameters( size,
3836 lineBreakInfo.Begin(),
3837 wordBreakInfo.Begin(),
3838 ( 0u != characterDirection.Count() ) ? characterDirection.Begin() : NULL,
3840 glyphsToCharactersMap.Begin(),
3841 charactersPerGlyph.Begin(),
3842 charactersToGlyphBuffer,
3843 glyphsPerCharacterBuffer,
3844 totalNumberOfGlyphs,
3845 mImpl->mModel->mHorizontalAlignment,
3846 mImpl->mModel->mLineWrapMode,
3848 mImpl->mModel->mIgnoreSpacesAfterText,
3849 mImpl->mModel->mMatchSystemLanguageDirection );
3851 // Resize the vector of positions to have the same size than the vector of glyphs.
3852 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
3853 glyphPositions.Resize( totalNumberOfGlyphs );
3855 // Whether the last character is a new paragraph character.
3856 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
3857 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
3859 // The initial glyph and the number of glyphs to layout.
3860 layoutParameters.startGlyphIndex = startGlyphIndex;
3861 layoutParameters.numberOfGlyphs = numberOfGlyphs;
3862 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
3863 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
3865 // Update the ellipsis
3866 bool elideTextEnabled = mImpl->mModel->mElideEnabled;
3868 if( NULL != mImpl->mEventData )
3870 if( mImpl->mEventData->mPlaceholderEllipsisFlag && mImpl->IsShowingPlaceholderText() )
3872 elideTextEnabled = mImpl->mEventData->mIsPlaceholderElideEnabled;
3874 else if( EventData::INACTIVE != mImpl->mEventData->mState )
3876 // Disable ellipsis when editing
3877 elideTextEnabled = false;
3880 // Reset the scroll position in inactive state
3881 if( elideTextEnabled && ( mImpl->mEventData->mState == EventData::INACTIVE ) )
3883 ResetScrollPosition();
3887 // Update the visual model.
3888 bool isAutoScrollEnabled = mImpl->mIsAutoScrollEnabled;
3890 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
3892 mImpl->mModel->mVisualModel->mLines,
3895 isAutoScrollEnabled );
3896 mImpl->mIsAutoScrollEnabled = isAutoScrollEnabled;
3898 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
3902 layoutSize = newLayoutSize;
3904 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
3906 mImpl->mIsTextDirectionRTL = false;
3909 // Reorder the lines
3910 if( NO_OPERATION != ( REORDER & operations ) )
3912 Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = mImpl->mModel->mLogicalModel->mBidirectionalParagraphInfo;
3913 Vector<BidirectionalLineInfoRun>& bidirectionalLineInfo = mImpl->mModel->mLogicalModel->mBidirectionalLineInfo;
3915 // Check first if there are paragraphs with bidirectional info.
3916 if( 0u != bidirectionalInfo.Count() )
3919 const Length numberOfLines = mImpl->mModel->mVisualModel->mLines.Count();
3921 // Reorder the lines.
3922 bidirectionalLineInfo.Reserve( numberOfLines ); // Reserve because is not known yet how many lines have right to left characters.
3923 ReorderLines( bidirectionalInfo,
3925 requestedNumberOfCharacters,
3926 mImpl->mModel->mVisualModel->mLines,
3927 bidirectionalLineInfo );
3929 // Set the bidirectional info per line into the layout parameters.
3930 layoutParameters.lineBidirectionalInfoRunsBuffer = bidirectionalLineInfo.Begin();
3931 layoutParameters.numberOfBidirectionalInfoRuns = bidirectionalLineInfo.Count();
3933 // Re-layout the text. Reorder those lines with right to left characters.
3934 mImpl->mLayoutEngine.ReLayoutRightToLeftLines( layoutParameters,
3936 requestedNumberOfCharacters,
3939 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && ( numberOfLines > 0 ) )
3941 const LineRun* const firstline = mImpl->mModel->mVisualModel->mLines.Begin();
3944 mImpl->mIsTextDirectionRTL = firstline->direction;
3950 // Sets the layout size.
3951 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3953 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
3958 if( NO_OPERATION != ( ALIGN & operations ) )
3960 // The laid-out lines.
3961 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
3963 CharacterIndex alignStartIndex = startIndex;
3964 Length alignRequestedNumberOfCharacters = requestedNumberOfCharacters;
3966 // the whole text needs to be full aligned.
3967 // If you do not do a full aligned, only the last line of the multiline input is aligned.
3968 if( mImpl->mEventData && mImpl->mEventData->mUpdateAlignment )
3970 alignStartIndex = 0u;
3971 alignRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
3972 mImpl->mEventData->mUpdateAlignment = false;
3975 // Need to align with the control's size as the text may contain lines
3976 // starting either with left to right text or right to left.
3977 mImpl->mLayoutEngine.Align( size,
3979 alignRequestedNumberOfCharacters,
3980 mImpl->mModel->mHorizontalAlignment,
3982 mImpl->mModel->mAlignmentOffset,
3983 mImpl->mLayoutDirection,
3984 mImpl->mModel->mMatchSystemLanguageDirection );
3988 #if defined(DEBUG_ENABLED)
3989 std::string currentText;
3990 GetText( currentText );
3991 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mIsTextDirectionRTL[%s] [%s]\n", this, (mImpl->mIsTextDirectionRTL)?"true":"false", currentText.c_str() );
3993 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
3997 void Controller::CalculateVerticalOffset( const Size& controlSize )
3999 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
4001 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
4003 // Get the line height of the default font.
4004 layoutSize.height = mImpl->GetDefaultFontLineHeight();
4007 switch( mImpl->mModel->mVerticalAlignment )
4009 case VerticalAlignment::TOP:
4011 mImpl->mModel->mScrollPosition.y = 0.f;
4014 case VerticalAlignment::CENTER:
4016 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
4019 case VerticalAlignment::BOTTOM:
4021 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
4027 // private : Events.
4029 void Controller::ProcessModifyEvents()
4031 Vector<ModifyEvent>& events = mImpl->mModifyEvents;
4033 if( 0u == events.Count() )
4039 for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
4040 endIt = events.End();
4044 const ModifyEvent& event = *it;
4046 if( ModifyEvent::TEXT_REPLACED == event.type )
4048 // A (single) replace event should come first, otherwise we wasted time processing NOOP events
4049 DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
4051 TextReplacedEvent();
4053 else if( ModifyEvent::TEXT_INSERTED == event.type )
4055 TextInsertedEvent();
4057 else if( ModifyEvent::TEXT_DELETED == event.type )
4059 // Placeholder-text cannot be deleted
4060 if( !mImpl->IsShowingPlaceholderText() )
4067 if( NULL != mImpl->mEventData )
4069 // When the text is being modified, delay cursor blinking
4070 mImpl->mEventData->mDecorator->DelayCursorBlink();
4072 // Update selection position after modifying the text
4073 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
4074 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
4077 // Discard temporary text
4081 void Controller::TextReplacedEvent()
4083 // The natural size needs to be re-calculated.
4084 mImpl->mRecalculateNaturalSize = true;
4086 // The text direction needs to be updated.
4087 mImpl->mUpdateTextDirection = true;
4089 // Apply modifications to the model
4090 mImpl->mOperationsPending = ALL_OPERATIONS;
4093 void Controller::TextInsertedEvent()
4095 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
4097 if( NULL == mImpl->mEventData )
4102 mImpl->mEventData->mCheckScrollAmount = true;
4104 // The natural size needs to be re-calculated.
4105 mImpl->mRecalculateNaturalSize = true;
4107 // The text direction needs to be updated.
4108 mImpl->mUpdateTextDirection = true;
4110 // Apply modifications to the model; TODO - Optimize this
4111 mImpl->mOperationsPending = ALL_OPERATIONS;
4114 void Controller::TextDeletedEvent()
4116 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
4118 if( NULL == mImpl->mEventData )
4123 mImpl->mEventData->mCheckScrollAmount = true;
4125 // The natural size needs to be re-calculated.
4126 mImpl->mRecalculateNaturalSize = true;
4128 // The text direction needs to be updated.
4129 mImpl->mUpdateTextDirection = true;
4131 // Apply modifications to the model; TODO - Optimize this
4132 mImpl->mOperationsPending = ALL_OPERATIONS;
4135 bool Controller::DeleteEvent( int keyCode )
4137 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p KeyCode : %d \n", this, keyCode );
4139 bool removed = false;
4141 if( NULL == mImpl->mEventData )
4146 // InputMethodContext is no longer handling key-events
4147 mImpl->ClearPreEditFlag();
4149 if( EventData::SELECTING == mImpl->mEventData->mState )
4151 removed = RemoveSelectedText();
4153 else if( ( mImpl->mEventData->mPrimaryCursorPosition > 0 ) && ( keyCode == Dali::DALI_KEY_BACKSPACE) )
4155 // Remove the character before the current cursor position
4156 removed = RemoveText( -1,
4158 UPDATE_INPUT_STYLE );
4160 else if( keyCode == Dali::DevelKey::DALI_KEY_DELETE )
4162 // Remove the character after the current cursor position
4163 removed = RemoveText( 0,
4165 UPDATE_INPUT_STYLE );
4170 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
4171 !mImpl->IsPlaceholderAvailable() )
4173 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
4177 ShowPlaceholderText();
4179 mImpl->mEventData->mUpdateCursorPosition = true;
4180 mImpl->mEventData->mScrollAfterDelete = true;
4186 // private : Helpers.
4188 void Controller::ResetText()
4191 mImpl->mModel->mLogicalModel->mText.Clear();
4193 // Reset the embedded images buffer.
4194 mImpl->mModel->mLogicalModel->ClearEmbeddedImages();
4196 // We have cleared everything including the placeholder-text
4197 mImpl->PlaceholderCleared();
4199 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4200 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4201 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
4203 // Clear any previous text.
4204 mImpl->mTextUpdateInfo.mClearAll = true;
4206 // The natural size needs to be re-calculated.
4207 mImpl->mRecalculateNaturalSize = true;
4209 // The text direction needs to be updated.
4210 mImpl->mUpdateTextDirection = true;
4212 // Apply modifications to the model
4213 mImpl->mOperationsPending = ALL_OPERATIONS;
4216 void Controller::ShowPlaceholderText()
4218 if( mImpl->IsPlaceholderAvailable() )
4220 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
4222 if( NULL == mImpl->mEventData )
4227 mImpl->mEventData->mIsShowingPlaceholderText = true;
4229 // Disable handles when showing place-holder text
4230 mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
4231 mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
4232 mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
4234 const char* text( NULL );
4237 // TODO - Switch Placeholder text when changing state
4238 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
4239 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
4241 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
4242 size = mImpl->mEventData->mPlaceholderTextActive.size();
4246 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
4247 size = mImpl->mEventData->mPlaceholderTextInactive.size();
4250 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4251 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4253 // Reset model for showing placeholder.
4254 mImpl->mModel->mLogicalModel->mText.Clear();
4255 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
4257 // Convert text into UTF-32
4258 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
4259 utf32Characters.Resize( size );
4261 // This is a bit horrible but std::string returns a (signed) char*
4262 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
4264 // Transform a text array encoded in utf8 into an array encoded in utf32.
4265 // It returns the actual number of characters.
4266 const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
4267 utf32Characters.Resize( characterCount );
4269 // The characters to be added.
4270 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
4272 // Reset the cursor position
4273 mImpl->mEventData->mPrimaryCursorPosition = 0;
4275 // The natural size needs to be re-calculated.
4276 mImpl->mRecalculateNaturalSize = true;
4278 // The text direction needs to be updated.
4279 mImpl->mUpdateTextDirection = true;
4281 // Apply modifications to the model
4282 mImpl->mOperationsPending = ALL_OPERATIONS;
4284 // Update the rest of the model during size negotiation
4285 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
4289 void Controller::ClearFontData()
4291 if( mImpl->mFontDefaults )
4293 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
4296 // Set flags to update the model.
4297 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4298 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4299 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
4301 mImpl->mTextUpdateInfo.mClearAll = true;
4302 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
4303 mImpl->mRecalculateNaturalSize = true;
4305 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
4311 UPDATE_LAYOUT_SIZE |
4316 void Controller::ClearStyleData()
4318 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
4319 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
4322 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
4324 // Reset the cursor position
4325 if( NULL != mImpl->mEventData )
4327 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
4329 // Update the cursor if it's in editing mode.
4330 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
4332 mImpl->mEventData->mUpdateCursorPosition = true;
4337 void Controller::ResetScrollPosition()
4339 if( NULL != mImpl->mEventData )
4341 // Reset the scroll position.
4342 mImpl->mModel->mScrollPosition = Vector2::ZERO;
4343 mImpl->mEventData->mScrollAfterUpdatePosition = true;
4347 void Controller::SetControlInterface( ControlInterface* controlInterface )
4349 mImpl->mControlInterface = controlInterface;
4352 bool Controller::ShouldClearFocusOnEscape() const
4354 return mImpl->mShouldClearFocusOnEscape;
4357 // private : Private contructors & copy operator.
4359 Controller::Controller()
4362 mImpl = new Controller::Impl( NULL, NULL );
4365 Controller::Controller( ControlInterface* controlInterface )
4367 mImpl = new Controller::Impl( controlInterface, NULL );
4370 Controller::Controller( ControlInterface* controlInterface,
4371 EditableControlInterface* editableControlInterface )
4373 mImpl = new Controller::Impl( controlInterface,
4374 editableControlInterface );
4377 // The copy constructor and operator are left unimplemented.
4379 // protected : Destructor.
4381 Controller::~Controller()
4388 } // namespace Toolkit