2 * Copyright (c) 2020 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";
56 const std::string KEY_A_NAME = "a";
57 const std::string KEY_INSERT_NAME = "Insert";
59 const char * const PLACEHOLDER_TEXT = "text";
60 const char * const PLACEHOLDER_TEXT_FOCUSED = "textFocused";
61 const char * const PLACEHOLDER_COLOR = "color";
62 const char * const PLACEHOLDER_FONT_FAMILY = "fontFamily";
63 const char * const PLACEHOLDER_FONT_STYLE = "fontStyle";
64 const char * const PLACEHOLDER_POINT_SIZE = "pointSize";
65 const char * const PLACEHOLDER_PIXEL_SIZE = "pixelSize";
66 const char * const PLACEHOLDER_ELLIPSIS = "ellipsis";
68 float ConvertToEven( float value )
70 int intValue(static_cast<int>( value ));
71 return static_cast<float>( intValue + ( intValue & 1 ) );
74 int ConvertPixelToPint( float pixel )
76 unsigned int horizontalDpi = 0u;
77 unsigned int verticalDpi = 0u;
78 Dali::TextAbstraction::FontClient fontClient = Dali::TextAbstraction::FontClient::Get();
79 fontClient.GetDpi( horizontalDpi, verticalDpi );
81 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,
147 SelectableControlInterface* selectableControlInterface )
149 return ControllerPtr( new Controller( controlInterface,
150 editableControlInterface,
151 selectableControlInterface ) );
154 // public : Configure the text controller.
156 void Controller::EnableTextInput( DecoratorPtr decorator, InputMethodContext& inputMethodContext )
160 delete mImpl->mEventData;
161 mImpl->mEventData = NULL;
163 // Nothing else to do.
167 if( NULL == mImpl->mEventData )
169 mImpl->mEventData = new EventData( decorator, inputMethodContext );
173 void Controller::SetGlyphType( TextAbstraction::GlyphType glyphType )
175 // Metrics for bitmap & vector based glyphs are different
176 mImpl->mMetrics->SetGlyphType( glyphType );
178 // Clear the font-specific data
181 mImpl->RequestRelayout();
184 void Controller::SetMarkupProcessorEnabled( bool enable )
186 if( enable != mImpl->mMarkupProcessorEnabled )
188 //If Text was already set, call the SetText again for enabling or disabling markup
189 mImpl->mMarkupProcessorEnabled = enable;
196 bool Controller::IsMarkupProcessorEnabled() const
198 return mImpl->mMarkupProcessorEnabled;
201 void Controller::SetAutoScrollEnabled( bool enable )
203 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 );
205 if( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX )
209 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled for SINGLE_LINE_BOX\n" );
210 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
220 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled Disabling autoscroll\n");
221 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
228 mImpl->mIsAutoScrollEnabled = enable;
229 mImpl->RequestRelayout();
233 DALI_LOG_WARNING( "Attempted AutoScrolling on a non SINGLE_LINE_BOX, request ignored\n" );
234 mImpl->mIsAutoScrollEnabled = false;
238 bool Controller::IsAutoScrollEnabled() const
240 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::IsAutoScrollEnabled[%s]\n", mImpl->mIsAutoScrollEnabled?"true":"false" );
242 return mImpl->mIsAutoScrollEnabled;
245 CharacterDirection Controller::GetAutoScrollDirection() const
247 return mImpl->mIsTextDirectionRTL;
250 float Controller::GetAutoScrollLineAlignment() const
254 if( mImpl->mModel->mVisualModel &&
255 ( 0u != mImpl->mModel->mVisualModel->mLines.Count() ) )
257 offset = ( *mImpl->mModel->mVisualModel->mLines.Begin() ).alignmentOffset;
263 void Controller::SetHorizontalScrollEnabled( bool enable )
265 if( ( NULL != mImpl->mEventData ) &&
266 mImpl->mEventData->mDecorator )
268 mImpl->mEventData->mDecorator->SetHorizontalScrollEnabled( enable );
271 bool Controller::IsHorizontalScrollEnabled() const
273 if( ( NULL != mImpl->mEventData ) &&
274 mImpl->mEventData->mDecorator )
276 return mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
282 void Controller::SetVerticalScrollEnabled( bool enable )
284 if( ( NULL != mImpl->mEventData ) &&
285 mImpl->mEventData->mDecorator )
287 if( mImpl->mEventData->mDecorator )
289 mImpl->mEventData->mDecorator->SetVerticalScrollEnabled( enable );
294 bool Controller::IsVerticalScrollEnabled() const
296 if( ( NULL != mImpl->mEventData ) &&
297 mImpl->mEventData->mDecorator )
299 return mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
305 void Controller::SetSmoothHandlePanEnabled( bool enable )
307 if( ( NULL != mImpl->mEventData ) &&
308 mImpl->mEventData->mDecorator )
310 mImpl->mEventData->mDecorator->SetSmoothHandlePanEnabled( enable );
314 bool Controller::IsSmoothHandlePanEnabled() const
316 if( ( NULL != mImpl->mEventData ) &&
317 mImpl->mEventData->mDecorator )
319 return mImpl->mEventData->mDecorator->IsSmoothHandlePanEnabled();
325 void Controller::SetMaximumNumberOfCharacters( Length maxCharacters )
327 mImpl->mMaximumNumberOfCharacters = maxCharacters;
330 int Controller::GetMaximumNumberOfCharacters()
332 return mImpl->mMaximumNumberOfCharacters;
335 void Controller::SetEnableCursorBlink( bool enable )
337 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "TextInput disabled" );
339 if( NULL != mImpl->mEventData )
341 mImpl->mEventData->mCursorBlinkEnabled = enable;
344 mImpl->mEventData->mDecorator )
346 mImpl->mEventData->mDecorator->StopCursorBlink();
351 bool Controller::GetEnableCursorBlink() const
353 if( NULL != mImpl->mEventData )
355 return mImpl->mEventData->mCursorBlinkEnabled;
361 void Controller::SetMultiLineEnabled( bool enable )
363 const Layout::Engine::Type layout = enable ? Layout::Engine::MULTI_LINE_BOX : Layout::Engine::SINGLE_LINE_BOX;
365 if( layout != mImpl->mLayoutEngine.GetLayout() )
367 // Set the layout type.
368 mImpl->mLayoutEngine.SetLayout( layout );
370 // Set the flags to redo the layout operations
371 const OperationsMask layoutOperations = static_cast<OperationsMask>( LAYOUT |
376 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
377 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | layoutOperations );
379 // Need to recalculate natural size
380 mImpl->mRecalculateNaturalSize = true;
382 mImpl->RequestRelayout();
386 bool Controller::IsMultiLineEnabled() const
388 return Layout::Engine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
391 void Controller::SetHorizontalAlignment( Text::HorizontalAlignment::Type alignment )
393 if( alignment != mImpl->mModel->mHorizontalAlignment )
395 // Set the alignment.
396 mImpl->mModel->mHorizontalAlignment = alignment;
398 // Set the flag to redo the alignment operation.
399 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
401 if( mImpl->mEventData )
403 mImpl->mEventData->mUpdateAlignment = true;
405 // Update the cursor if it's in editing mode
406 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
408 mImpl->ChangeState( EventData::EDITING );
409 mImpl->mEventData->mUpdateCursorPosition = true;
413 mImpl->RequestRelayout();
417 Text::HorizontalAlignment::Type Controller::GetHorizontalAlignment() const
419 return mImpl->mModel->mHorizontalAlignment;
422 void Controller::SetVerticalAlignment( VerticalAlignment::Type alignment )
424 if( alignment != mImpl->mModel->mVerticalAlignment )
426 // Set the alignment.
427 mImpl->mModel->mVerticalAlignment = alignment;
429 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
431 mImpl->RequestRelayout();
435 VerticalAlignment::Type Controller::GetVerticalAlignment() const
437 return mImpl->mModel->mVerticalAlignment;
440 bool Controller::IsIgnoreSpacesAfterText() const
442 return mImpl->mModel->mIgnoreSpacesAfterText;
445 void Controller::SetIgnoreSpacesAfterText( bool ignore )
447 mImpl->mModel->mIgnoreSpacesAfterText = ignore;
450 bool Controller::IsMatchSystemLanguageDirection() const
452 return mImpl->mModel->mMatchSystemLanguageDirection;
455 void Controller::SetMatchSystemLanguageDirection( bool match )
457 mImpl->mModel->mMatchSystemLanguageDirection = match;
460 void Controller::SetLayoutDirection( Dali::LayoutDirection::Type layoutDirection )
462 mImpl->mLayoutDirection = layoutDirection;
465 bool Controller::IsShowingRealText() const
467 return mImpl->IsShowingRealText();
471 void Controller::SetLineWrapMode( Text::LineWrap::Mode lineWrapMode )
473 if( lineWrapMode != mImpl->mModel->mLineWrapMode )
475 // Set the text wrap mode.
476 mImpl->mModel->mLineWrapMode = lineWrapMode;
479 // Update Text layout for applying wrap mode
480 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
485 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
486 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
487 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
490 mImpl->RequestRelayout();
494 Text::LineWrap::Mode Controller::GetLineWrapMode() const
496 return mImpl->mModel->mLineWrapMode;
499 void Controller::SetTextElideEnabled( bool enabled )
501 mImpl->mModel->mElideEnabled = enabled;
504 bool Controller::IsTextElideEnabled() const
506 return mImpl->mModel->mElideEnabled;
509 void Controller::SetTextFitEnabled(bool enabled)
511 mImpl->mTextFitEnabled = enabled;
514 bool Controller::IsTextFitEnabled() const
516 return mImpl->mTextFitEnabled;
519 void Controller::SetTextFitMinSize( float minSize, FontSizeType type )
525 mImpl->mTextFitMinSize = minSize;
530 mImpl->mTextFitMinSize = ConvertPixelToPint( minSize );
536 float Controller::GetTextFitMinSize() const
538 return mImpl->mTextFitMinSize;
541 void Controller::SetTextFitMaxSize( float maxSize, FontSizeType type )
547 mImpl->mTextFitMaxSize = maxSize;
552 mImpl->mTextFitMaxSize = ConvertPixelToPint( maxSize );
558 float Controller::GetTextFitMaxSize() const
560 return mImpl->mTextFitMaxSize;
563 void Controller::SetTextFitStepSize( float step, FontSizeType type )
569 mImpl->mTextFitStepSize = step;
574 mImpl->mTextFitStepSize = ConvertPixelToPint( step );
580 float Controller::GetTextFitStepSize() const
582 return mImpl->mTextFitStepSize;
585 void Controller::SetTextFitContentSize(Vector2 size)
587 mImpl->mTextFitContentSize = size;
590 Vector2 Controller::GetTextFitContentSize() const
592 return mImpl->mTextFitContentSize;
595 void Controller::SetPlaceholderTextElideEnabled( bool enabled )
597 mImpl->mEventData->mIsPlaceholderElideEnabled = enabled;
598 mImpl->mEventData->mPlaceholderEllipsisFlag = true;
600 // Update placeholder if there is no text
601 if( mImpl->IsShowingPlaceholderText() ||
602 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
604 ShowPlaceholderText();
608 bool Controller::IsPlaceholderTextElideEnabled() const
610 return mImpl->mEventData->mIsPlaceholderElideEnabled;
613 void Controller::SetSelectionEnabled( bool enabled )
615 mImpl->mEventData->mSelectionEnabled = enabled;
618 bool Controller::IsSelectionEnabled() const
620 return mImpl->mEventData->mSelectionEnabled;
623 void Controller::SetShiftSelectionEnabled( bool enabled )
625 mImpl->mEventData->mShiftSelectionFlag = enabled;
628 bool Controller::IsShiftSelectionEnabled() const
630 return mImpl->mEventData->mShiftSelectionFlag;
633 void Controller::SetGrabHandleEnabled( bool enabled )
635 mImpl->mEventData->mGrabHandleEnabled = enabled;
638 bool Controller::IsGrabHandleEnabled() const
640 return mImpl->mEventData->mGrabHandleEnabled;
643 void Controller::SetGrabHandlePopupEnabled(bool enabled)
645 mImpl->mEventData->mGrabHandlePopupEnabled = enabled;
648 bool Controller::IsGrabHandlePopupEnabled() const
650 return mImpl->mEventData->mGrabHandlePopupEnabled;
655 void Controller::SetText( const std::string& text )
657 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" );
659 // Reset keyboard as text changed
660 mImpl->ResetInputMethodContext();
662 // Remove the previously set text and style.
668 CharacterIndex lastCursorIndex = 0u;
670 if( NULL != mImpl->mEventData )
672 // If popup shown then hide it by switching to Editing state
673 if( ( EventData::SELECTING == mImpl->mEventData->mState ) ||
674 ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
675 ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) ||
676 ( EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState ) )
678 mImpl->ChangeState( EventData::EDITING );
684 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mTextColor );
686 MarkupProcessData markupProcessData( mImpl->mModel->mLogicalModel->mColorRuns,
687 mImpl->mModel->mLogicalModel->mFontDescriptionRuns,
688 mImpl->mModel->mLogicalModel->mEmbeddedItems );
690 Length textSize = 0u;
691 const uint8_t* utf8 = NULL;
692 if( mImpl->mMarkupProcessorEnabled )
694 ProcessMarkupString( text, markupProcessData );
695 textSize = markupProcessData.markupProcessedText.size();
697 // This is a bit horrible but std::string returns a (signed) char*
698 utf8 = reinterpret_cast<const uint8_t*>( markupProcessData.markupProcessedText.c_str() );
702 textSize = text.size();
704 // This is a bit horrible but std::string returns a (signed) char*
705 utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
708 // Convert text into UTF-32
709 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
710 utf32Characters.Resize( textSize );
712 // Transform a text array encoded in utf8 into an array encoded in utf32.
713 // It returns the actual number of characters.
714 Length characterCount = Utf8ToUtf32( utf8, textSize, utf32Characters.Begin() );
715 utf32Characters.Resize( characterCount );
717 DALI_ASSERT_DEBUG( textSize >= characterCount && "Invalid UTF32 conversion length" );
718 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", this, textSize, mImpl->mModel->mLogicalModel->mText.Count() );
720 // The characters to be added.
721 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
723 // To reset the cursor position
724 lastCursorIndex = characterCount;
726 // Update the rest of the model during size negotiation
727 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
729 // The natural size needs to be re-calculated.
730 mImpl->mRecalculateNaturalSize = true;
732 // The text direction needs to be updated.
733 mImpl->mUpdateTextDirection = true;
735 // Apply modifications to the model
736 mImpl->mOperationsPending = ALL_OPERATIONS;
740 ShowPlaceholderText();
743 // Resets the cursor position.
744 ResetCursorPosition( lastCursorIndex );
746 // Scrolls the text to make the cursor visible.
747 ResetScrollPosition();
749 mImpl->RequestRelayout();
751 if( NULL != mImpl->mEventData )
753 // Cancel previously queued events
754 mImpl->mEventData->mEventQueue.clear();
757 // Do this last since it provides callbacks into application code.
758 if( NULL != mImpl->mEditableControlInterface )
760 mImpl->mEditableControlInterface->TextChanged();
764 void Controller::GetText( std::string& text ) const
766 if( !mImpl->IsShowingPlaceholderText() )
768 // Retrieves the text string.
769 mImpl->GetText( 0u, text );
773 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this );
777 void Controller::SetPlaceholderText( PlaceholderType type, const std::string& text )
779 if( NULL != mImpl->mEventData )
781 if( PLACEHOLDER_TYPE_INACTIVE == type )
783 mImpl->mEventData->mPlaceholderTextInactive = text;
787 mImpl->mEventData->mPlaceholderTextActive = text;
790 // Update placeholder if there is no text
791 if( mImpl->IsShowingPlaceholderText() ||
792 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
794 ShowPlaceholderText();
799 void Controller::GetPlaceholderText( PlaceholderType type, std::string& text ) const
801 if( NULL != mImpl->mEventData )
803 if( PLACEHOLDER_TYPE_INACTIVE == type )
805 text = mImpl->mEventData->mPlaceholderTextInactive;
809 text = mImpl->mEventData->mPlaceholderTextActive;
814 void Controller::UpdateAfterFontChange( const std::string& newDefaultFont )
816 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
818 if( !mImpl->mFontDefaults->familyDefined ) // If user defined font then should not update when system font changes
820 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
821 mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
825 mImpl->RequestRelayout();
829 // public : Default style & Input style
831 void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
833 if( NULL == mImpl->mFontDefaults )
835 mImpl->mFontDefaults = new FontDefaults();
838 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
839 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
840 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
842 if( mImpl->mEventData )
844 // Update the cursor position if it's in editing mode
845 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
847 mImpl->mEventData->mDecoratorUpdated = true;
848 mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font family is updated.
852 // Clear the font-specific data
855 mImpl->RequestRelayout();
858 const std::string& Controller::GetDefaultFontFamily() const
860 if( NULL != mImpl->mFontDefaults )
862 return mImpl->mFontDefaults->mFontDescription.family;
868 void Controller::SetPlaceholderFontFamily( const std::string& placeholderTextFontFamily )
870 if( NULL != mImpl->mEventData )
872 if( NULL == mImpl->mEventData->mPlaceholderFont )
874 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
877 mImpl->mEventData->mPlaceholderFont->mFontDescription.family = placeholderTextFontFamily;
878 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetPlaceholderFontFamily %s\n", placeholderTextFontFamily.c_str());
879 mImpl->mEventData->mPlaceholderFont->familyDefined = !placeholderTextFontFamily.empty();
881 mImpl->RequestRelayout();
885 const std::string& Controller::GetPlaceholderFontFamily() const
887 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
889 return mImpl->mEventData->mPlaceholderFont->mFontDescription.family;
895 void Controller::SetDefaultFontWeight( FontWeight weight )
897 if( NULL == mImpl->mFontDefaults )
899 mImpl->mFontDefaults = new FontDefaults();
902 mImpl->mFontDefaults->mFontDescription.weight = weight;
903 mImpl->mFontDefaults->weightDefined = true;
905 if( mImpl->mEventData )
907 // Update the cursor position if it's in editing mode
908 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
910 mImpl->mEventData->mDecoratorUpdated = true;
911 mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font weight is updated.
915 // Clear the font-specific data
918 mImpl->RequestRelayout();
921 bool Controller::IsDefaultFontWeightDefined() const
923 if( NULL != mImpl->mFontDefaults )
925 return mImpl->mFontDefaults->weightDefined;
931 FontWeight Controller::GetDefaultFontWeight() const
933 if( NULL != mImpl->mFontDefaults )
935 return mImpl->mFontDefaults->mFontDescription.weight;
938 return TextAbstraction::FontWeight::NORMAL;
941 void Controller::SetPlaceholderTextFontWeight( FontWeight weight )
943 if( NULL != mImpl->mEventData )
945 if( NULL == mImpl->mEventData->mPlaceholderFont )
947 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
950 mImpl->mEventData->mPlaceholderFont->mFontDescription.weight = weight;
951 mImpl->mEventData->mPlaceholderFont->weightDefined = true;
953 mImpl->RequestRelayout();
957 bool Controller::IsPlaceholderTextFontWeightDefined() const
959 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
961 return mImpl->mEventData->mPlaceholderFont->weightDefined;
966 FontWeight Controller::GetPlaceholderTextFontWeight() const
968 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
970 return mImpl->mEventData->mPlaceholderFont->mFontDescription.weight;
973 return TextAbstraction::FontWeight::NORMAL;
976 void Controller::SetDefaultFontWidth( FontWidth width )
978 if( NULL == mImpl->mFontDefaults )
980 mImpl->mFontDefaults = new FontDefaults();
983 mImpl->mFontDefaults->mFontDescription.width = width;
984 mImpl->mFontDefaults->widthDefined = true;
986 if( mImpl->mEventData )
988 // Update the cursor position if it's in editing mode
989 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
991 mImpl->mEventData->mDecoratorUpdated = true;
992 mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font width is updated.
996 // Clear the font-specific data
999 mImpl->RequestRelayout();
1002 bool Controller::IsDefaultFontWidthDefined() const
1004 if( NULL != mImpl->mFontDefaults )
1006 return mImpl->mFontDefaults->widthDefined;
1012 FontWidth Controller::GetDefaultFontWidth() const
1014 if( NULL != mImpl->mFontDefaults )
1016 return mImpl->mFontDefaults->mFontDescription.width;
1019 return TextAbstraction::FontWidth::NORMAL;
1022 void Controller::SetPlaceholderTextFontWidth( FontWidth width )
1024 if( NULL != mImpl->mEventData )
1026 if( NULL == mImpl->mEventData->mPlaceholderFont )
1028 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
1031 mImpl->mEventData->mPlaceholderFont->mFontDescription.width = width;
1032 mImpl->mEventData->mPlaceholderFont->widthDefined = true;
1034 mImpl->RequestRelayout();
1038 bool Controller::IsPlaceholderTextFontWidthDefined() const
1040 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1042 return mImpl->mEventData->mPlaceholderFont->widthDefined;
1047 FontWidth Controller::GetPlaceholderTextFontWidth() const
1049 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1051 return mImpl->mEventData->mPlaceholderFont->mFontDescription.width;
1054 return TextAbstraction::FontWidth::NORMAL;
1057 void Controller::SetDefaultFontSlant( FontSlant slant )
1059 if( NULL == mImpl->mFontDefaults )
1061 mImpl->mFontDefaults = new FontDefaults();
1064 mImpl->mFontDefaults->mFontDescription.slant = slant;
1065 mImpl->mFontDefaults->slantDefined = true;
1067 if( mImpl->mEventData )
1069 // Update the cursor position if it's in editing mode
1070 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
1072 mImpl->mEventData->mDecoratorUpdated = true;
1073 mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font slant is updated.
1077 // Clear the font-specific data
1080 mImpl->RequestRelayout();
1083 bool Controller::IsDefaultFontSlantDefined() const
1085 if( NULL != mImpl->mFontDefaults )
1087 return mImpl->mFontDefaults->slantDefined;
1092 FontSlant Controller::GetDefaultFontSlant() const
1094 if( NULL != mImpl->mFontDefaults )
1096 return mImpl->mFontDefaults->mFontDescription.slant;
1099 return TextAbstraction::FontSlant::NORMAL;
1102 void Controller::SetPlaceholderTextFontSlant( FontSlant slant )
1104 if( NULL != mImpl->mEventData )
1106 if( NULL == mImpl->mEventData->mPlaceholderFont )
1108 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
1111 mImpl->mEventData->mPlaceholderFont->mFontDescription.slant = slant;
1112 mImpl->mEventData->mPlaceholderFont->slantDefined = true;
1114 mImpl->RequestRelayout();
1118 bool Controller::IsPlaceholderTextFontSlantDefined() const
1120 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1122 return mImpl->mEventData->mPlaceholderFont->slantDefined;
1127 FontSlant Controller::GetPlaceholderTextFontSlant() const
1129 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1131 return mImpl->mEventData->mPlaceholderFont->mFontDescription.slant;
1134 return TextAbstraction::FontSlant::NORMAL;
1137 void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
1139 if( NULL == mImpl->mFontDefaults )
1141 mImpl->mFontDefaults = new FontDefaults();
1148 mImpl->mFontDefaults->mDefaultPointSize = fontSize;
1149 mImpl->mFontDefaults->sizeDefined = true;
1154 // Point size = Pixel size * 72.f / DPI
1155 unsigned int horizontalDpi = 0u;
1156 unsigned int verticalDpi = 0u;
1157 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1158 fontClient.GetDpi( horizontalDpi, verticalDpi );
1160 mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
1161 mImpl->mFontDefaults->sizeDefined = true;
1166 if( mImpl->mEventData )
1168 // Update the cursor position if it's in editing mode
1169 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
1171 mImpl->mEventData->mDecoratorUpdated = true;
1172 mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font size is updated.
1176 // Clear the font-specific data
1179 mImpl->RequestRelayout();
1182 float Controller::GetDefaultFontSize( FontSizeType type ) const
1185 if( NULL != mImpl->mFontDefaults )
1191 value = mImpl->mFontDefaults->mDefaultPointSize;
1196 // Pixel size = Point size * DPI / 72.f
1197 unsigned int horizontalDpi = 0u;
1198 unsigned int verticalDpi = 0u;
1199 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1200 fontClient.GetDpi( horizontalDpi, verticalDpi );
1202 value = mImpl->mFontDefaults->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1212 void Controller::SetPlaceholderTextFontSize( float fontSize, FontSizeType type )
1214 if( NULL != mImpl->mEventData )
1216 if( NULL == mImpl->mEventData->mPlaceholderFont )
1218 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
1225 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = fontSize;
1226 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1227 mImpl->mEventData->mIsPlaceholderPixelSize = false; // Font size flag
1232 // Point size = Pixel size * 72.f / DPI
1233 unsigned int horizontalDpi = 0u;
1234 unsigned int verticalDpi = 0u;
1235 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1236 fontClient.GetDpi( horizontalDpi, verticalDpi );
1238 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
1239 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1240 mImpl->mEventData->mIsPlaceholderPixelSize = true; // Font size flag
1245 mImpl->RequestRelayout();
1249 float Controller::GetPlaceholderTextFontSize( FontSizeType type ) const
1252 if( NULL != mImpl->mEventData )
1258 if( NULL != mImpl->mEventData->mPlaceholderFont )
1260 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize;
1264 // If the placeholder text font size is not set, then return the default font size.
1265 value = GetDefaultFontSize( POINT_SIZE );
1271 if( NULL != mImpl->mEventData->mPlaceholderFont )
1273 // Pixel size = Point size * DPI / 72.f
1274 unsigned int horizontalDpi = 0u;
1275 unsigned int verticalDpi = 0u;
1276 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1277 fontClient.GetDpi( horizontalDpi, verticalDpi );
1279 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1283 // If the placeholder text font size is not set, then return the default font size.
1284 value = GetDefaultFontSize( PIXEL_SIZE );
1295 void Controller::SetDefaultColor( const Vector4& color )
1297 mImpl->mTextColor = color;
1299 if( !mImpl->IsShowingPlaceholderText() )
1301 mImpl->mModel->mVisualModel->SetTextColor( color );
1303 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
1305 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1307 mImpl->RequestRelayout();
1311 const Vector4& Controller::GetDefaultColor() const
1313 return mImpl->mTextColor;
1316 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
1318 if( NULL != mImpl->mEventData )
1320 mImpl->mEventData->mPlaceholderTextColor = textColor;
1323 if( mImpl->IsShowingPlaceholderText() )
1325 mImpl->mModel->mVisualModel->SetTextColor( textColor );
1326 mImpl->RequestRelayout();
1330 const Vector4& Controller::GetPlaceholderTextColor() const
1332 if( NULL != mImpl->mEventData )
1334 return mImpl->mEventData->mPlaceholderTextColor;
1337 return Color::BLACK;
1340 void Controller::SetShadowOffset( const Vector2& shadowOffset )
1342 mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
1344 mImpl->RequestRelayout();
1347 const Vector2& Controller::GetShadowOffset() const
1349 return mImpl->mModel->mVisualModel->GetShadowOffset();
1352 void Controller::SetShadowColor( const Vector4& shadowColor )
1354 mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
1356 mImpl->RequestRelayout();
1359 const Vector4& Controller::GetShadowColor() const
1361 return mImpl->mModel->mVisualModel->GetShadowColor();
1364 void Controller::SetShadowBlurRadius( const float& shadowBlurRadius )
1366 if ( fabsf( GetShadowBlurRadius() - shadowBlurRadius ) > Math::MACHINE_EPSILON_1 )
1368 mImpl->mModel->mVisualModel->SetShadowBlurRadius( shadowBlurRadius );
1370 mImpl->RequestRelayout();
1374 const float& Controller::GetShadowBlurRadius() const
1376 return mImpl->mModel->mVisualModel->GetShadowBlurRadius();
1379 void Controller::SetUnderlineColor( const Vector4& color )
1381 mImpl->mModel->mVisualModel->SetUnderlineColor( color );
1383 mImpl->RequestRelayout();
1386 const Vector4& Controller::GetUnderlineColor() const
1388 return mImpl->mModel->mVisualModel->GetUnderlineColor();
1391 void Controller::SetUnderlineEnabled( bool enabled )
1393 mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
1395 mImpl->RequestRelayout();
1398 bool Controller::IsUnderlineEnabled() const
1400 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
1403 void Controller::SetUnderlineHeight( float height )
1405 mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
1407 mImpl->RequestRelayout();
1410 float Controller::GetUnderlineHeight() const
1412 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
1415 void Controller::SetOutlineColor( const Vector4& color )
1417 mImpl->mModel->mVisualModel->SetOutlineColor( color );
1419 mImpl->RequestRelayout();
1422 const Vector4& Controller::GetOutlineColor() const
1424 return mImpl->mModel->mVisualModel->GetOutlineColor();
1427 void Controller::SetOutlineWidth( uint16_t width )
1429 mImpl->mModel->mVisualModel->SetOutlineWidth( width );
1431 mImpl->RequestRelayout();
1434 uint16_t Controller::GetOutlineWidth() const
1436 return mImpl->mModel->mVisualModel->GetOutlineWidth();
1439 void Controller::SetBackgroundColor( const Vector4& color )
1441 mImpl->mModel->mVisualModel->SetBackgroundColor( color );
1443 mImpl->RequestRelayout();
1446 const Vector4& Controller::GetBackgroundColor() const
1448 return mImpl->mModel->mVisualModel->GetBackgroundColor();
1451 void Controller::SetBackgroundEnabled( bool enabled )
1453 mImpl->mModel->mVisualModel->SetBackgroundEnabled( enabled );
1455 mImpl->RequestRelayout();
1458 bool Controller::IsBackgroundEnabled() const
1460 return mImpl->mModel->mVisualModel->IsBackgroundEnabled();
1463 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
1465 if( NULL == mImpl->mEmbossDefaults )
1467 mImpl->mEmbossDefaults = new EmbossDefaults();
1470 mImpl->mEmbossDefaults->properties = embossProperties;
1473 const std::string& Controller::GetDefaultEmbossProperties() const
1475 if( NULL != mImpl->mEmbossDefaults )
1477 return mImpl->mEmbossDefaults->properties;
1480 return EMPTY_STRING;
1483 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
1485 if( NULL == mImpl->mOutlineDefaults )
1487 mImpl->mOutlineDefaults = new OutlineDefaults();
1490 mImpl->mOutlineDefaults->properties = outlineProperties;
1493 const std::string& Controller::GetDefaultOutlineProperties() const
1495 if( NULL != mImpl->mOutlineDefaults )
1497 return mImpl->mOutlineDefaults->properties;
1500 return EMPTY_STRING;
1503 bool Controller::SetDefaultLineSpacing( float lineSpacing )
1505 if( std::fabs( lineSpacing - mImpl->mLayoutEngine.GetDefaultLineSpacing() ) > Math::MACHINE_EPSILON_1000 )
1507 mImpl->mLayoutEngine.SetDefaultLineSpacing(lineSpacing);
1508 mImpl->mRecalculateNaturalSize = true;
1514 float Controller::GetDefaultLineSpacing() const
1516 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
1519 bool Controller::SetDefaultLineSize( float lineSize )
1521 if( std::fabs( lineSize - mImpl->mLayoutEngine.GetDefaultLineSize() ) > Math::MACHINE_EPSILON_1000 )
1523 mImpl->mLayoutEngine.SetDefaultLineSize(lineSize);
1524 mImpl->mRecalculateNaturalSize = true;
1530 float Controller::GetDefaultLineSize() const
1532 return mImpl->mLayoutEngine.GetDefaultLineSize();
1535 void Controller::SetInputColor( const Vector4& color )
1537 if( NULL != mImpl->mEventData )
1539 mImpl->mEventData->mInputStyle.textColor = color;
1540 mImpl->mEventData->mInputStyle.isDefaultColor = false;
1542 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1544 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
1546 // Get start and end position of selection
1547 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
1548 const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
1550 // Add the color run.
1551 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1552 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
1554 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
1555 colorRun.color = color;
1556 colorRun.characterRun.characterIndex = startOfSelectedText;
1557 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1559 // Request to relayout.
1560 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1561 mImpl->RequestRelayout();
1563 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1564 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1565 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1570 const Vector4& Controller::GetInputColor() const
1572 if( NULL != mImpl->mEventData )
1574 return mImpl->mEventData->mInputStyle.textColor;
1577 // Return the default text's color if there is no EventData.
1578 return mImpl->mTextColor;
1582 void Controller::SetInputFontFamily( const std::string& fontFamily )
1584 if( NULL != mImpl->mEventData )
1586 mImpl->mEventData->mInputStyle.familyName = fontFamily;
1587 mImpl->mEventData->mInputStyle.isFamilyDefined = true;
1589 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1591 CharacterIndex startOfSelectedText = 0u;
1592 Length lengthOfSelectedText = 0u;
1594 if( EventData::SELECTING == mImpl->mEventData->mState )
1596 // Update a font description run for the selecting state.
1597 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1598 mImpl->mModel->mLogicalModel,
1599 startOfSelectedText,
1600 lengthOfSelectedText );
1602 fontDescriptionRun.familyLength = fontFamily.size();
1603 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
1604 memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength );
1605 fontDescriptionRun.familyDefined = true;
1607 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
1609 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1610 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1611 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1615 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
1616 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
1617 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
1620 // Request to relayout.
1621 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1626 UPDATE_LAYOUT_SIZE |
1629 mImpl->mRecalculateNaturalSize = true;
1630 mImpl->RequestRelayout();
1632 // As the font changes, recalculate the handle positions is needed.
1633 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1634 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1635 mImpl->mEventData->mUpdateHighlightBox = true;
1636 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1641 const std::string& Controller::GetInputFontFamily() const
1643 if( NULL != mImpl->mEventData )
1645 return mImpl->mEventData->mInputStyle.familyName;
1648 // Return the default font's family if there is no EventData.
1649 return GetDefaultFontFamily();
1652 void Controller::SetInputFontWeight( FontWeight weight )
1654 if( NULL != mImpl->mEventData )
1656 mImpl->mEventData->mInputStyle.weight = weight;
1657 mImpl->mEventData->mInputStyle.isWeightDefined = true;
1659 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1661 CharacterIndex startOfSelectedText = 0u;
1662 Length lengthOfSelectedText = 0u;
1664 if( EventData::SELECTING == mImpl->mEventData->mState )
1666 // Update a font description run for the selecting state.
1667 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1668 mImpl->mModel->mLogicalModel,
1669 startOfSelectedText,
1670 lengthOfSelectedText );
1672 fontDescriptionRun.weight = weight;
1673 fontDescriptionRun.weightDefined = true;
1675 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1676 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1677 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1681 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
1682 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
1683 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
1686 // Request to relayout.
1687 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1692 UPDATE_LAYOUT_SIZE |
1695 mImpl->mRecalculateNaturalSize = true;
1696 mImpl->RequestRelayout();
1698 // As the font might change, recalculate the handle positions is needed.
1699 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1700 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1701 mImpl->mEventData->mUpdateHighlightBox = true;
1702 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1707 bool Controller::IsInputFontWeightDefined() const
1709 bool defined = false;
1711 if( NULL != mImpl->mEventData )
1713 defined = mImpl->mEventData->mInputStyle.isWeightDefined;
1719 FontWeight Controller::GetInputFontWeight() const
1721 if( NULL != mImpl->mEventData )
1723 return mImpl->mEventData->mInputStyle.weight;
1726 return GetDefaultFontWeight();
1729 void Controller::SetInputFontWidth( FontWidth width )
1731 if( NULL != mImpl->mEventData )
1733 mImpl->mEventData->mInputStyle.width = width;
1734 mImpl->mEventData->mInputStyle.isWidthDefined = true;
1736 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1738 CharacterIndex startOfSelectedText = 0u;
1739 Length lengthOfSelectedText = 0u;
1741 if( EventData::SELECTING == mImpl->mEventData->mState )
1743 // Update a font description run for the selecting state.
1744 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1745 mImpl->mModel->mLogicalModel,
1746 startOfSelectedText,
1747 lengthOfSelectedText );
1749 fontDescriptionRun.width = width;
1750 fontDescriptionRun.widthDefined = true;
1752 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1753 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1754 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1758 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
1759 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
1760 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
1763 // Request to relayout.
1764 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1769 UPDATE_LAYOUT_SIZE |
1772 mImpl->mRecalculateNaturalSize = true;
1773 mImpl->RequestRelayout();
1775 // As the font might change, recalculate the handle positions is needed.
1776 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1777 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1778 mImpl->mEventData->mUpdateHighlightBox = true;
1779 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1784 bool Controller::IsInputFontWidthDefined() const
1786 bool defined = false;
1788 if( NULL != mImpl->mEventData )
1790 defined = mImpl->mEventData->mInputStyle.isWidthDefined;
1796 FontWidth Controller::GetInputFontWidth() const
1798 if( NULL != mImpl->mEventData )
1800 return mImpl->mEventData->mInputStyle.width;
1803 return GetDefaultFontWidth();
1806 void Controller::SetInputFontSlant( FontSlant slant )
1808 if( NULL != mImpl->mEventData )
1810 mImpl->mEventData->mInputStyle.slant = slant;
1811 mImpl->mEventData->mInputStyle.isSlantDefined = true;
1813 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1815 CharacterIndex startOfSelectedText = 0u;
1816 Length lengthOfSelectedText = 0u;
1818 if( EventData::SELECTING == mImpl->mEventData->mState )
1820 // Update a font description run for the selecting state.
1821 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1822 mImpl->mModel->mLogicalModel,
1823 startOfSelectedText,
1824 lengthOfSelectedText );
1826 fontDescriptionRun.slant = slant;
1827 fontDescriptionRun.slantDefined = true;
1829 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1830 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1831 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1835 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
1836 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
1837 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
1840 // Request to relayout.
1841 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1846 UPDATE_LAYOUT_SIZE |
1849 mImpl->mRecalculateNaturalSize = true;
1850 mImpl->RequestRelayout();
1852 // As the font might change, recalculate the handle positions is needed.
1853 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1854 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1855 mImpl->mEventData->mUpdateHighlightBox = true;
1856 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1861 bool Controller::IsInputFontSlantDefined() const
1863 bool defined = false;
1865 if( NULL != mImpl->mEventData )
1867 defined = mImpl->mEventData->mInputStyle.isSlantDefined;
1873 FontSlant Controller::GetInputFontSlant() const
1875 if( NULL != mImpl->mEventData )
1877 return mImpl->mEventData->mInputStyle.slant;
1880 return GetDefaultFontSlant();
1883 void Controller::SetInputFontPointSize( float size )
1885 if( NULL != mImpl->mEventData )
1887 mImpl->mEventData->mInputStyle.size = size;
1888 mImpl->mEventData->mInputStyle.isSizeDefined = true;
1890 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1892 CharacterIndex startOfSelectedText = 0u;
1893 Length lengthOfSelectedText = 0u;
1895 if( EventData::SELECTING == mImpl->mEventData->mState )
1897 // Update a font description run for the selecting state.
1898 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1899 mImpl->mModel->mLogicalModel,
1900 startOfSelectedText,
1901 lengthOfSelectedText );
1903 fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
1904 fontDescriptionRun.sizeDefined = true;
1906 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1907 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1908 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1912 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
1913 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
1914 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
1917 // Request to relayout.
1918 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1923 UPDATE_LAYOUT_SIZE |
1926 mImpl->mRecalculateNaturalSize = true;
1927 mImpl->RequestRelayout();
1929 // As the font might change, recalculate the handle positions is needed.
1930 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1931 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1932 mImpl->mEventData->mUpdateHighlightBox = true;
1933 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1938 float Controller::GetInputFontPointSize() const
1940 if( NULL != mImpl->mEventData )
1942 return mImpl->mEventData->mInputStyle.size;
1945 // Return the default font's point size if there is no EventData.
1946 return GetDefaultFontSize( Text::Controller::POINT_SIZE );
1949 void Controller::SetInputLineSpacing( float lineSpacing )
1951 if( NULL != mImpl->mEventData )
1953 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1954 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1958 float Controller::GetInputLineSpacing() const
1960 if( NULL != mImpl->mEventData )
1962 return mImpl->mEventData->mInputStyle.lineSpacing;
1968 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1970 if( NULL != mImpl->mEventData )
1972 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1976 const std::string& Controller::GetInputShadowProperties() const
1978 if( NULL != mImpl->mEventData )
1980 return mImpl->mEventData->mInputStyle.shadowProperties;
1983 return EMPTY_STRING;
1986 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1988 if( NULL != mImpl->mEventData )
1990 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1994 const std::string& Controller::GetInputUnderlineProperties() const
1996 if( NULL != mImpl->mEventData )
1998 return mImpl->mEventData->mInputStyle.underlineProperties;
2001 return EMPTY_STRING;
2004 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
2006 if( NULL != mImpl->mEventData )
2008 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
2012 const std::string& Controller::GetInputEmbossProperties() const
2014 if( NULL != mImpl->mEventData )
2016 return mImpl->mEventData->mInputStyle.embossProperties;
2019 return GetDefaultEmbossProperties();
2022 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
2024 if( NULL != mImpl->mEventData )
2026 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
2030 const std::string& Controller::GetInputOutlineProperties() const
2032 if( NULL != mImpl->mEventData )
2034 return mImpl->mEventData->mInputStyle.outlineProperties;
2037 return GetDefaultOutlineProperties();
2040 void Controller::SetInputModePassword( bool passwordInput )
2042 if( NULL != mImpl->mEventData )
2044 mImpl->mEventData->mPasswordInput = passwordInput;
2048 bool Controller::IsInputModePassword()
2050 if( NULL != mImpl->mEventData )
2052 return mImpl->mEventData->mPasswordInput;
2057 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
2059 if( NULL != mImpl->mEventData )
2061 mImpl->mEventData->mDoubleTapAction = action;
2065 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
2067 NoTextTap::Action action = NoTextTap::NO_ACTION;
2069 if( NULL != mImpl->mEventData )
2071 action = mImpl->mEventData->mDoubleTapAction;
2077 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
2079 if( NULL != mImpl->mEventData )
2081 mImpl->mEventData->mLongPressAction = action;
2085 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
2087 NoTextTap::Action action = NoTextTap::NO_ACTION;
2089 if( NULL != mImpl->mEventData )
2091 action = mImpl->mEventData->mLongPressAction;
2097 bool Controller::IsUnderlineSetByString()
2099 return mImpl->mUnderlineSetByString;
2102 void Controller::UnderlineSetByString( bool setByString )
2104 mImpl->mUnderlineSetByString = setByString;
2107 bool Controller::IsShadowSetByString()
2109 return mImpl->mShadowSetByString;
2112 void Controller::ShadowSetByString( bool setByString )
2114 mImpl->mShadowSetByString = setByString;
2117 bool Controller::IsOutlineSetByString()
2119 return mImpl->mOutlineSetByString;
2122 void Controller::OutlineSetByString( bool setByString )
2124 mImpl->mOutlineSetByString = setByString;
2127 bool Controller::IsFontStyleSetByString()
2129 return mImpl->mFontStyleSetByString;
2132 void Controller::FontStyleSetByString( bool setByString )
2134 mImpl->mFontStyleSetByString = setByString;
2137 // public : Queries & retrieves.
2139 Layout::Engine& Controller::GetLayoutEngine()
2141 return mImpl->mLayoutEngine;
2144 View& Controller::GetView()
2146 return mImpl->mView;
2149 Vector3 Controller::GetNaturalSize()
2151 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
2152 Vector3 naturalSize;
2154 // Make sure the model is up-to-date before layouting
2155 ProcessModifyEvents();
2157 if( mImpl->mRecalculateNaturalSize )
2159 // Operations that can be done only once until the text changes.
2160 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2166 GET_GLYPH_METRICS );
2168 // Set the update info to relayout the whole text.
2169 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2170 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2172 // Make sure the model is up-to-date before layouting
2173 mImpl->UpdateModel( onlyOnceOperations );
2175 // Layout the text for the new width.
2176 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT | REORDER );
2178 // Store the actual control's size to restore later.
2179 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
2181 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
2182 static_cast<OperationsMask>( onlyOnceOperations |
2184 naturalSize.GetVectorXY() );
2186 // Do not do again the only once operations.
2187 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2189 // Do the size related operations again.
2190 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
2193 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
2195 // Stores the natural size to avoid recalculate it again
2196 // unless the text/style changes.
2197 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
2199 mImpl->mRecalculateNaturalSize = false;
2201 // Clear the update info. This info will be set the next time the text is updated.
2202 mImpl->mTextUpdateInfo.Clear();
2203 mImpl->mTextUpdateInfo.mClearAll = true;
2205 // Restore the actual control's size.
2206 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
2208 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
2212 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
2214 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
2217 naturalSize.x = ConvertToEven( naturalSize.x );
2218 naturalSize.y = ConvertToEven( naturalSize.y );
2223 bool Controller::CheckForTextFit( float pointSize, Size& layoutSize )
2226 mImpl->mFontDefaults->mFitPointSize = pointSize;
2227 mImpl->mFontDefaults->sizeDefined = true;
2230 // Operations that can be done only once until the text changes.
2231 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2237 GET_GLYPH_METRICS );
2239 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2240 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2242 // Make sure the model is up-to-date before layouting
2243 mImpl->UpdateModel( onlyOnceOperations );
2245 DoRelayout( Size( layoutSize.width, MAX_FLOAT ),
2246 static_cast<OperationsMask>( onlyOnceOperations | LAYOUT),
2249 // Clear the update info. This info will be set the next time the text is updated.
2250 mImpl->mTextUpdateInfo.Clear();
2251 mImpl->mTextUpdateInfo.mClearAll = true;
2253 if( textSize.width > layoutSize.width || textSize.height > layoutSize.height )
2260 void Controller::FitPointSizeforLayout( Size layoutSize )
2262 const OperationsMask operations = mImpl->mOperationsPending;
2263 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) || mImpl->mTextFitContentSize != layoutSize )
2265 bool actualellipsis = mImpl->mModel->mElideEnabled;
2266 float minPointSize = mImpl->mTextFitMinSize;
2267 float maxPointSize = mImpl->mTextFitMaxSize;
2268 float pointInterval = mImpl->mTextFitStepSize;
2270 mImpl->mModel->mElideEnabled = false;
2271 Vector<float> pointSizeArray;
2274 if( pointInterval < 1.f )
2276 mImpl->mTextFitStepSize = pointInterval = 1.0f;
2279 pointSizeArray.Reserve( static_cast< unsigned int >( ceil( ( maxPointSize - minPointSize ) / pointInterval ) ) );
2281 for( float i = minPointSize; i < maxPointSize; i += pointInterval )
2283 pointSizeArray.PushBack( i );
2286 pointSizeArray.PushBack( maxPointSize );
2288 int bestSizeIndex = 0;
2289 int min = bestSizeIndex + 1;
2290 int max = pointSizeArray.Size() - 1;
2293 int destI = ( min + max ) / 2;
2295 if( CheckForTextFit( pointSizeArray[destI], layoutSize ) )
2297 bestSizeIndex = min;
2303 bestSizeIndex = max;
2307 mImpl->mModel->mElideEnabled = actualellipsis;
2308 mImpl->mFontDefaults->mFitPointSize = pointSizeArray[bestSizeIndex];
2309 mImpl->mFontDefaults->sizeDefined = true;
2314 float Controller::GetHeightForWidth( float width )
2316 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
2317 // Make sure the model is up-to-date before layouting
2318 ProcessModifyEvents();
2321 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ||
2322 mImpl->mTextUpdateInfo.mFullRelayoutNeeded ||
2323 mImpl->mTextUpdateInfo.mClearAll )
2325 // Operations that can be done only once until the text changes.
2326 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2332 GET_GLYPH_METRICS );
2334 // Set the update info to relayout the whole text.
2335 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2336 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2338 // Make sure the model is up-to-date before layouting
2339 mImpl->UpdateModel( onlyOnceOperations );
2342 // Layout the text for the new width.
2343 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
2345 // Store the actual control's width.
2346 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
2348 DoRelayout( Size( width, MAX_FLOAT ),
2349 static_cast<OperationsMask>( onlyOnceOperations |
2353 // Do not do again the only once operations.
2354 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2356 // Do the size related operations again.
2357 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
2361 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
2363 // Clear the update info. This info will be set the next time the text is updated.
2364 mImpl->mTextUpdateInfo.Clear();
2365 mImpl->mTextUpdateInfo.mClearAll = true;
2367 // Restore the actual control's width.
2368 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
2370 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
2374 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
2375 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
2378 return layoutSize.height;
2381 int Controller::GetLineCount( float width )
2383 GetHeightForWidth( width );
2384 int numberofLines = mImpl->mModel->GetNumberOfLines();
2385 return numberofLines;
2388 const ModelInterface* const Controller::GetTextModel() const
2390 return mImpl->mModel.Get();
2393 float Controller::GetScrollAmountByUserInput()
2395 float scrollAmount = 0.0f;
2397 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
2399 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
2400 mImpl->mEventData->mCheckScrollAmount = false;
2402 return scrollAmount;
2405 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
2407 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
2410 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
2411 layoutHeight = layout.height;
2412 scrollPosition = mImpl->mModel->mScrollPosition.y;
2413 isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
2417 void Controller::SetHiddenInputOption(const Property::Map& options )
2419 if( NULL == mImpl->mHiddenInput )
2421 mImpl->mHiddenInput = new HiddenText( this );
2423 mImpl->mHiddenInput->SetProperties(options);
2426 void Controller::GetHiddenInputOption(Property::Map& options )
2428 if( NULL != mImpl->mHiddenInput )
2430 mImpl->mHiddenInput->GetProperties(options);
2434 void Controller::SetPlaceholderProperty( const Property::Map& map )
2436 const Property::Map::SizeType count = map.Count();
2438 for( Property::Map::SizeType position = 0; position < count; ++position )
2440 KeyValuePair keyValue = map.GetKeyValue( position );
2441 Property::Key& key = keyValue.first;
2442 Property::Value& value = keyValue.second;
2444 if( key == Toolkit::Text::PlaceHolder::Property::TEXT || key == PLACEHOLDER_TEXT )
2446 std::string text = "";
2448 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
2450 else if( key == Toolkit::Text::PlaceHolder::Property::TEXT_FOCUSED || key == PLACEHOLDER_TEXT_FOCUSED )
2452 std::string text = "";
2454 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
2456 else if( key == Toolkit::Text::PlaceHolder::Property::COLOR || key == PLACEHOLDER_COLOR )
2459 value.Get( textColor );
2460 if( GetPlaceholderTextColor() != textColor )
2462 SetPlaceholderTextColor( textColor );
2465 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_FAMILY || key == PLACEHOLDER_FONT_FAMILY )
2467 std::string fontFamily = "";
2468 value.Get( fontFamily );
2469 SetPlaceholderFontFamily( fontFamily );
2471 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_STYLE || key == PLACEHOLDER_FONT_STYLE )
2473 SetFontStyleProperty( this, value, Text::FontStyle::PLACEHOLDER );
2475 else if( key == Toolkit::Text::PlaceHolder::Property::POINT_SIZE || key == PLACEHOLDER_POINT_SIZE )
2478 value.Get( pointSize );
2479 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
2481 SetPlaceholderTextFontSize( pointSize, Text::Controller::POINT_SIZE );
2484 else if( key == Toolkit::Text::PlaceHolder::Property::PIXEL_SIZE || key == PLACEHOLDER_PIXEL_SIZE )
2487 value.Get( pixelSize );
2488 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
2490 SetPlaceholderTextFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
2493 else if( key == Toolkit::Text::PlaceHolder::Property::ELLIPSIS || key == PLACEHOLDER_ELLIPSIS )
2496 value.Get( ellipsis );
2497 SetPlaceholderTextElideEnabled( ellipsis );
2502 void Controller::GetPlaceholderProperty( Property::Map& map )
2504 if( NULL != mImpl->mEventData )
2506 if( !mImpl->mEventData->mPlaceholderTextActive.empty() )
2508 map[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = mImpl->mEventData->mPlaceholderTextActive;
2510 if( !mImpl->mEventData->mPlaceholderTextInactive.empty() )
2512 map[ Text::PlaceHolder::Property::TEXT ] = mImpl->mEventData->mPlaceholderTextInactive;
2515 map[ Text::PlaceHolder::Property::COLOR ] = mImpl->mEventData->mPlaceholderTextColor;
2516 map[ Text::PlaceHolder::Property::FONT_FAMILY ] = GetPlaceholderFontFamily();
2518 Property::Value fontStyleMapGet;
2519 GetFontStyleProperty( this, fontStyleMapGet, Text::FontStyle::PLACEHOLDER );
2520 map[ Text::PlaceHolder::Property::FONT_STYLE ] = fontStyleMapGet;
2522 // Choose font size : POINT_SIZE or PIXEL_SIZE
2523 if( !mImpl->mEventData->mIsPlaceholderPixelSize )
2525 map[ Text::PlaceHolder::Property::POINT_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE );
2529 map[ Text::PlaceHolder::Property::PIXEL_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE );
2532 if( mImpl->mEventData->mPlaceholderEllipsisFlag )
2534 map[ Text::PlaceHolder::Property::ELLIPSIS ] = IsPlaceholderTextElideEnabled();
2539 Toolkit::DevelText::TextDirection::Type Controller::GetTextDirection()
2541 // Make sure the model is up-to-date before layouting
2542 ProcessModifyEvents();
2544 if ( mImpl->mUpdateTextDirection )
2546 // Operations that can be done only once until the text changes.
2547 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2553 GET_GLYPH_METRICS );
2555 // Set the update info to relayout the whole text.
2556 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2557 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2559 // Make sure the model is up-to-date before layouting
2560 mImpl->UpdateModel( onlyOnceOperations );
2562 Vector3 naturalSize;
2563 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
2564 static_cast<OperationsMask>( onlyOnceOperations |
2565 LAYOUT | REORDER | UPDATE_DIRECTION ),
2566 naturalSize.GetVectorXY() );
2568 // Do not do again the only once operations.
2569 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2571 // Clear the update info. This info will be set the next time the text is updated.
2572 mImpl->mTextUpdateInfo.Clear();
2574 // FullRelayoutNeeded should be true because DoRelayout is MAX_FLOAT, MAX_FLOAT.
2575 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2577 mImpl->mUpdateTextDirection = false;
2580 return mImpl->mIsTextDirectionRTL ? Toolkit::DevelText::TextDirection::RIGHT_TO_LEFT : Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT;
2583 Toolkit::DevelText::VerticalLineAlignment::Type Controller::GetVerticalLineAlignment() const
2585 return mImpl->mModel->GetVerticalLineAlignment();
2588 void Controller::SetVerticalLineAlignment( Toolkit::DevelText::VerticalLineAlignment::Type alignment )
2590 mImpl->mModel->mVerticalLineAlignment = alignment;
2593 // public : Relayout.
2595 Controller::UpdateTextType Controller::Relayout( const Size& size, Dali::LayoutDirection::Type layoutDirection )
2597 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
2599 UpdateTextType updateTextType = NONE_UPDATED;
2601 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
2603 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
2605 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
2606 updateTextType = MODEL_UPDATED;
2609 // Clear the update info. This info will be set the next time the text is updated.
2610 mImpl->mTextUpdateInfo.Clear();
2612 // Not worth to relayout if width or height is equal to zero.
2613 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
2615 return updateTextType;
2618 // Whether a new size has been set.
2619 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
2623 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
2625 if( ( 0 == mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd ) &&
2626 ( 0 == mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) &&
2627 ( ( mImpl->mModel->mVisualModel->mControlSize.width < Math::MACHINE_EPSILON_1000 ) || ( mImpl->mModel->mVisualModel->mControlSize.height < Math::MACHINE_EPSILON_1000 ) ) )
2629 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
2632 // Layout operations that need to be done if the size changes.
2633 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2636 UPDATE_LAYOUT_SIZE |
2638 // Set the update info to relayout the whole text.
2639 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2640 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2642 // Store the size used to layout the text.
2643 mImpl->mModel->mVisualModel->mControlSize = size;
2646 // Whether there are modify events.
2647 if( 0u != mImpl->mModifyEvents.Count() )
2649 // Style operations that need to be done if the text is modified.
2650 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2654 // Set the update info to elide the text.
2655 if( mImpl->mModel->mElideEnabled ||
2656 ( ( NULL != mImpl->mEventData ) && mImpl->mEventData->mIsPlaceholderElideEnabled ) )
2658 // Update Text layout for applying elided
2659 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2662 UPDATE_LAYOUT_SIZE |
2664 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2665 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2668 if( mImpl->mModel->mMatchSystemLanguageDirection && mImpl->mLayoutDirection != layoutDirection )
2670 // Clear the update info. This info will be set the next time the text is updated.
2671 mImpl->mTextUpdateInfo.mClearAll = true;
2672 // Apply modifications to the model
2673 // Shape the text again is needed because characters like '()[]{}' have to be mirrored and the glyphs generated again.
2674 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2681 mImpl->mLayoutDirection = layoutDirection;
2684 // Make sure the model is up-to-date before layouting.
2685 ProcessModifyEvents();
2686 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
2690 updated = DoRelayout( size,
2691 mImpl->mOperationsPending,
2692 layoutSize ) || updated;
2697 updateTextType = MODEL_UPDATED;
2700 // Do not re-do any operation until something changes.
2701 mImpl->mOperationsPending = NO_OPERATION;
2702 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
2704 // Whether the text control is editable
2705 const bool isEditable = NULL != mImpl->mEventData;
2707 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
2709 if( newSize && isEditable )
2711 offset = mImpl->mModel->mScrollPosition;
2714 if( !isEditable || !IsMultiLineEnabled() )
2716 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
2717 CalculateVerticalOffset( size );
2724 // If there is a new size, the scroll position needs to be clamped.
2725 mImpl->ClampHorizontalScroll( layoutSize );
2727 // Update the decorator's positions is needed if there is a new size.
2728 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
2731 // Move the cursor, grab handle etc.
2732 if( mImpl->ProcessInputEvents() )
2734 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
2738 // Clear the update info. This info will be set the next time the text is updated.
2739 mImpl->mTextUpdateInfo.Clear();
2740 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
2742 return updateTextType;
2745 void Controller::RequestRelayout()
2747 mImpl->RequestRelayout();
2750 // public : Input style change signals.
2752 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
2754 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
2757 void Controller::ProcessInputStyleChangedSignals()
2759 if( NULL == mImpl->mEventData )
2765 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
2766 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
2770 const InputStyle::Mask mask = *it;
2772 if( NULL != mImpl->mEditableControlInterface )
2774 // Emit the input style changed signal.
2775 mImpl->mEditableControlInterface->InputStyleChanged( mask );
2779 mImpl->mEventData->mInputStyleChangedQueue.Clear();
2782 // public : Text-input Event Queuing.
2784 void Controller::KeyboardFocusGainEvent()
2786 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
2788 if( NULL != mImpl->mEventData )
2790 if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
2791 ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
2793 mImpl->ChangeState( EventData::EDITING );
2794 mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
2795 mImpl->mEventData->mUpdateInputStyle = true;
2796 mImpl->mEventData->mScrollAfterUpdatePosition = true;
2798 mImpl->NotifyInputMethodContextMultiLineStatus();
2799 if( mImpl->IsShowingPlaceholderText() )
2801 // Show alternative placeholder-text when editing
2802 ShowPlaceholderText();
2805 mImpl->RequestRelayout();
2809 void Controller::KeyboardFocusLostEvent()
2811 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
2813 if( NULL != mImpl->mEventData )
2815 if( EventData::INTERRUPTED != mImpl->mEventData->mState )
2817 mImpl->ChangeState( EventData::INACTIVE );
2819 if( !mImpl->IsShowingRealText() )
2821 // Revert to regular placeholder-text when not editing
2822 ShowPlaceholderText();
2826 mImpl->RequestRelayout();
2829 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
2831 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
2833 bool textChanged = false;
2834 bool relayoutNeeded = false;
2836 if( ( NULL != mImpl->mEventData ) &&
2837 ( keyEvent.GetState() == KeyEvent::DOWN ) )
2839 int keyCode = keyEvent.GetKeyCode();
2840 const std::string& keyString = keyEvent.GetKeyString();
2841 const std::string keyName = keyEvent.GetKeyName();
2843 const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
2845 // Pre-process to separate modifying events from non-modifying input events.
2848 // In some platforms arrive key events with no key code.
2852 else if( Dali::DALI_KEY_ESCAPE == keyCode || Dali::DALI_KEY_BACK == keyCode || Dali::DALI_KEY_SEARCH == keyCode )
2857 else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) ||
2858 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
2859 ( Dali::DALI_KEY_CURSOR_UP == keyCode ) ||
2860 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) )
2862 // If don't have any text, do nothing.
2863 if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
2868 uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition;
2869 uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2870 uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition );
2871 uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines();
2873 // Logic to determine whether this text control will lose focus or not.
2874 if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2875 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2876 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) ||
2877 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) ||
2878 ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) ||
2879 ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) )
2881 // Release the active highlight.
2882 if( mImpl->mEventData->mState == EventData::SELECTING )
2884 mImpl->ChangeState( EventData::EDITING );
2886 // Update selection position.
2887 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2888 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2889 mImpl->mEventData->mUpdateCursorPosition = true;
2890 mImpl->RequestRelayout();
2895 mImpl->mEventData->mCheckScrollAmount = true;
2896 Event event( Event::CURSOR_KEY_EVENT );
2897 event.p1.mInt = keyCode;
2898 event.p2.mBool = keyEvent.IsShiftModifier();
2899 mImpl->mEventData->mEventQueue.push_back( event );
2901 // Will request for relayout.
2902 relayoutNeeded = true;
2904 else if ( Dali::DevelKey::DALI_KEY_CONTROL_LEFT == keyCode || Dali::DevelKey::DALI_KEY_CONTROL_RIGHT == keyCode )
2906 // Left or Right Control key event is received before Ctrl-C/V/X key event is received
2907 // If not handle it here, any selected text will be deleted
2912 else if ( keyEvent.IsCtrlModifier() && !keyEvent.IsShiftModifier())
2914 bool consumed = false;
2915 if (keyName == KEY_C_NAME || keyName == KEY_INSERT_NAME)
2917 // Ctrl-C or Ctrl+Insert to copy the selected text
2918 TextPopupButtonTouched( Toolkit::TextSelectionPopup::COPY );
2921 else if (keyName == KEY_V_NAME)
2923 // Ctrl-V to paste the copied text
2924 TextPopupButtonTouched( Toolkit::TextSelectionPopup::PASTE );
2927 else if (keyName == KEY_X_NAME)
2929 // Ctrl-X to cut the selected text
2930 TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
2933 else if (keyName == KEY_A_NAME)
2935 // Ctrl-A to select All the text
2936 TextPopupButtonTouched( Toolkit::TextSelectionPopup::SELECT_ALL );
2941 else if( ( Dali::DALI_KEY_BACKSPACE == keyCode ) ||
2942 ( Dali::DevelKey::DALI_KEY_DELETE == keyCode ) )
2944 textChanged = DeleteEvent( keyCode );
2946 // Will request for relayout.
2947 relayoutNeeded = true;
2949 else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
2950 IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
2951 IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
2953 // Power key/Menu/Home key behaviour does not allow edit mode to resume.
2954 mImpl->ChangeState( EventData::INACTIVE );
2956 // Will request for relayout.
2957 relayoutNeeded = true;
2959 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2961 else if( ( Dali::DALI_KEY_SHIFT_LEFT == keyCode ) || ( Dali::DALI_KEY_SHIFT_RIGHT == keyCode ) )
2963 // 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
2964 // and a character is typed after the type of a upper case latin character.
2969 else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
2971 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2977 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
2979 if( !keyString.empty() )
2981 // InputMethodContext is no longer handling key-events
2982 mImpl->ClearPreEditFlag();
2984 InsertText( keyString, COMMIT );
2988 // Will request for relayout.
2989 relayoutNeeded = true;
2994 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
2995 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
2997 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
2998 ( Dali::DALI_KEY_SHIFT_RIGHT != keyCode ) &&
2999 ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
3000 ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
3002 // Should not change the state if the key is the shift send by the InputMethodContext.
3003 // Otherwise, when the state is SELECTING the text controller can't send the right
3004 // surrounding info to the InputMethodContext.
3005 mImpl->ChangeState( EventData::EDITING );
3007 // Will request for relayout.
3008 relayoutNeeded = true;
3011 if( relayoutNeeded )
3013 mImpl->RequestRelayout();
3018 ( NULL != mImpl->mEditableControlInterface ) )
3020 // Do this last since it provides callbacks into application code
3021 mImpl->mEditableControlInterface->TextChanged();
3027 void Controller::TapEvent( unsigned int tapCount, float x, float y )
3029 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
3031 if( NULL != mImpl->mEventData )
3033 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
3034 EventData::State state( mImpl->mEventData->mState );
3035 bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
3037 if( mImpl->IsClipboardVisible() )
3039 if( EventData::INACTIVE == state || EventData::EDITING == state)
3041 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
3043 relayoutNeeded = true;
3045 else if( 1u == tapCount )
3047 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
3049 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
3052 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
3054 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
3055 relayoutNeeded = true;
3059 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
3061 // Hide placeholder text
3065 if( EventData::INACTIVE == state )
3067 mImpl->ChangeState( EventData::EDITING );
3069 else if( !mImpl->IsClipboardEmpty() )
3071 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
3073 relayoutNeeded = true;
3076 else if( 2u == tapCount )
3078 if( mImpl->mEventData->mSelectionEnabled &&
3079 mImpl->IsShowingRealText() )
3081 relayoutNeeded = true;
3082 mImpl->mEventData->mIsLeftHandleSelected = true;
3083 mImpl->mEventData->mIsRightHandleSelected = true;
3087 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
3088 if( relayoutNeeded )
3090 Event event( Event::TAP_EVENT );
3091 event.p1.mUint = tapCount;
3092 event.p2.mFloat = x;
3093 event.p3.mFloat = y;
3094 mImpl->mEventData->mEventQueue.push_back( event );
3096 mImpl->RequestRelayout();
3100 // Reset keyboard as tap event has occurred.
3101 mImpl->ResetInputMethodContext();
3104 void Controller::PanEvent( GestureState state, const Vector2& displacement )
3106 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
3108 if( NULL != mImpl->mEventData )
3110 Event event( Event::PAN_EVENT );
3111 event.p1.mInt = static_cast<int>( state );
3112 event.p2.mFloat = displacement.x;
3113 event.p3.mFloat = displacement.y;
3114 mImpl->mEventData->mEventQueue.push_back( event );
3116 mImpl->RequestRelayout();
3120 void Controller::LongPressEvent( GestureState state, float x, float y )
3122 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
3124 if( ( state == GestureState::STARTED ) &&
3125 ( NULL != mImpl->mEventData ) )
3127 // The 1st long-press on inactive text-field is treated as tap
3128 if( EventData::INACTIVE == mImpl->mEventData->mState )
3130 mImpl->ChangeState( EventData::EDITING );
3132 Event event( Event::TAP_EVENT );
3134 event.p2.mFloat = x;
3135 event.p3.mFloat = y;
3136 mImpl->mEventData->mEventQueue.push_back( event );
3138 mImpl->RequestRelayout();
3140 else if( !mImpl->IsShowingRealText() )
3142 Event event( Event::LONG_PRESS_EVENT );
3143 event.p1.mInt = static_cast<int>( state );
3144 event.p2.mFloat = x;
3145 event.p3.mFloat = y;
3146 mImpl->mEventData->mEventQueue.push_back( event );
3147 mImpl->RequestRelayout();
3149 else if( !mImpl->IsClipboardVisible() )
3151 // Reset the InputMethodContext to commit the pre-edit before selecting the text.
3152 mImpl->ResetInputMethodContext();
3154 Event event( Event::LONG_PRESS_EVENT );
3155 event.p1.mInt = static_cast<int>( state );
3156 event.p2.mFloat = x;
3157 event.p3.mFloat = y;
3158 mImpl->mEventData->mEventQueue.push_back( event );
3159 mImpl->RequestRelayout();
3161 mImpl->mEventData->mIsLeftHandleSelected = true;
3162 mImpl->mEventData->mIsRightHandleSelected = true;
3167 void Controller::SelectEvent( float x, float y, SelectionType selectType )
3169 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
3171 if( NULL != mImpl->mEventData )
3173 if( selectType == SelectionType::ALL )
3175 Event event( Event::SELECT_ALL );
3176 mImpl->mEventData->mEventQueue.push_back( event );
3178 else if( selectType == SelectionType::NONE )
3180 Event event( Event::SELECT_NONE );
3181 mImpl->mEventData->mEventQueue.push_back( event );
3185 Event event( Event::SELECT );
3186 event.p2.mFloat = x;
3187 event.p3.mFloat = y;
3188 mImpl->mEventData->mEventQueue.push_back( event );
3191 mImpl->mEventData->mCheckScrollAmount = true;
3192 mImpl->mEventData->mIsLeftHandleSelected = true;
3193 mImpl->mEventData->mIsRightHandleSelected = true;
3194 mImpl->RequestRelayout();
3198 void Controller::SetTextSelectionRange(const uint32_t *start, const uint32_t *end)
3200 if( mImpl->mEventData )
3202 mImpl->mEventData->mCheckScrollAmount = true;
3203 mImpl->mEventData->mIsLeftHandleSelected = true;
3204 mImpl->mEventData->mIsRightHandleSelected = true;
3205 mImpl->SetTextSelectionRange(start, end);
3206 mImpl->RequestRelayout();
3207 KeyboardFocusGainEvent();
3211 Uint32Pair Controller::GetTextSelectionRange() const
3213 return mImpl->GetTextSelectionRange();
3216 InputMethodContext::CallbackData Controller::OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
3218 // Whether the text needs to be relaid-out.
3219 bool requestRelayout = false;
3221 // Whether to retrieve the text and cursor position to be sent to the InputMethodContext.
3222 bool retrieveText = false;
3223 bool retrieveCursor = false;
3225 switch( inputMethodContextEvent.eventName )
3227 case InputMethodContext::COMMIT:
3229 InsertText( inputMethodContextEvent.predictiveString, Text::Controller::COMMIT );
3230 requestRelayout = true;
3231 retrieveCursor = true;
3234 case InputMethodContext::PRE_EDIT:
3236 InsertText( inputMethodContextEvent.predictiveString, Text::Controller::PRE_EDIT );
3237 requestRelayout = true;
3238 retrieveCursor = true;
3241 case InputMethodContext::DELETE_SURROUNDING:
3243 const bool textDeleted = RemoveText( inputMethodContextEvent.cursorOffset,
3244 inputMethodContextEvent.numberOfChars,
3245 DONT_UPDATE_INPUT_STYLE );
3249 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3250 !mImpl->IsPlaceholderAvailable() )
3252 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3256 ShowPlaceholderText();
3258 mImpl->mEventData->mUpdateCursorPosition = true;
3259 mImpl->mEventData->mScrollAfterDelete = true;
3261 requestRelayout = true;
3265 case InputMethodContext::GET_SURROUNDING:
3267 retrieveText = true;
3268 retrieveCursor = true;
3271 case InputMethodContext::PRIVATE_COMMAND:
3273 // PRIVATECOMMAND event is just for getting the private command message
3274 retrieveText = true;
3275 retrieveCursor = true;
3278 case InputMethodContext::VOID:
3285 if( requestRelayout )
3287 mImpl->mOperationsPending = ALL_OPERATIONS;
3288 mImpl->RequestRelayout();
3292 CharacterIndex cursorPosition = 0u;
3293 Length numberOfWhiteSpaces = 0u;
3295 if( retrieveCursor )
3297 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
3299 cursorPosition = mImpl->GetLogicalCursorPosition();
3301 if( cursorPosition < numberOfWhiteSpaces )
3303 cursorPosition = 0u;
3307 cursorPosition -= numberOfWhiteSpaces;
3313 if( !mImpl->IsShowingPlaceholderText() )
3315 // Retrieves the normal text string.
3316 mImpl->GetText( numberOfWhiteSpaces, text );
3320 // When the current text is Placeholder Text, the surrounding text should be empty string.
3321 // It means DALi should send empty string ("") to IME.
3326 InputMethodContext::CallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
3328 if( requestRelayout &&
3329 ( NULL != mImpl->mEditableControlInterface ) )
3331 // Do this last since it provides callbacks into application code
3332 mImpl->mEditableControlInterface->TextChanged();
3335 return callbackData;
3338 void Controller::PasteClipboardItemEvent()
3340 // Retrieve the clipboard contents first
3341 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
3342 std::string stringToPaste( notifier.GetContent() );
3344 // Commit the current pre-edit text; the contents of the clipboard should be appended
3345 mImpl->ResetInputMethodContext();
3347 // Temporary disable hiding clipboard
3348 mImpl->SetClipboardHideEnable( false );
3351 PasteText( stringToPaste );
3353 mImpl->SetClipboardHideEnable( true );
3356 // protected : Inherit from Text::Decorator::ControllerInterface.
3358 void Controller::GetTargetSize( Vector2& targetSize )
3360 targetSize = mImpl->mModel->mVisualModel->mControlSize;
3363 void Controller::AddDecoration( Actor& actor, bool needsClipping )
3365 if( NULL != mImpl->mEditableControlInterface )
3367 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
3371 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
3373 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
3375 if( NULL != mImpl->mEventData )
3377 switch( handleType )
3381 Event event( Event::GRAB_HANDLE_EVENT );
3382 event.p1.mUint = state;
3383 event.p2.mFloat = x;
3384 event.p3.mFloat = y;
3386 mImpl->mEventData->mEventQueue.push_back( event );
3389 case LEFT_SELECTION_HANDLE:
3391 Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
3392 event.p1.mUint = state;
3393 event.p2.mFloat = x;
3394 event.p3.mFloat = y;
3396 mImpl->mEventData->mEventQueue.push_back( event );
3399 case RIGHT_SELECTION_HANDLE:
3401 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
3402 event.p1.mUint = state;
3403 event.p2.mFloat = x;
3404 event.p3.mFloat = y;
3406 mImpl->mEventData->mEventQueue.push_back( event );
3409 case LEFT_SELECTION_HANDLE_MARKER:
3410 case RIGHT_SELECTION_HANDLE_MARKER:
3412 // Markers do not move the handles.
3415 case HANDLE_TYPE_COUNT:
3417 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
3421 mImpl->RequestRelayout();
3425 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
3427 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
3429 if( NULL == mImpl->mEventData )
3436 case Toolkit::TextSelectionPopup::CUT:
3438 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
3439 mImpl->mOperationsPending = ALL_OPERATIONS;
3441 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3442 !mImpl->IsPlaceholderAvailable() )
3444 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3448 ShowPlaceholderText();
3451 mImpl->mEventData->mUpdateCursorPosition = true;
3452 mImpl->mEventData->mScrollAfterDelete = true;
3454 mImpl->RequestRelayout();
3456 if( NULL != mImpl->mEditableControlInterface )
3458 mImpl->mEditableControlInterface->TextChanged();
3462 case Toolkit::TextSelectionPopup::COPY:
3464 mImpl->SendSelectionToClipboard( false ); // Text not modified
3466 mImpl->mEventData->mUpdateCursorPosition = true;
3468 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
3471 case Toolkit::TextSelectionPopup::PASTE:
3473 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
3476 case Toolkit::TextSelectionPopup::SELECT:
3478 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
3480 if( mImpl->mEventData->mSelectionEnabled )
3482 // Creates a SELECT event.
3483 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, SelectionType::INTERACTIVE );
3487 case Toolkit::TextSelectionPopup::SELECT_ALL:
3489 // Creates a SELECT_ALL event
3490 SelectEvent( 0.f, 0.f, SelectionType::ALL );
3493 case Toolkit::TextSelectionPopup::CLIPBOARD:
3495 mImpl->ShowClipboard();
3498 case Toolkit::TextSelectionPopup::NONE:
3506 void Controller::DisplayTimeExpired()
3508 mImpl->mEventData->mUpdateCursorPosition = true;
3509 // Apply modifications to the model
3510 mImpl->mOperationsPending = ALL_OPERATIONS;
3512 mImpl->RequestRelayout();
3515 // private : Update.
3517 void Controller::InsertText( const std::string& text, Controller::InsertType type )
3519 bool removedPrevious = false;
3520 bool removedSelected = false;
3521 bool maxLengthReached = false;
3523 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
3525 if( NULL == mImpl->mEventData )
3530 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
3531 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
3532 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3534 // TODO: At the moment the underline runs are only for pre-edit.
3535 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
3537 // Remove the previous InputMethodContext pre-edit.
3538 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
3540 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
3541 mImpl->mEventData->mPreEditLength,
3542 DONT_UPDATE_INPUT_STYLE );
3544 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
3545 mImpl->mEventData->mPreEditLength = 0u;
3549 // Remove the previous Selection.
3550 removedSelected = RemoveSelectedText();
3554 Vector<Character> utf32Characters;
3555 Length characterCount = 0u;
3559 // Convert text into UTF-32
3560 utf32Characters.Resize( text.size() );
3562 // This is a bit horrible but std::string returns a (signed) char*
3563 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
3565 // Transform a text array encoded in utf8 into an array encoded in utf32.
3566 // It returns the actual number of characters.
3567 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
3568 utf32Characters.Resize( characterCount );
3570 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
3571 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
3574 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
3576 // The placeholder text is no longer needed
3577 if( mImpl->IsShowingPlaceholderText() )
3582 mImpl->ChangeState( EventData::EDITING );
3584 // Handle the InputMethodContext (predicitive text) state changes
3585 if( COMMIT == type )
3587 // InputMethodContext is no longer handling key-events
3588 mImpl->ClearPreEditFlag();
3592 if( !mImpl->mEventData->mPreEditFlag )
3594 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
3596 // Record the start of the pre-edit text
3597 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
3600 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
3601 mImpl->mEventData->mPreEditFlag = true;
3603 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3606 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
3608 // Restrict new text to fit within Maximum characters setting.
3609 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
3610 maxLengthReached = ( characterCount > maxSizeOfNewText );
3612 // The cursor position.
3613 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3615 // Update the text's style.
3617 // Updates the text style runs by adding characters.
3618 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
3620 // Get the character index from the cursor index.
3621 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
3623 // Retrieve the text's style for the given index.
3625 mImpl->RetrieveDefaultInputStyle( style );
3626 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
3628 // Whether to add a new text color run.
3629 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor ) && !mImpl->mEventData->mInputStyle.isDefaultColor;
3631 // Whether to add a new font run.
3632 const bool addFontNameRun = ( style.familyName != mImpl->mEventData->mInputStyle.familyName ) && mImpl->mEventData->mInputStyle.isFamilyDefined;
3633 const bool addFontWeightRun = ( style.weight != mImpl->mEventData->mInputStyle.weight ) && mImpl->mEventData->mInputStyle.isWeightDefined;
3634 const bool addFontWidthRun = ( style.width != mImpl->mEventData->mInputStyle.width ) && mImpl->mEventData->mInputStyle.isWidthDefined;
3635 const bool addFontSlantRun = ( style.slant != mImpl->mEventData->mInputStyle.slant ) && mImpl->mEventData->mInputStyle.isSlantDefined;
3636 const bool addFontSizeRun = ( style.size != mImpl->mEventData->mInputStyle.size ) && mImpl->mEventData->mInputStyle.isSizeDefined ;
3641 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
3642 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
3644 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
3645 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
3646 colorRun.characterRun.characterIndex = cursorIndex;
3647 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3650 if( addFontNameRun ||
3656 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
3657 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
3659 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
3661 if( addFontNameRun )
3663 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
3664 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
3665 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
3666 fontDescriptionRun.familyDefined = true;
3668 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
3671 if( addFontWeightRun )
3673 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
3674 fontDescriptionRun.weightDefined = true;
3677 if( addFontWidthRun )
3679 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
3680 fontDescriptionRun.widthDefined = true;
3683 if( addFontSlantRun )
3685 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
3686 fontDescriptionRun.slantDefined = true;
3689 if( addFontSizeRun )
3691 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
3692 fontDescriptionRun.sizeDefined = true;
3695 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
3696 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3699 // Insert at current cursor position.
3700 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
3702 if( cursorIndex < numberOfCharactersInModel )
3704 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3708 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3711 // Mark the first paragraph to be updated.
3712 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3714 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3715 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3716 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
3717 mImpl->mTextUpdateInfo.mClearAll = true;
3721 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3722 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
3725 // Update the cursor index.
3726 cursorIndex += maxSizeOfNewText;
3728 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 );
3731 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
3732 mImpl->IsPlaceholderAvailable() )
3734 // Show place-holder if empty after removing the pre-edit text
3735 ShowPlaceholderText();
3736 mImpl->mEventData->mUpdateCursorPosition = true;
3737 mImpl->ClearPreEditFlag();
3739 else if( removedPrevious ||
3741 ( 0 != utf32Characters.Count() ) )
3743 // Queue an inserted event
3744 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
3746 mImpl->mEventData->mUpdateCursorPosition = true;
3747 if( removedSelected )
3749 mImpl->mEventData->mScrollAfterDelete = true;
3753 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3757 if( maxLengthReached )
3759 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
3761 mImpl->ResetInputMethodContext();
3763 if( NULL != mImpl->mEditableControlInterface )
3765 // Do this last since it provides callbacks into application code
3766 mImpl->mEditableControlInterface->MaxLengthReached();
3771 void Controller::PasteText( const std::string& stringToPaste )
3773 InsertText( stringToPaste, Text::Controller::COMMIT );
3774 mImpl->ChangeState( EventData::EDITING );
3775 mImpl->RequestRelayout();
3777 if( NULL != mImpl->mEditableControlInterface )
3779 // Do this last since it provides callbacks into application code
3780 mImpl->mEditableControlInterface->TextChanged();
3784 bool Controller::RemoveText( int cursorOffset,
3785 int numberOfCharacters,
3786 UpdateInputStyleType type )
3788 bool removed = false;
3790 if( NULL == mImpl->mEventData )
3795 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
3796 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
3798 if( !mImpl->IsShowingPlaceholderText() )
3800 // Delete at current cursor position
3801 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
3802 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3804 CharacterIndex cursorIndex = 0;
3806 // Validate the cursor position & number of characters
3807 if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
3809 cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
3812 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
3814 numberOfCharacters = currentText.Count() - cursorIndex;
3817 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.
3818 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
3820 // Mark the paragraphs to be updated.
3821 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3823 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3824 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3825 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
3826 mImpl->mTextUpdateInfo.mClearAll = true;
3830 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3831 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
3834 // Update the input style and remove the text's style before removing the text.
3836 if( UPDATE_INPUT_STYLE == type )
3838 // Keep a copy of the current input style.
3839 InputStyle currentInputStyle;
3840 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
3842 // Set first the default input style.
3843 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
3845 // Update the input style.
3846 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
3848 // Compare if the input style has changed.
3849 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
3851 if( hasInputStyleChanged )
3853 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
3854 // Queue the input style changed signal.
3855 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
3859 // If the number of current text and the number of characters to be deleted are same,
3860 // it means all texts should be removed and all Preedit variables should be initialized.
3861 if( ( currentText.Count() - numberOfCharacters == 0 ) && ( cursorIndex == 0 ) )
3863 mImpl->ClearPreEditFlag();
3864 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0;
3867 // Updates the text style runs by removing characters. Runs with no characters are removed.
3868 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
3870 // Remove the characters.
3871 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
3872 Vector<Character>::Iterator last = first + numberOfCharacters;
3874 currentText.Erase( first, last );
3876 // Cursor position retreat
3877 oldCursorIndex = cursorIndex;
3879 mImpl->mEventData->mScrollAfterDelete = true;
3881 if( EventData::INACTIVE == mImpl->mEventData->mState )
3883 mImpl->ChangeState( EventData::EDITING );
3886 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
3894 bool Controller::RemoveSelectedText()
3896 bool textRemoved( false );
3898 if( EventData::SELECTING == mImpl->mEventData->mState )
3900 std::string removedString;
3901 mImpl->RetrieveSelection( removedString, true );
3903 if( !removedString.empty() )
3906 mImpl->ChangeState( EventData::EDITING );
3913 std::string Controller::GetSelectedText()
3916 if( EventData::SELECTING == mImpl->mEventData->mState )
3918 mImpl->RetrieveSelection( text, false );
3923 // private : Relayout.
3925 bool Controller::DoRelayout( const Size& size,
3926 OperationsMask operationsRequired,
3929 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
3930 bool viewUpdated( false );
3932 // Calculate the operations to be done.
3933 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
3935 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
3936 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
3938 // Get the current layout size.
3939 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3941 if( NO_OPERATION != ( LAYOUT & operations ) )
3943 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
3945 // Some vectors with data needed to layout and reorder may be void
3946 // after the first time the text has been laid out.
3947 // Fill the vectors again.
3949 // Calculate the number of glyphs to layout.
3950 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
3951 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
3952 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
3953 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
3955 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
3956 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
3958 // Make sure the index is not out of bound
3959 if ( charactersToGlyph.Count() != glyphsPerCharacter.Count() ||
3960 requestedNumberOfCharacters > charactersToGlyph.Count() ||
3961 ( lastIndex > charactersToGlyph.Count() && charactersToGlyph.Count() > 0u ) )
3963 std::string currentText;
3964 GetText( currentText );
3966 DALI_LOG_ERROR( "Controller::DoRelayout: Attempting to access invalid buffer\n" );
3967 DALI_LOG_ERROR( "Current text is: %s\n", currentText.c_str() );
3968 DALI_LOG_ERROR( "startIndex: %u, lastIndex: %u, requestedNumberOfCharacters: %u, charactersToGlyph.Count = %lu, glyphsPerCharacter.Count = %lu\n", startIndex, lastIndex, requestedNumberOfCharacters, charactersToGlyph.Count(), glyphsPerCharacter.Count());
3973 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
3974 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
3976 if( 0u == totalNumberOfGlyphs )
3978 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3980 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
3983 // Nothing else to do if there is no glyphs.
3984 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
3988 // Set the layout parameters.
3989 Layout::Parameters layoutParameters( size,
3992 // Resize the vector of positions to have the same size than the vector of glyphs.
3993 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
3994 glyphPositions.Resize( totalNumberOfGlyphs );
3996 // Whether the last character is a new paragraph character.
3997 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
3998 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
3999 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
4001 // The initial glyph and the number of glyphs to layout.
4002 layoutParameters.startGlyphIndex = startGlyphIndex;
4003 layoutParameters.numberOfGlyphs = numberOfGlyphs;
4004 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
4005 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
4007 // Update the ellipsis
4008 bool elideTextEnabled = mImpl->mModel->mElideEnabled;
4010 if( NULL != mImpl->mEventData )
4012 if( mImpl->mEventData->mPlaceholderEllipsisFlag && mImpl->IsShowingPlaceholderText() )
4014 elideTextEnabled = mImpl->mEventData->mIsPlaceholderElideEnabled;
4016 else if( EventData::INACTIVE != mImpl->mEventData->mState )
4018 // Disable ellipsis when editing
4019 elideTextEnabled = false;
4022 // Reset the scroll position in inactive state
4023 if( elideTextEnabled && ( mImpl->mEventData->mState == EventData::INACTIVE ) )
4025 ResetScrollPosition();
4029 // Update the visual model.
4030 bool isAutoScrollEnabled = mImpl->mIsAutoScrollEnabled;
4032 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
4035 isAutoScrollEnabled );
4036 mImpl->mIsAutoScrollEnabled = isAutoScrollEnabled;
4038 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
4042 layoutSize = newLayoutSize;
4044 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
4046 mImpl->mIsTextDirectionRTL = false;
4049 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && !mImpl->mModel->mVisualModel->mLines.Empty() )
4051 mImpl->mIsTextDirectionRTL = mImpl->mModel->mVisualModel->mLines[0u].direction;
4054 // Sets the layout size.
4055 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
4057 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
4062 if( NO_OPERATION != ( ALIGN & operations ) )
4064 // The laid-out lines.
4065 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
4067 CharacterIndex alignStartIndex = startIndex;
4068 Length alignRequestedNumberOfCharacters = requestedNumberOfCharacters;
4070 // the whole text needs to be full aligned.
4071 // If you do not do a full aligned, only the last line of the multiline input is aligned.
4072 if( mImpl->mEventData && mImpl->mEventData->mUpdateAlignment )
4074 alignStartIndex = 0u;
4075 alignRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
4076 mImpl->mEventData->mUpdateAlignment = false;
4079 // Need to align with the control's size as the text may contain lines
4080 // starting either with left to right text or right to left.
4081 mImpl->mLayoutEngine.Align( size,
4083 alignRequestedNumberOfCharacters,
4084 mImpl->mModel->mHorizontalAlignment,
4086 mImpl->mModel->mAlignmentOffset,
4087 mImpl->mLayoutDirection,
4088 mImpl->mModel->mMatchSystemLanguageDirection );
4092 #if defined(DEBUG_ENABLED)
4093 std::string currentText;
4094 GetText( currentText );
4095 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mIsTextDirectionRTL[%s] [%s]\n", this, (mImpl->mIsTextDirectionRTL)?"true":"false", currentText.c_str() );
4097 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
4101 void Controller::CalculateVerticalOffset( const Size& controlSize )
4103 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
4105 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
4107 // Get the line height of the default font.
4108 layoutSize.height = mImpl->GetDefaultFontLineHeight();
4111 switch( mImpl->mModel->mVerticalAlignment )
4113 case VerticalAlignment::TOP:
4115 mImpl->mModel->mScrollPosition.y = 0.f;
4118 case VerticalAlignment::CENTER:
4120 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
4123 case VerticalAlignment::BOTTOM:
4125 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
4131 // private : Events.
4133 void Controller::ProcessModifyEvents()
4135 Vector<ModifyEvent>& events = mImpl->mModifyEvents;
4137 if( 0u == events.Count() )
4143 for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
4144 endIt = events.End();
4148 const ModifyEvent& event = *it;
4150 if( ModifyEvent::TEXT_REPLACED == event.type )
4152 // A (single) replace event should come first, otherwise we wasted time processing NOOP events
4153 DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
4155 TextReplacedEvent();
4157 else if( ModifyEvent::TEXT_INSERTED == event.type )
4159 TextInsertedEvent();
4161 else if( ModifyEvent::TEXT_DELETED == event.type )
4163 // Placeholder-text cannot be deleted
4164 if( !mImpl->IsShowingPlaceholderText() )
4171 if( NULL != mImpl->mEventData )
4173 // When the text is being modified, delay cursor blinking
4174 mImpl->mEventData->mDecorator->DelayCursorBlink();
4176 // Update selection position after modifying the text
4177 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
4178 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
4181 // DISCARD temporary text
4185 void Controller::TextReplacedEvent()
4187 // The natural size needs to be re-calculated.
4188 mImpl->mRecalculateNaturalSize = true;
4190 // The text direction needs to be updated.
4191 mImpl->mUpdateTextDirection = true;
4193 // Apply modifications to the model
4194 mImpl->mOperationsPending = ALL_OPERATIONS;
4197 void Controller::TextInsertedEvent()
4199 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
4201 if( NULL == mImpl->mEventData )
4206 mImpl->mEventData->mCheckScrollAmount = true;
4208 // The natural size needs to be re-calculated.
4209 mImpl->mRecalculateNaturalSize = true;
4211 // The text direction needs to be updated.
4212 mImpl->mUpdateTextDirection = true;
4214 // Apply modifications to the model; TODO - Optimize this
4215 mImpl->mOperationsPending = ALL_OPERATIONS;
4218 void Controller::TextDeletedEvent()
4220 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
4222 if( NULL == mImpl->mEventData )
4227 mImpl->mEventData->mCheckScrollAmount = true;
4229 // The natural size needs to be re-calculated.
4230 mImpl->mRecalculateNaturalSize = true;
4232 // The text direction needs to be updated.
4233 mImpl->mUpdateTextDirection = true;
4235 // Apply modifications to the model; TODO - Optimize this
4236 mImpl->mOperationsPending = ALL_OPERATIONS;
4239 bool Controller::DeleteEvent( int keyCode )
4241 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p KeyCode : %d \n", this, keyCode );
4243 bool removed = false;
4245 if( NULL == mImpl->mEventData )
4250 // InputMethodContext is no longer handling key-events
4251 mImpl->ClearPreEditFlag();
4253 if( EventData::SELECTING == mImpl->mEventData->mState )
4255 removed = RemoveSelectedText();
4257 else if( ( mImpl->mEventData->mPrimaryCursorPosition > 0 ) && ( keyCode == Dali::DALI_KEY_BACKSPACE) )
4259 // Remove the character before the current cursor position
4260 removed = RemoveText( -1,
4262 UPDATE_INPUT_STYLE );
4264 else if( keyCode == Dali::DevelKey::DALI_KEY_DELETE )
4266 // Remove the character after the current cursor position
4267 removed = RemoveText( 0,
4269 UPDATE_INPUT_STYLE );
4274 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
4275 !mImpl->IsPlaceholderAvailable() )
4277 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
4281 ShowPlaceholderText();
4283 mImpl->mEventData->mUpdateCursorPosition = true;
4284 mImpl->mEventData->mScrollAfterDelete = true;
4290 // private : Helpers.
4292 void Controller::ResetText()
4295 mImpl->mModel->mLogicalModel->mText.Clear();
4297 // Reset the embedded images buffer.
4298 mImpl->mModel->mLogicalModel->ClearEmbeddedImages();
4300 // We have cleared everything including the placeholder-text
4301 mImpl->PlaceholderCleared();
4303 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4304 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4305 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
4307 // Clear any previous text.
4308 mImpl->mTextUpdateInfo.mClearAll = true;
4310 // The natural size needs to be re-calculated.
4311 mImpl->mRecalculateNaturalSize = true;
4313 // The text direction needs to be updated.
4314 mImpl->mUpdateTextDirection = true;
4316 // Apply modifications to the model
4317 mImpl->mOperationsPending = ALL_OPERATIONS;
4320 void Controller::ShowPlaceholderText()
4322 if( mImpl->IsPlaceholderAvailable() )
4324 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
4326 if( NULL == mImpl->mEventData )
4331 mImpl->mEventData->mIsShowingPlaceholderText = true;
4333 // Disable handles when showing place-holder text
4334 mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
4335 mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
4336 mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
4338 const char* text( NULL );
4341 // TODO - Switch Placeholder text when changing state
4342 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
4343 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
4345 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
4346 size = mImpl->mEventData->mPlaceholderTextActive.size();
4350 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
4351 size = mImpl->mEventData->mPlaceholderTextInactive.size();
4354 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4355 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4357 // Reset model for showing placeholder.
4358 mImpl->mModel->mLogicalModel->mText.Clear();
4359 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
4361 // Convert text into UTF-32
4362 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
4363 utf32Characters.Resize( size );
4365 // This is a bit horrible but std::string returns a (signed) char*
4366 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
4368 // Transform a text array encoded in utf8 into an array encoded in utf32.
4369 // It returns the actual number of characters.
4370 const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
4371 utf32Characters.Resize( characterCount );
4373 // The characters to be added.
4374 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
4376 // Reset the cursor position
4377 mImpl->mEventData->mPrimaryCursorPosition = 0;
4379 // The natural size needs to be re-calculated.
4380 mImpl->mRecalculateNaturalSize = true;
4382 // The text direction needs to be updated.
4383 mImpl->mUpdateTextDirection = true;
4385 // Apply modifications to the model
4386 mImpl->mOperationsPending = ALL_OPERATIONS;
4388 // Update the rest of the model during size negotiation
4389 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
4393 void Controller::ClearFontData()
4395 if( mImpl->mFontDefaults )
4397 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
4400 // Set flags to update the model.
4401 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4402 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4403 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
4405 mImpl->mTextUpdateInfo.mClearAll = true;
4406 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
4407 mImpl->mRecalculateNaturalSize = true;
4409 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
4415 UPDATE_LAYOUT_SIZE |
4420 void Controller::ClearStyleData()
4422 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
4423 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
4426 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
4428 // Reset the cursor position
4429 if( NULL != mImpl->mEventData )
4431 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
4433 // Update the cursor if it's in editing mode.
4434 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
4436 mImpl->mEventData->mUpdateCursorPosition = true;
4441 void Controller::ResetScrollPosition()
4443 if( NULL != mImpl->mEventData )
4445 // Reset the scroll position.
4446 mImpl->mModel->mScrollPosition = Vector2::ZERO;
4447 mImpl->mEventData->mScrollAfterUpdatePosition = true;
4451 void Controller::SetControlInterface( ControlInterface* controlInterface )
4453 mImpl->mControlInterface = controlInterface;
4456 bool Controller::ShouldClearFocusOnEscape() const
4458 return mImpl->mShouldClearFocusOnEscape;
4461 Actor Controller::CreateBackgroundActor()
4463 return mImpl->CreateBackgroundActor();
4466 // private : Private contructors & copy operator.
4468 Controller::Controller()
4471 mImpl = new Controller::Impl( nullptr, nullptr, nullptr );
4474 Controller::Controller( ControlInterface* controlInterface )
4476 mImpl = new Controller::Impl( controlInterface, NULL, NULL );
4479 Controller::Controller( ControlInterface* controlInterface,
4480 EditableControlInterface* editableControlInterface,
4481 SelectableControlInterface* selectableControlInterface )
4483 mImpl = new Controller::Impl( controlInterface,
4484 editableControlInterface,
4485 selectableControlInterface );
4488 // The copy constructor and operator are left unimplemented.
4490 // protected : Destructor.
4492 Controller::~Controller()
4499 } // namespace Toolkit