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() );
2978 if (!IsEditable()) return false;
2980 if( !keyString.empty() )
2982 // InputMethodContext is no longer handling key-events
2983 mImpl->ClearPreEditFlag();
2985 InsertText( keyString, COMMIT );
2989 // Will request for relayout.
2990 relayoutNeeded = true;
2995 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
2996 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
2998 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
2999 ( Dali::DALI_KEY_SHIFT_RIGHT != keyCode ) &&
3000 ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
3001 ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
3003 // Should not change the state if the key is the shift send by the InputMethodContext.
3004 // Otherwise, when the state is SELECTING the text controller can't send the right
3005 // surrounding info to the InputMethodContext.
3006 mImpl->ChangeState( EventData::EDITING );
3008 // Will request for relayout.
3009 relayoutNeeded = true;
3012 if( relayoutNeeded )
3014 mImpl->RequestRelayout();
3019 ( NULL != mImpl->mEditableControlInterface ) )
3021 // Do this last since it provides callbacks into application code
3022 mImpl->mEditableControlInterface->TextChanged();
3028 void Controller::TapEvent( unsigned int tapCount, float x, float y )
3030 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
3032 if( NULL != mImpl->mEventData )
3034 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
3035 EventData::State state( mImpl->mEventData->mState );
3036 bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
3038 if( mImpl->IsClipboardVisible() )
3040 if( EventData::INACTIVE == state || EventData::EDITING == state)
3042 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
3044 relayoutNeeded = true;
3046 else if( 1u == tapCount )
3048 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
3050 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
3053 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
3055 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
3056 relayoutNeeded = true;
3060 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
3062 // Hide placeholder text
3066 if( EventData::INACTIVE == state )
3068 mImpl->ChangeState( EventData::EDITING );
3070 else if( !mImpl->IsClipboardEmpty() )
3072 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
3074 relayoutNeeded = true;
3077 else if( 2u == tapCount )
3079 if( mImpl->mEventData->mSelectionEnabled &&
3080 mImpl->IsShowingRealText() )
3082 relayoutNeeded = true;
3083 mImpl->mEventData->mIsLeftHandleSelected = true;
3084 mImpl->mEventData->mIsRightHandleSelected = true;
3088 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
3089 if( relayoutNeeded )
3091 Event event( Event::TAP_EVENT );
3092 event.p1.mUint = tapCount;
3093 event.p2.mFloat = x;
3094 event.p3.mFloat = y;
3095 mImpl->mEventData->mEventQueue.push_back( event );
3097 mImpl->RequestRelayout();
3101 // Reset keyboard as tap event has occurred.
3102 mImpl->ResetInputMethodContext();
3105 void Controller::PanEvent( GestureState state, const Vector2& displacement )
3107 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
3109 if( NULL != mImpl->mEventData )
3111 Event event( Event::PAN_EVENT );
3112 event.p1.mInt = static_cast<int>( state );
3113 event.p2.mFloat = displacement.x;
3114 event.p3.mFloat = displacement.y;
3115 mImpl->mEventData->mEventQueue.push_back( event );
3117 mImpl->RequestRelayout();
3121 void Controller::LongPressEvent( GestureState state, float x, float y )
3123 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
3125 if( ( state == GestureState::STARTED ) &&
3126 ( NULL != mImpl->mEventData ) )
3128 // The 1st long-press on inactive text-field is treated as tap
3129 if( EventData::INACTIVE == mImpl->mEventData->mState )
3131 mImpl->ChangeState( EventData::EDITING );
3133 Event event( Event::TAP_EVENT );
3135 event.p2.mFloat = x;
3136 event.p3.mFloat = y;
3137 mImpl->mEventData->mEventQueue.push_back( event );
3139 mImpl->RequestRelayout();
3141 else if( !mImpl->IsShowingRealText() )
3143 Event event( Event::LONG_PRESS_EVENT );
3144 event.p1.mInt = static_cast<int>( state );
3145 event.p2.mFloat = x;
3146 event.p3.mFloat = y;
3147 mImpl->mEventData->mEventQueue.push_back( event );
3148 mImpl->RequestRelayout();
3150 else if( !mImpl->IsClipboardVisible() )
3152 // Reset the InputMethodContext to commit the pre-edit before selecting the text.
3153 mImpl->ResetInputMethodContext();
3155 Event event( Event::LONG_PRESS_EVENT );
3156 event.p1.mInt = static_cast<int>( state );
3157 event.p2.mFloat = x;
3158 event.p3.mFloat = y;
3159 mImpl->mEventData->mEventQueue.push_back( event );
3160 mImpl->RequestRelayout();
3162 mImpl->mEventData->mIsLeftHandleSelected = true;
3163 mImpl->mEventData->mIsRightHandleSelected = true;
3168 void Controller::SelectEvent( float x, float y, SelectionType selectType )
3170 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
3172 if( NULL != mImpl->mEventData )
3174 if( selectType == SelectionType::ALL )
3176 Event event( Event::SELECT_ALL );
3177 mImpl->mEventData->mEventQueue.push_back( event );
3179 else if( selectType == SelectionType::NONE )
3181 Event event( Event::SELECT_NONE );
3182 mImpl->mEventData->mEventQueue.push_back( event );
3186 Event event( Event::SELECT );
3187 event.p2.mFloat = x;
3188 event.p3.mFloat = y;
3189 mImpl->mEventData->mEventQueue.push_back( event );
3192 mImpl->mEventData->mCheckScrollAmount = true;
3193 mImpl->mEventData->mIsLeftHandleSelected = true;
3194 mImpl->mEventData->mIsRightHandleSelected = true;
3195 mImpl->RequestRelayout();
3199 void Controller::SetTextSelectionRange(const uint32_t *start, const uint32_t *end)
3201 if( mImpl->mEventData )
3203 mImpl->mEventData->mCheckScrollAmount = true;
3204 mImpl->mEventData->mIsLeftHandleSelected = true;
3205 mImpl->mEventData->mIsRightHandleSelected = true;
3206 mImpl->SetTextSelectionRange(start, end);
3207 mImpl->RequestRelayout();
3208 KeyboardFocusGainEvent();
3212 Uint32Pair Controller::GetTextSelectionRange() const
3214 return mImpl->GetTextSelectionRange();
3217 InputMethodContext::CallbackData Controller::OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
3219 // Whether the text needs to be relaid-out.
3220 bool requestRelayout = false;
3222 // Whether to retrieve the text and cursor position to be sent to the InputMethodContext.
3223 bool retrieveText = false;
3224 bool retrieveCursor = false;
3226 switch( inputMethodContextEvent.eventName )
3228 case InputMethodContext::COMMIT:
3230 InsertText( inputMethodContextEvent.predictiveString, Text::Controller::COMMIT );
3231 requestRelayout = true;
3232 retrieveCursor = true;
3235 case InputMethodContext::PRE_EDIT:
3237 InsertText( inputMethodContextEvent.predictiveString, Text::Controller::PRE_EDIT );
3238 requestRelayout = true;
3239 retrieveCursor = true;
3242 case InputMethodContext::DELETE_SURROUNDING:
3244 const bool textDeleted = RemoveText( inputMethodContextEvent.cursorOffset,
3245 inputMethodContextEvent.numberOfChars,
3246 DONT_UPDATE_INPUT_STYLE );
3250 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3251 !mImpl->IsPlaceholderAvailable() )
3253 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3257 ShowPlaceholderText();
3259 mImpl->mEventData->mUpdateCursorPosition = true;
3260 mImpl->mEventData->mScrollAfterDelete = true;
3262 requestRelayout = true;
3266 case InputMethodContext::GET_SURROUNDING:
3268 retrieveText = true;
3269 retrieveCursor = true;
3272 case InputMethodContext::PRIVATE_COMMAND:
3274 // PRIVATECOMMAND event is just for getting the private command message
3275 retrieveText = true;
3276 retrieveCursor = true;
3279 case InputMethodContext::VOID:
3286 if( requestRelayout )
3288 mImpl->mOperationsPending = ALL_OPERATIONS;
3289 mImpl->RequestRelayout();
3293 CharacterIndex cursorPosition = 0u;
3294 Length numberOfWhiteSpaces = 0u;
3296 if( retrieveCursor )
3298 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
3300 cursorPosition = mImpl->GetLogicalCursorPosition();
3302 if( cursorPosition < numberOfWhiteSpaces )
3304 cursorPosition = 0u;
3308 cursorPosition -= numberOfWhiteSpaces;
3314 if( !mImpl->IsShowingPlaceholderText() )
3316 // Retrieves the normal text string.
3317 mImpl->GetText( numberOfWhiteSpaces, text );
3321 // When the current text is Placeholder Text, the surrounding text should be empty string.
3322 // It means DALi should send empty string ("") to IME.
3327 InputMethodContext::CallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
3329 if( requestRelayout &&
3330 ( NULL != mImpl->mEditableControlInterface ) )
3332 // Do this last since it provides callbacks into application code
3333 mImpl->mEditableControlInterface->TextChanged();
3336 return callbackData;
3339 void Controller::PasteClipboardItemEvent()
3341 // Retrieve the clipboard contents first
3342 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
3343 std::string stringToPaste( notifier.GetContent() );
3345 // Commit the current pre-edit text; the contents of the clipboard should be appended
3346 mImpl->ResetInputMethodContext();
3348 // Temporary disable hiding clipboard
3349 mImpl->SetClipboardHideEnable( false );
3352 PasteText( stringToPaste );
3354 mImpl->SetClipboardHideEnable( true );
3357 // protected : Inherit from Text::Decorator::ControllerInterface.
3359 void Controller::GetTargetSize( Vector2& targetSize )
3361 targetSize = mImpl->mModel->mVisualModel->mControlSize;
3364 void Controller::AddDecoration( Actor& actor, bool needsClipping )
3366 if( NULL != mImpl->mEditableControlInterface )
3368 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
3372 bool Controller::IsEditable() const
3374 return mImpl->IsEditable();
3377 void Controller::SetEditable( bool editable )
3379 mImpl->SetEditable( editable );
3380 if(mImpl->mEventData && mImpl->mEventData->mDecorator)
3382 mImpl->mEventData->mDecorator->SetEditable( editable );
3386 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
3388 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
3390 if( NULL != mImpl->mEventData )
3392 switch( handleType )
3396 Event event( Event::GRAB_HANDLE_EVENT );
3397 event.p1.mUint = state;
3398 event.p2.mFloat = x;
3399 event.p3.mFloat = y;
3401 mImpl->mEventData->mEventQueue.push_back( event );
3404 case LEFT_SELECTION_HANDLE:
3406 Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
3407 event.p1.mUint = state;
3408 event.p2.mFloat = x;
3409 event.p3.mFloat = y;
3411 mImpl->mEventData->mEventQueue.push_back( event );
3414 case RIGHT_SELECTION_HANDLE:
3416 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
3417 event.p1.mUint = state;
3418 event.p2.mFloat = x;
3419 event.p3.mFloat = y;
3421 mImpl->mEventData->mEventQueue.push_back( event );
3424 case LEFT_SELECTION_HANDLE_MARKER:
3425 case RIGHT_SELECTION_HANDLE_MARKER:
3427 // Markers do not move the handles.
3430 case HANDLE_TYPE_COUNT:
3432 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
3436 mImpl->RequestRelayout();
3440 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
3442 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
3444 if( NULL == mImpl->mEventData )
3451 case Toolkit::TextSelectionPopup::CUT:
3453 if (!IsEditable()) return;
3454 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
3455 mImpl->mOperationsPending = ALL_OPERATIONS;
3457 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3458 !mImpl->IsPlaceholderAvailable() )
3460 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3464 ShowPlaceholderText();
3467 mImpl->mEventData->mUpdateCursorPosition = true;
3468 mImpl->mEventData->mScrollAfterDelete = true;
3470 mImpl->RequestRelayout();
3472 if( NULL != mImpl->mEditableControlInterface )
3474 mImpl->mEditableControlInterface->TextChanged();
3478 case Toolkit::TextSelectionPopup::COPY:
3480 mImpl->SendSelectionToClipboard( false ); // Text not modified
3482 mImpl->mEventData->mUpdateCursorPosition = true;
3484 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
3487 case Toolkit::TextSelectionPopup::PASTE:
3489 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
3492 case Toolkit::TextSelectionPopup::SELECT:
3494 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
3496 if( mImpl->mEventData->mSelectionEnabled )
3498 // Creates a SELECT event.
3499 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, SelectionType::INTERACTIVE );
3503 case Toolkit::TextSelectionPopup::SELECT_ALL:
3505 // Creates a SELECT_ALL event
3506 SelectEvent( 0.f, 0.f, SelectionType::ALL );
3509 case Toolkit::TextSelectionPopup::CLIPBOARD:
3511 mImpl->ShowClipboard();
3514 case Toolkit::TextSelectionPopup::NONE:
3522 void Controller::DisplayTimeExpired()
3524 mImpl->mEventData->mUpdateCursorPosition = true;
3525 // Apply modifications to the model
3526 mImpl->mOperationsPending = ALL_OPERATIONS;
3528 mImpl->RequestRelayout();
3531 // private : Update.
3533 void Controller::InsertText( const std::string& text, Controller::InsertType type )
3535 bool removedPrevious = false;
3536 bool removedSelected = false;
3537 bool maxLengthReached = false;
3539 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
3541 if( NULL == mImpl->mEventData )
3546 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
3547 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
3548 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3550 // TODO: At the moment the underline runs are only for pre-edit.
3551 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
3553 // Remove the previous InputMethodContext pre-edit.
3554 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
3556 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
3557 mImpl->mEventData->mPreEditLength,
3558 DONT_UPDATE_INPUT_STYLE );
3560 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
3561 mImpl->mEventData->mPreEditLength = 0u;
3565 // Remove the previous Selection.
3566 removedSelected = RemoveSelectedText();
3570 Vector<Character> utf32Characters;
3571 Length characterCount = 0u;
3575 // Convert text into UTF-32
3576 utf32Characters.Resize( text.size() );
3578 // This is a bit horrible but std::string returns a (signed) char*
3579 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
3581 // Transform a text array encoded in utf8 into an array encoded in utf32.
3582 // It returns the actual number of characters.
3583 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
3584 utf32Characters.Resize( characterCount );
3586 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
3587 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
3590 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
3592 // The placeholder text is no longer needed
3593 if( mImpl->IsShowingPlaceholderText() )
3598 mImpl->ChangeState( EventData::EDITING );
3600 // Handle the InputMethodContext (predicitive text) state changes
3601 if( COMMIT == type )
3603 // InputMethodContext is no longer handling key-events
3604 mImpl->ClearPreEditFlag();
3608 if( !mImpl->mEventData->mPreEditFlag )
3610 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
3612 // Record the start of the pre-edit text
3613 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
3616 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
3617 mImpl->mEventData->mPreEditFlag = true;
3619 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3622 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
3624 // Restrict new text to fit within Maximum characters setting.
3625 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
3626 maxLengthReached = ( characterCount > maxSizeOfNewText );
3628 // The cursor position.
3629 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3631 // Update the text's style.
3633 // Updates the text style runs by adding characters.
3634 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
3636 // Get the character index from the cursor index.
3637 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
3639 // Retrieve the text's style for the given index.
3641 mImpl->RetrieveDefaultInputStyle( style );
3642 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
3644 // Whether to add a new text color run.
3645 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor ) && !mImpl->mEventData->mInputStyle.isDefaultColor;
3647 // Whether to add a new font run.
3648 const bool addFontNameRun = ( style.familyName != mImpl->mEventData->mInputStyle.familyName ) && mImpl->mEventData->mInputStyle.isFamilyDefined;
3649 const bool addFontWeightRun = ( style.weight != mImpl->mEventData->mInputStyle.weight ) && mImpl->mEventData->mInputStyle.isWeightDefined;
3650 const bool addFontWidthRun = ( style.width != mImpl->mEventData->mInputStyle.width ) && mImpl->mEventData->mInputStyle.isWidthDefined;
3651 const bool addFontSlantRun = ( style.slant != mImpl->mEventData->mInputStyle.slant ) && mImpl->mEventData->mInputStyle.isSlantDefined;
3652 const bool addFontSizeRun = ( style.size != mImpl->mEventData->mInputStyle.size ) && mImpl->mEventData->mInputStyle.isSizeDefined ;
3657 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
3658 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
3660 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
3661 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
3662 colorRun.characterRun.characterIndex = cursorIndex;
3663 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3666 if( addFontNameRun ||
3672 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
3673 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
3675 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
3677 if( addFontNameRun )
3679 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
3680 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
3681 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
3682 fontDescriptionRun.familyDefined = true;
3684 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
3687 if( addFontWeightRun )
3689 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
3690 fontDescriptionRun.weightDefined = true;
3693 if( addFontWidthRun )
3695 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
3696 fontDescriptionRun.widthDefined = true;
3699 if( addFontSlantRun )
3701 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
3702 fontDescriptionRun.slantDefined = true;
3705 if( addFontSizeRun )
3707 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
3708 fontDescriptionRun.sizeDefined = true;
3711 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
3712 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3715 // Insert at current cursor position.
3716 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
3718 if( cursorIndex < numberOfCharactersInModel )
3720 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3724 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3727 // Mark the first paragraph to be updated.
3728 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3730 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3731 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3732 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
3733 mImpl->mTextUpdateInfo.mClearAll = true;
3737 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3738 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
3741 // Update the cursor index.
3742 cursorIndex += maxSizeOfNewText;
3744 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 );
3747 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
3748 mImpl->IsPlaceholderAvailable() )
3750 // Show place-holder if empty after removing the pre-edit text
3751 ShowPlaceholderText();
3752 mImpl->mEventData->mUpdateCursorPosition = true;
3753 mImpl->ClearPreEditFlag();
3755 else if( removedPrevious ||
3757 ( 0 != utf32Characters.Count() ) )
3759 // Queue an inserted event
3760 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
3762 mImpl->mEventData->mUpdateCursorPosition = true;
3763 if( removedSelected )
3765 mImpl->mEventData->mScrollAfterDelete = true;
3769 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3773 if( maxLengthReached )
3775 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
3777 mImpl->ResetInputMethodContext();
3779 if( NULL != mImpl->mEditableControlInterface )
3781 // Do this last since it provides callbacks into application code
3782 mImpl->mEditableControlInterface->MaxLengthReached();
3787 void Controller::PasteText( const std::string& stringToPaste )
3789 InsertText( stringToPaste, Text::Controller::COMMIT );
3790 mImpl->ChangeState( EventData::EDITING );
3791 mImpl->RequestRelayout();
3793 if( NULL != mImpl->mEditableControlInterface )
3795 // Do this last since it provides callbacks into application code
3796 mImpl->mEditableControlInterface->TextChanged();
3800 bool Controller::RemoveText( int cursorOffset,
3801 int numberOfCharacters,
3802 UpdateInputStyleType type )
3804 bool removed = false;
3806 if( NULL == mImpl->mEventData )
3811 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
3812 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
3814 if( !mImpl->IsShowingPlaceholderText() )
3816 // Delete at current cursor position
3817 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
3818 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3820 CharacterIndex cursorIndex = 0;
3822 // Validate the cursor position & number of characters
3823 if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
3825 cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
3828 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
3830 numberOfCharacters = currentText.Count() - cursorIndex;
3833 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.
3834 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
3836 // Mark the paragraphs to be updated.
3837 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3839 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3840 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3841 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
3842 mImpl->mTextUpdateInfo.mClearAll = true;
3846 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3847 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
3850 // Update the input style and remove the text's style before removing the text.
3852 if( UPDATE_INPUT_STYLE == type )
3854 // Keep a copy of the current input style.
3855 InputStyle currentInputStyle;
3856 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
3858 // Set first the default input style.
3859 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
3861 // Update the input style.
3862 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
3864 // Compare if the input style has changed.
3865 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
3867 if( hasInputStyleChanged )
3869 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
3870 // Queue the input style changed signal.
3871 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
3875 // If the number of current text and the number of characters to be deleted are same,
3876 // it means all texts should be removed and all Preedit variables should be initialized.
3877 if( ( currentText.Count() - numberOfCharacters == 0 ) && ( cursorIndex == 0 ) )
3879 mImpl->ClearPreEditFlag();
3880 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0;
3883 // Updates the text style runs by removing characters. Runs with no characters are removed.
3884 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
3886 // Remove the characters.
3887 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
3888 Vector<Character>::Iterator last = first + numberOfCharacters;
3890 currentText.Erase( first, last );
3892 // Cursor position retreat
3893 oldCursorIndex = cursorIndex;
3895 mImpl->mEventData->mScrollAfterDelete = true;
3897 if( EventData::INACTIVE == mImpl->mEventData->mState )
3899 mImpl->ChangeState( EventData::EDITING );
3902 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
3910 bool Controller::RemoveSelectedText()
3912 bool textRemoved( false );
3914 if( EventData::SELECTING == mImpl->mEventData->mState )
3916 std::string removedString;
3917 mImpl->RetrieveSelection( removedString, true );
3919 if( !removedString.empty() )
3922 mImpl->ChangeState( EventData::EDITING );
3929 std::string Controller::GetSelectedText()
3932 if( EventData::SELECTING == mImpl->mEventData->mState )
3934 mImpl->RetrieveSelection( text, false );
3939 // private : Relayout.
3941 bool Controller::DoRelayout( const Size& size,
3942 OperationsMask operationsRequired,
3945 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
3946 bool viewUpdated( false );
3948 // Calculate the operations to be done.
3949 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
3951 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
3952 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
3954 // Get the current layout size.
3955 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3957 if( NO_OPERATION != ( LAYOUT & operations ) )
3959 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
3961 // Some vectors with data needed to layout and reorder may be void
3962 // after the first time the text has been laid out.
3963 // Fill the vectors again.
3965 // Calculate the number of glyphs to layout.
3966 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
3967 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
3968 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
3969 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
3971 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
3972 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
3974 // Make sure the index is not out of bound
3975 if ( charactersToGlyph.Count() != glyphsPerCharacter.Count() ||
3976 requestedNumberOfCharacters > charactersToGlyph.Count() ||
3977 ( lastIndex > charactersToGlyph.Count() && charactersToGlyph.Count() > 0u ) )
3979 std::string currentText;
3980 GetText( currentText );
3982 DALI_LOG_ERROR( "Controller::DoRelayout: Attempting to access invalid buffer\n" );
3983 DALI_LOG_ERROR( "Current text is: %s\n", currentText.c_str() );
3984 DALI_LOG_ERROR( "startIndex: %u, lastIndex: %u, requestedNumberOfCharacters: %u, charactersToGlyph.Count = %lu, glyphsPerCharacter.Count = %lu\n", startIndex, lastIndex, requestedNumberOfCharacters, charactersToGlyph.Count(), glyphsPerCharacter.Count());
3989 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
3990 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
3992 if( 0u == totalNumberOfGlyphs )
3994 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3996 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
3999 // Nothing else to do if there is no glyphs.
4000 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
4004 // Set the layout parameters.
4005 Layout::Parameters layoutParameters( size,
4008 // Resize the vector of positions to have the same size than the vector of glyphs.
4009 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
4010 glyphPositions.Resize( totalNumberOfGlyphs );
4012 // Whether the last character is a new paragraph character.
4013 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
4014 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
4015 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
4017 // The initial glyph and the number of glyphs to layout.
4018 layoutParameters.startGlyphIndex = startGlyphIndex;
4019 layoutParameters.numberOfGlyphs = numberOfGlyphs;
4020 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
4021 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
4023 // Update the ellipsis
4024 bool elideTextEnabled = mImpl->mModel->mElideEnabled;
4026 if( NULL != mImpl->mEventData )
4028 if( mImpl->mEventData->mPlaceholderEllipsisFlag && mImpl->IsShowingPlaceholderText() )
4030 elideTextEnabled = mImpl->mEventData->mIsPlaceholderElideEnabled;
4032 else if( EventData::INACTIVE != mImpl->mEventData->mState )
4034 // Disable ellipsis when editing
4035 elideTextEnabled = false;
4038 // Reset the scroll position in inactive state
4039 if( elideTextEnabled && ( mImpl->mEventData->mState == EventData::INACTIVE ) )
4041 ResetScrollPosition();
4045 // Update the visual model.
4046 bool isAutoScrollEnabled = mImpl->mIsAutoScrollEnabled;
4048 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
4051 isAutoScrollEnabled );
4052 mImpl->mIsAutoScrollEnabled = isAutoScrollEnabled;
4054 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
4058 layoutSize = newLayoutSize;
4060 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
4062 mImpl->mIsTextDirectionRTL = false;
4065 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && !mImpl->mModel->mVisualModel->mLines.Empty() )
4067 mImpl->mIsTextDirectionRTL = mImpl->mModel->mVisualModel->mLines[0u].direction;
4070 // Sets the layout size.
4071 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
4073 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
4078 if( NO_OPERATION != ( ALIGN & operations ) )
4080 // The laid-out lines.
4081 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
4083 CharacterIndex alignStartIndex = startIndex;
4084 Length alignRequestedNumberOfCharacters = requestedNumberOfCharacters;
4086 // the whole text needs to be full aligned.
4087 // If you do not do a full aligned, only the last line of the multiline input is aligned.
4088 if( mImpl->mEventData && mImpl->mEventData->mUpdateAlignment )
4090 alignStartIndex = 0u;
4091 alignRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
4092 mImpl->mEventData->mUpdateAlignment = false;
4095 // Need to align with the control's size as the text may contain lines
4096 // starting either with left to right text or right to left.
4097 mImpl->mLayoutEngine.Align( size,
4099 alignRequestedNumberOfCharacters,
4100 mImpl->mModel->mHorizontalAlignment,
4102 mImpl->mModel->mAlignmentOffset,
4103 mImpl->mLayoutDirection,
4104 mImpl->mModel->mMatchSystemLanguageDirection );
4108 #if defined(DEBUG_ENABLED)
4109 std::string currentText;
4110 GetText( currentText );
4111 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mIsTextDirectionRTL[%s] [%s]\n", this, (mImpl->mIsTextDirectionRTL)?"true":"false", currentText.c_str() );
4113 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
4117 void Controller::CalculateVerticalOffset( const Size& controlSize )
4119 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
4121 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
4123 // Get the line height of the default font.
4124 layoutSize.height = mImpl->GetDefaultFontLineHeight();
4127 switch( mImpl->mModel->mVerticalAlignment )
4129 case VerticalAlignment::TOP:
4131 mImpl->mModel->mScrollPosition.y = 0.f;
4134 case VerticalAlignment::CENTER:
4136 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
4139 case VerticalAlignment::BOTTOM:
4141 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
4147 // private : Events.
4149 void Controller::ProcessModifyEvents()
4151 Vector<ModifyEvent>& events = mImpl->mModifyEvents;
4153 if( 0u == events.Count() )
4159 for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
4160 endIt = events.End();
4164 const ModifyEvent& event = *it;
4166 if( ModifyEvent::TEXT_REPLACED == event.type )
4168 // A (single) replace event should come first, otherwise we wasted time processing NOOP events
4169 DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
4171 TextReplacedEvent();
4173 else if( ModifyEvent::TEXT_INSERTED == event.type )
4175 TextInsertedEvent();
4177 else if( ModifyEvent::TEXT_DELETED == event.type )
4179 // Placeholder-text cannot be deleted
4180 if( !mImpl->IsShowingPlaceholderText() )
4187 if( NULL != mImpl->mEventData )
4189 // When the text is being modified, delay cursor blinking
4190 mImpl->mEventData->mDecorator->DelayCursorBlink();
4192 // Update selection position after modifying the text
4193 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
4194 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
4197 // DISCARD temporary text
4201 void Controller::TextReplacedEvent()
4203 // The natural size needs to be re-calculated.
4204 mImpl->mRecalculateNaturalSize = true;
4206 // The text direction needs to be updated.
4207 mImpl->mUpdateTextDirection = true;
4209 // Apply modifications to the model
4210 mImpl->mOperationsPending = ALL_OPERATIONS;
4213 void Controller::TextInsertedEvent()
4215 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
4217 if( NULL == mImpl->mEventData )
4222 mImpl->mEventData->mCheckScrollAmount = true;
4224 // The natural size needs to be re-calculated.
4225 mImpl->mRecalculateNaturalSize = true;
4227 // The text direction needs to be updated.
4228 mImpl->mUpdateTextDirection = true;
4230 // Apply modifications to the model; TODO - Optimize this
4231 mImpl->mOperationsPending = ALL_OPERATIONS;
4234 void Controller::TextDeletedEvent()
4236 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
4238 if( NULL == mImpl->mEventData )
4243 if (!IsEditable()) return;
4245 mImpl->mEventData->mCheckScrollAmount = true;
4247 // The natural size needs to be re-calculated.
4248 mImpl->mRecalculateNaturalSize = true;
4250 // The text direction needs to be updated.
4251 mImpl->mUpdateTextDirection = true;
4253 // Apply modifications to the model; TODO - Optimize this
4254 mImpl->mOperationsPending = ALL_OPERATIONS;
4257 bool Controller::DeleteEvent( int keyCode )
4259 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p KeyCode : %d \n", this, keyCode );
4261 bool removed = false;
4263 if( NULL == mImpl->mEventData )
4268 if (!IsEditable()) return false;
4270 // InputMethodContext is no longer handling key-events
4271 mImpl->ClearPreEditFlag();
4273 if( EventData::SELECTING == mImpl->mEventData->mState )
4275 removed = RemoveSelectedText();
4277 else if( ( mImpl->mEventData->mPrimaryCursorPosition > 0 ) && ( keyCode == Dali::DALI_KEY_BACKSPACE) )
4279 // Remove the character before the current cursor position
4280 removed = RemoveText( -1,
4282 UPDATE_INPUT_STYLE );
4284 else if( keyCode == Dali::DevelKey::DALI_KEY_DELETE )
4286 // Remove the character after the current cursor position
4287 removed = RemoveText( 0,
4289 UPDATE_INPUT_STYLE );
4294 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
4295 !mImpl->IsPlaceholderAvailable() )
4297 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
4301 ShowPlaceholderText();
4303 mImpl->mEventData->mUpdateCursorPosition = true;
4304 mImpl->mEventData->mScrollAfterDelete = true;
4310 // private : Helpers.
4312 void Controller::ResetText()
4315 mImpl->mModel->mLogicalModel->mText.Clear();
4317 // Reset the embedded images buffer.
4318 mImpl->mModel->mLogicalModel->ClearEmbeddedImages();
4320 // We have cleared everything including the placeholder-text
4321 mImpl->PlaceholderCleared();
4323 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4324 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4325 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
4327 // Clear any previous text.
4328 mImpl->mTextUpdateInfo.mClearAll = true;
4330 // The natural size needs to be re-calculated.
4331 mImpl->mRecalculateNaturalSize = true;
4333 // The text direction needs to be updated.
4334 mImpl->mUpdateTextDirection = true;
4336 // Apply modifications to the model
4337 mImpl->mOperationsPending = ALL_OPERATIONS;
4340 void Controller::ShowPlaceholderText()
4342 if( mImpl->IsPlaceholderAvailable() )
4344 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
4346 if( NULL == mImpl->mEventData )
4351 mImpl->mEventData->mIsShowingPlaceholderText = true;
4353 // Disable handles when showing place-holder text
4354 mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
4355 mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
4356 mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
4358 const char* text( NULL );
4361 // TODO - Switch Placeholder text when changing state
4362 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
4363 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
4365 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
4366 size = mImpl->mEventData->mPlaceholderTextActive.size();
4370 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
4371 size = mImpl->mEventData->mPlaceholderTextInactive.size();
4374 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4375 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4377 // Reset model for showing placeholder.
4378 mImpl->mModel->mLogicalModel->mText.Clear();
4379 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
4381 // Convert text into UTF-32
4382 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
4383 utf32Characters.Resize( size );
4385 // This is a bit horrible but std::string returns a (signed) char*
4386 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
4388 // Transform a text array encoded in utf8 into an array encoded in utf32.
4389 // It returns the actual number of characters.
4390 const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
4391 utf32Characters.Resize( characterCount );
4393 // The characters to be added.
4394 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
4396 // Reset the cursor position
4397 mImpl->mEventData->mPrimaryCursorPosition = 0;
4399 // The natural size needs to be re-calculated.
4400 mImpl->mRecalculateNaturalSize = true;
4402 // The text direction needs to be updated.
4403 mImpl->mUpdateTextDirection = true;
4405 // Apply modifications to the model
4406 mImpl->mOperationsPending = ALL_OPERATIONS;
4408 // Update the rest of the model during size negotiation
4409 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
4413 void Controller::ClearFontData()
4415 if( mImpl->mFontDefaults )
4417 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
4420 // Set flags to update the model.
4421 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4422 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4423 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
4425 mImpl->mTextUpdateInfo.mClearAll = true;
4426 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
4427 mImpl->mRecalculateNaturalSize = true;
4429 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
4435 UPDATE_LAYOUT_SIZE |
4440 void Controller::ClearStyleData()
4442 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
4443 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
4446 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
4448 // Reset the cursor position
4449 if( NULL != mImpl->mEventData )
4451 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
4453 // Update the cursor if it's in editing mode.
4454 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
4456 mImpl->mEventData->mUpdateCursorPosition = true;
4461 void Controller::ResetScrollPosition()
4463 if( NULL != mImpl->mEventData )
4465 // Reset the scroll position.
4466 mImpl->mModel->mScrollPosition = Vector2::ZERO;
4467 mImpl->mEventData->mScrollAfterUpdatePosition = true;
4471 void Controller::SetControlInterface( ControlInterface* controlInterface )
4473 mImpl->mControlInterface = controlInterface;
4476 bool Controller::ShouldClearFocusOnEscape() const
4478 return mImpl->mShouldClearFocusOnEscape;
4481 Actor Controller::CreateBackgroundActor()
4483 return mImpl->CreateBackgroundActor();
4486 // private : Private contructors & copy operator.
4488 Controller::Controller()
4491 mImpl = new Controller::Impl( nullptr, nullptr, nullptr );
4494 Controller::Controller( ControlInterface* controlInterface )
4496 mImpl = new Controller::Impl( controlInterface, NULL, NULL );
4499 Controller::Controller( ControlInterface* controlInterface,
4500 EditableControlInterface* editableControlInterface,
4501 SelectableControlInterface* selectableControlInterface )
4503 mImpl = new Controller::Impl( controlInterface,
4504 editableControlInterface,
4505 selectableControlInterface );
4508 // The copy constructor and operator are left unimplemented.
4510 // protected : Destructor.
4512 Controller::~Controller()
4519 } // namespace Toolkit