2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/text/text-controller.h>
25 #include <dali/public-api/adaptor-framework/key.h>
26 #include <dali/integration-api/debug.h>
27 #include <dali/devel-api/adaptor-framework/clipboard-event-notifier.h>
28 #include <dali/devel-api/text-abstraction/font-client.h>
29 #include <dali/devel-api/adaptor-framework/key-devel.h>
32 #include <dali-toolkit/public-api/controls/text-controls/placeholder-properties.h>
33 #include <dali-toolkit/internal/text/bidirectional-support.h>
34 #include <dali-toolkit/internal/text/character-set-conversion.h>
35 #include <dali-toolkit/internal/text/layouts/layout-parameters.h>
36 #include <dali-toolkit/internal/text/markup-processor.h>
37 #include <dali-toolkit/internal/text/multi-language-support.h>
38 #include <dali-toolkit/internal/text/text-controller-impl.h>
39 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
40 #include <dali-toolkit/internal/text/text-font-style.h>
45 #if defined(DEBUG_ENABLED)
46 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
49 const float MAX_FLOAT = std::numeric_limits<float>::max();
51 const std::string EMPTY_STRING("");
53 const std::string KEY_C_NAME = "c";
54 const std::string KEY_V_NAME = "v";
55 const std::string KEY_X_NAME = "x";
57 const char * const PLACEHOLDER_TEXT = "text";
58 const char * const PLACEHOLDER_TEXT_FOCUSED = "textFocused";
59 const char * const PLACEHOLDER_COLOR = "color";
60 const char * const PLACEHOLDER_FONT_FAMILY = "fontFamily";
61 const char * const PLACEHOLDER_FONT_STYLE = "fontStyle";
62 const char * const PLACEHOLDER_POINT_SIZE = "pointSize";
63 const char * const PLACEHOLDER_PIXEL_SIZE = "pixelSize";
64 const char * const PLACEHOLDER_ELLIPSIS = "ellipsis";
65 const unsigned int MAX_TEXT_LENGTH = 1024u * 32u;
67 float ConvertToEven( float value )
69 int intValue(static_cast<int>( value ));
70 return static_cast<float>( intValue + ( intValue & 1 ) );
73 int ConvertPixelToPint( float pixel )
75 unsigned int horizontalDpi = 0u;
76 unsigned int verticalDpi = 0u;
77 Dali::TextAbstraction::FontClient fontClient = Dali::TextAbstraction::FontClient::Get();
78 fontClient.GetDpi( horizontalDpi, verticalDpi );
80 return ( pixel * 72.f ) / static_cast< float >( horizontalDpi );
96 * @brief Adds a new font description run for the selected text.
98 * The new font parameters are added after the call to this method.
100 * @param[in] eventData The event data pointer.
101 * @param[in] logicalModel The logical model where to add the new font description run.
102 * @param[out] startOfSelectedText Index to the first selected character.
103 * @param[out] lengthOfSelectedText Number of selected characters.
105 FontDescriptionRun& UpdateSelectionFontStyleRun( EventData* eventData,
106 LogicalModelPtr logicalModel,
107 CharacterIndex& startOfSelectedText,
108 Length& lengthOfSelectedText )
110 const bool handlesCrossed = eventData->mLeftSelectionPosition > eventData->mRightSelectionPosition;
112 // Get start and end position of selection
113 startOfSelectedText = handlesCrossed ? eventData->mRightSelectionPosition : eventData->mLeftSelectionPosition;
114 lengthOfSelectedText = ( handlesCrossed ? eventData->mLeftSelectionPosition : eventData->mRightSelectionPosition ) - startOfSelectedText;
117 const VectorBase::SizeType numberOfRuns = logicalModel->mFontDescriptionRuns.Count();
118 logicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
120 FontDescriptionRun& fontDescriptionRun = *( logicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
122 fontDescriptionRun.characterRun.characterIndex = startOfSelectedText;
123 fontDescriptionRun.characterRun.numberOfCharacters = lengthOfSelectedText;
125 // Recalculate the selection highlight as the metrics may have changed.
126 eventData->mUpdateLeftSelectionPosition = true;
127 eventData->mUpdateRightSelectionPosition = true;
128 eventData->mUpdateHighlightBox = true;
130 return fontDescriptionRun;
133 // public : Constructor.
135 ControllerPtr Controller::New()
137 return ControllerPtr( new Controller() );
140 ControllerPtr Controller::New( ControlInterface* controlInterface )
142 return ControllerPtr( new Controller( controlInterface ) );
145 ControllerPtr Controller::New( ControlInterface* controlInterface,
146 EditableControlInterface* editableControlInterface )
148 return ControllerPtr( new Controller( controlInterface,
149 editableControlInterface ) );
152 // public : Configure the text controller.
154 void Controller::EnableTextInput( DecoratorPtr decorator, InputMethodContext& inputMethodContext )
158 delete mImpl->mEventData;
159 mImpl->mEventData = NULL;
161 // Nothing else to do.
165 if( NULL == mImpl->mEventData )
167 mImpl->mEventData = new EventData( decorator, inputMethodContext );
171 void Controller::SetGlyphType( TextAbstraction::GlyphType glyphType )
173 // Metrics for bitmap & vector based glyphs are different
174 mImpl->mMetrics->SetGlyphType( glyphType );
176 // Clear the font-specific data
179 mImpl->RequestRelayout();
182 void Controller::SetMarkupProcessorEnabled( bool enable )
184 if( enable != mImpl->mMarkupProcessorEnabled )
186 //If Text was already set, call the SetText again for enabling or disabling markup
187 mImpl->mMarkupProcessorEnabled = enable;
194 bool Controller::IsMarkupProcessorEnabled() const
196 return mImpl->mMarkupProcessorEnabled;
199 void Controller::SetAutoScrollEnabled( bool enable )
201 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled[%s] SingleBox[%s]-> [%p]\n", (enable)?"true":"false", ( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX)?"true":"false", this );
203 if( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX )
207 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled for SINGLE_LINE_BOX\n" );
208 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
218 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled Disabling autoscroll\n");
219 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
226 mImpl->mIsAutoScrollEnabled = enable;
227 mImpl->RequestRelayout();
231 DALI_LOG_WARNING( "Attempted AutoScrolling on a non SINGLE_LINE_BOX, request ignored\n" );
232 mImpl->mIsAutoScrollEnabled = false;
236 bool Controller::IsAutoScrollEnabled() const
238 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::IsAutoScrollEnabled[%s]\n", mImpl->mIsAutoScrollEnabled?"true":"false" );
240 return mImpl->mIsAutoScrollEnabled;
243 CharacterDirection Controller::GetAutoScrollDirection() const
245 return mImpl->mIsTextDirectionRTL;
248 float Controller::GetAutoScrollLineAlignment() const
252 if( mImpl->mModel->mVisualModel &&
253 ( 0u != mImpl->mModel->mVisualModel->mLines.Count() ) )
255 offset = ( *mImpl->mModel->mVisualModel->mLines.Begin() ).alignmentOffset;
261 void Controller::SetHorizontalScrollEnabled( bool enable )
263 if( ( NULL != mImpl->mEventData ) &&
264 mImpl->mEventData->mDecorator )
266 mImpl->mEventData->mDecorator->SetHorizontalScrollEnabled( enable );
269 bool Controller::IsHorizontalScrollEnabled() const
271 if( ( NULL != mImpl->mEventData ) &&
272 mImpl->mEventData->mDecorator )
274 return mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
280 void Controller::SetVerticalScrollEnabled( bool enable )
282 if( ( NULL != mImpl->mEventData ) &&
283 mImpl->mEventData->mDecorator )
285 if( mImpl->mEventData->mDecorator )
287 mImpl->mEventData->mDecorator->SetVerticalScrollEnabled( enable );
292 bool Controller::IsVerticalScrollEnabled() const
294 if( ( NULL != mImpl->mEventData ) &&
295 mImpl->mEventData->mDecorator )
297 return mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
303 void Controller::SetSmoothHandlePanEnabled( bool enable )
305 if( ( NULL != mImpl->mEventData ) &&
306 mImpl->mEventData->mDecorator )
308 mImpl->mEventData->mDecorator->SetSmoothHandlePanEnabled( enable );
312 bool Controller::IsSmoothHandlePanEnabled() const
314 if( ( NULL != mImpl->mEventData ) &&
315 mImpl->mEventData->mDecorator )
317 return mImpl->mEventData->mDecorator->IsSmoothHandlePanEnabled();
323 void Controller::SetMaximumNumberOfCharacters( Length maxCharacters )
325 mImpl->mMaximumNumberOfCharacters = std::min( maxCharacters, MAX_TEXT_LENGTH );
328 int Controller::GetMaximumNumberOfCharacters()
330 return mImpl->mMaximumNumberOfCharacters;
333 void Controller::SetEnableCursorBlink( bool enable )
335 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "TextInput disabled" );
337 if( NULL != mImpl->mEventData )
339 mImpl->mEventData->mCursorBlinkEnabled = enable;
342 mImpl->mEventData->mDecorator )
344 mImpl->mEventData->mDecorator->StopCursorBlink();
349 bool Controller::GetEnableCursorBlink() const
351 if( NULL != mImpl->mEventData )
353 return mImpl->mEventData->mCursorBlinkEnabled;
359 void Controller::SetMultiLineEnabled( bool enable )
361 const Layout::Engine::Type layout = enable ? Layout::Engine::MULTI_LINE_BOX : Layout::Engine::SINGLE_LINE_BOX;
363 if( layout != mImpl->mLayoutEngine.GetLayout() )
365 // Set the layout type.
366 mImpl->mLayoutEngine.SetLayout( layout );
368 // Set the flags to redo the layout operations
369 const OperationsMask layoutOperations = static_cast<OperationsMask>( LAYOUT |
374 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
375 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | layoutOperations );
377 // Need to recalculate natural size
378 mImpl->mRecalculateNaturalSize = true;
380 mImpl->RequestRelayout();
384 bool Controller::IsMultiLineEnabled() const
386 return Layout::Engine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
389 void Controller::SetHorizontalAlignment( Text::HorizontalAlignment::Type alignment )
391 if( alignment != mImpl->mModel->mHorizontalAlignment )
393 // Set the alignment.
394 mImpl->mModel->mHorizontalAlignment = alignment;
396 // Set the flag to redo the alignment operation.
397 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
399 mImpl->RequestRelayout();
403 Text::HorizontalAlignment::Type Controller::GetHorizontalAlignment() const
405 return mImpl->mModel->mHorizontalAlignment;
408 void Controller::SetVerticalAlignment( VerticalAlignment::Type alignment )
410 if( alignment != mImpl->mModel->mVerticalAlignment )
412 // Set the alignment.
413 mImpl->mModel->mVerticalAlignment = alignment;
415 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
417 mImpl->RequestRelayout();
421 VerticalAlignment::Type Controller::GetVerticalAlignment() const
423 return mImpl->mModel->mVerticalAlignment;
426 bool Controller::IsIgnoreSpacesAfterText() const
428 return mImpl->mModel->mIgnoreSpacesAfterText;
431 void Controller::SetIgnoreSpacesAfterText( bool ignore )
433 mImpl->mModel->mIgnoreSpacesAfterText = ignore;
436 bool Controller::IsMatchSystemLanguageDirection() const
438 return mImpl->mModel->mMatchSystemLanguageDirection;
441 void Controller::SetMatchSystemLanguageDirection( bool match )
443 mImpl->mModel->mMatchSystemLanguageDirection = match;
446 void Controller::SetLayoutDirection( Dali::LayoutDirection::Type layoutDirection )
448 mImpl->mLayoutDirection = layoutDirection;
451 bool Controller::IsShowingRealText() const
453 return mImpl->IsShowingRealText();
457 void Controller::SetLineWrapMode( Text::LineWrap::Mode lineWrapMode )
459 if( lineWrapMode != mImpl->mModel->mLineWrapMode )
461 // Set the text wrap mode.
462 mImpl->mModel->mLineWrapMode = lineWrapMode;
465 // Update Text layout for applying wrap mode
466 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
471 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
472 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
473 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
476 mImpl->RequestRelayout();
480 Text::LineWrap::Mode Controller::GetLineWrapMode() const
482 return mImpl->mModel->mLineWrapMode;
485 void Controller::SetTextElideEnabled( bool enabled )
487 mImpl->mModel->mElideEnabled = enabled;
490 bool Controller::IsTextElideEnabled() const
492 return mImpl->mModel->mElideEnabled;
495 void Controller::SetTextFitEnabled(bool enabled)
497 mImpl->mTextFitEnabled = enabled;
500 bool Controller::IsTextFitEnabled() const
502 return mImpl->mTextFitEnabled;
505 void Controller::SetTextFitMinSize( float minSize, FontSizeType type )
511 mImpl->mTextFitMinSize = minSize;
516 mImpl->mTextFitMinSize = ConvertPixelToPint( minSize );
522 float Controller::GetTextFitMinSize() const
524 return mImpl->mTextFitMinSize;
527 void Controller::SetTextFitMaxSize( float maxSize, FontSizeType type )
533 mImpl->mTextFitMaxSize = maxSize;
538 mImpl->mTextFitMaxSize = ConvertPixelToPint( maxSize );
544 float Controller::GetTextFitMaxSize() const
546 return mImpl->mTextFitMaxSize;
549 void Controller::SetTextFitStepSize( float step, FontSizeType type )
555 mImpl->mTextFitStepSize = step;
560 mImpl->mTextFitStepSize = ConvertPixelToPint( step );
566 float Controller::GetTextFitStepSize() const
568 return mImpl->mTextFitStepSize;
571 void Controller::SetTextFitContentSize(Vector2 size)
573 mImpl->mTextFitContentSize = size;
576 Vector2 Controller::GetTextFitContentSize() const
578 return mImpl->mTextFitContentSize;
581 void Controller::SetPlaceholderTextElideEnabled( bool enabled )
583 mImpl->mEventData->mIsPlaceholderElideEnabled = enabled;
584 mImpl->mEventData->mPlaceholderEllipsisFlag = true;
586 // Update placeholder if there is no text
587 if( mImpl->IsShowingPlaceholderText() ||
588 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
590 ShowPlaceholderText();
594 bool Controller::IsPlaceholderTextElideEnabled() const
596 return mImpl->mEventData->mIsPlaceholderElideEnabled;
599 void Controller::SetSelectionEnabled( bool enabled )
601 mImpl->mEventData->mSelectionEnabled = enabled;
604 bool Controller::IsSelectionEnabled() const
606 return mImpl->mEventData->mSelectionEnabled;
609 void Controller::SetShiftSelectionEnabled( bool enabled )
611 mImpl->mEventData->mShiftSelectionFlag = enabled;
614 bool Controller::IsShiftSelectionEnabled() const
616 return mImpl->mEventData->mShiftSelectionFlag;
619 void Controller::SetGrabHandleEnabled( bool enabled )
621 mImpl->mEventData->mGrabHandleEnabled = enabled;
624 bool Controller::IsGrabHandleEnabled() const
626 return mImpl->mEventData->mGrabHandleEnabled;
629 void Controller::SetGrabHandlePopupEnabled(bool enabled)
631 mImpl->mEventData->mGrabHandlePopupEnabled = enabled;
634 bool Controller::IsGrabHandlePopupEnabled() const
636 return mImpl->mEventData->mGrabHandlePopupEnabled;
641 void Controller::SetText( const std::string& text )
643 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" );
645 // Reset keyboard as text changed
646 mImpl->ResetInputMethodContext();
648 // Remove the previously set text and style.
654 CharacterIndex lastCursorIndex = 0u;
656 if( NULL != mImpl->mEventData )
658 // If popup shown then hide it by switching to Editing state
659 if( ( EventData::SELECTING == mImpl->mEventData->mState ) ||
660 ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
661 ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) ||
662 ( EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState ) )
664 mImpl->ChangeState( EventData::EDITING );
670 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mTextColor );
672 MarkupProcessData markupProcessData( mImpl->mModel->mLogicalModel->mColorRuns,
673 mImpl->mModel->mLogicalModel->mFontDescriptionRuns,
674 mImpl->mModel->mLogicalModel->mEmbeddedItems );
676 Length textSize = 0u;
677 const uint8_t* utf8 = NULL;
678 if( mImpl->mMarkupProcessorEnabled )
680 ProcessMarkupString( text, markupProcessData );
681 textSize = markupProcessData.markupProcessedText.size();
683 // This is a bit horrible but std::string returns a (signed) char*
684 utf8 = reinterpret_cast<const uint8_t*>( markupProcessData.markupProcessedText.c_str() );
688 textSize = text.size();
690 // This is a bit horrible but std::string returns a (signed) char*
691 utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
694 // Limit the text size. If the text size is too large, crash or deadlock will occur.
695 if( textSize > MAX_TEXT_LENGTH )
697 DALI_LOG_WARNING( "The text size is too large(%d), limit the length to 32,768u\n", textSize );
698 textSize = MAX_TEXT_LENGTH;
701 // Convert text into UTF-32
702 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
703 utf32Characters.Resize( textSize );
705 // Transform a text array encoded in utf8 into an array encoded in utf32.
706 // It returns the actual number of characters.
707 Length characterCount = Utf8ToUtf32( utf8, textSize, utf32Characters.Begin() );
708 utf32Characters.Resize( characterCount );
710 DALI_ASSERT_DEBUG( textSize >= characterCount && "Invalid UTF32 conversion length" );
711 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", this, textSize, mImpl->mModel->mLogicalModel->mText.Count() );
713 // The characters to be added.
714 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
716 // To reset the cursor position
717 lastCursorIndex = characterCount;
719 // Update the rest of the model during size negotiation
720 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
722 // The natural size needs to be re-calculated.
723 mImpl->mRecalculateNaturalSize = true;
725 // The text direction needs to be updated.
726 mImpl->mUpdateTextDirection = true;
728 // Apply modifications to the model
729 mImpl->mOperationsPending = ALL_OPERATIONS;
733 ShowPlaceholderText();
736 // Resets the cursor position.
737 ResetCursorPosition( lastCursorIndex );
739 // Scrolls the text to make the cursor visible.
740 ResetScrollPosition();
742 mImpl->RequestRelayout();
744 if( NULL != mImpl->mEventData )
746 // Cancel previously queued events
747 mImpl->mEventData->mEventQueue.clear();
750 // Do this last since it provides callbacks into application code.
751 if( NULL != mImpl->mEditableControlInterface )
753 mImpl->mEditableControlInterface->TextChanged();
757 void Controller::GetText( std::string& text ) const
759 if( !mImpl->IsShowingPlaceholderText() )
761 // Retrieves the text string.
762 mImpl->GetText( 0u, text );
766 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this );
770 void Controller::SetPlaceholderText( PlaceholderType type, const std::string& text )
772 if( NULL != mImpl->mEventData )
774 if( PLACEHOLDER_TYPE_INACTIVE == type )
776 mImpl->mEventData->mPlaceholderTextInactive = text;
780 mImpl->mEventData->mPlaceholderTextActive = text;
783 // Update placeholder if there is no text
784 if( mImpl->IsShowingPlaceholderText() ||
785 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
787 ShowPlaceholderText();
792 void Controller::GetPlaceholderText( PlaceholderType type, std::string& text ) const
794 if( NULL != mImpl->mEventData )
796 if( PLACEHOLDER_TYPE_INACTIVE == type )
798 text = mImpl->mEventData->mPlaceholderTextInactive;
802 text = mImpl->mEventData->mPlaceholderTextActive;
807 void Controller::UpdateAfterFontChange( const std::string& newDefaultFont )
809 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
811 if( !mImpl->mFontDefaults->familyDefined ) // If user defined font then should not update when system font changes
813 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
814 mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
818 mImpl->RequestRelayout();
822 void Controller::RetrieveSelection( std::string& selectedText ) const
824 mImpl->RetrieveSelection( selectedText, false );
827 void Controller::SetSelection( int start, int end )
829 mImpl->SetSelection( start, end );
832 std::pair< int, int > Controller::GetSelectionIndexes() const
834 return mImpl->GetSelectionIndexes();
837 void Controller::CopyStringToClipboard( const std::string& source )
839 mImpl->CopyStringToClipboard( source );
842 void Controller::SendSelectionToClipboard( bool deleteAfterSending )
844 mImpl->SendSelectionToClipboard( deleteAfterSending );
847 // public : Default style & Input style
849 void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
851 if( NULL == mImpl->mFontDefaults )
853 mImpl->mFontDefaults = new FontDefaults();
856 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
857 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
858 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
860 // Clear the font-specific data
863 mImpl->RequestRelayout();
866 const std::string& Controller::GetDefaultFontFamily() const
868 if( NULL != mImpl->mFontDefaults )
870 return mImpl->mFontDefaults->mFontDescription.family;
876 void Controller::SetPlaceholderFontFamily( const std::string& placeholderTextFontFamily )
878 if( NULL != mImpl->mEventData )
880 if( NULL == mImpl->mEventData->mPlaceholderFont )
882 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
885 mImpl->mEventData->mPlaceholderFont->mFontDescription.family = placeholderTextFontFamily;
886 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetPlaceholderFontFamily %s\n", placeholderTextFontFamily.c_str());
887 mImpl->mEventData->mPlaceholderFont->familyDefined = !placeholderTextFontFamily.empty();
889 mImpl->RequestRelayout();
893 const std::string& Controller::GetPlaceholderFontFamily() const
895 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
897 return mImpl->mEventData->mPlaceholderFont->mFontDescription.family;
903 void Controller::SetDefaultFontWeight( FontWeight weight )
905 if( NULL == mImpl->mFontDefaults )
907 mImpl->mFontDefaults = new FontDefaults();
910 mImpl->mFontDefaults->mFontDescription.weight = weight;
911 mImpl->mFontDefaults->weightDefined = true;
913 // Clear the font-specific data
916 mImpl->RequestRelayout();
919 bool Controller::IsDefaultFontWeightDefined() const
921 if( NULL != mImpl->mFontDefaults )
923 return mImpl->mFontDefaults->weightDefined;
929 FontWeight Controller::GetDefaultFontWeight() const
931 if( NULL != mImpl->mFontDefaults )
933 return mImpl->mFontDefaults->mFontDescription.weight;
936 return TextAbstraction::FontWeight::NORMAL;
939 void Controller::SetPlaceholderTextFontWeight( FontWeight weight )
941 if( NULL != mImpl->mEventData )
943 if( NULL == mImpl->mEventData->mPlaceholderFont )
945 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
948 mImpl->mEventData->mPlaceholderFont->mFontDescription.weight = weight;
949 mImpl->mEventData->mPlaceholderFont->weightDefined = true;
951 mImpl->RequestRelayout();
955 bool Controller::IsPlaceholderTextFontWeightDefined() const
957 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
959 return mImpl->mEventData->mPlaceholderFont->weightDefined;
964 FontWeight Controller::GetPlaceholderTextFontWeight() const
966 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
968 return mImpl->mEventData->mPlaceholderFont->mFontDescription.weight;
971 return TextAbstraction::FontWeight::NORMAL;
974 void Controller::SetDefaultFontWidth( FontWidth width )
976 if( NULL == mImpl->mFontDefaults )
978 mImpl->mFontDefaults = new FontDefaults();
981 mImpl->mFontDefaults->mFontDescription.width = width;
982 mImpl->mFontDefaults->widthDefined = true;
984 // Clear the font-specific data
987 mImpl->RequestRelayout();
990 bool Controller::IsDefaultFontWidthDefined() const
992 if( NULL != mImpl->mFontDefaults )
994 return mImpl->mFontDefaults->widthDefined;
1000 FontWidth Controller::GetDefaultFontWidth() const
1002 if( NULL != mImpl->mFontDefaults )
1004 return mImpl->mFontDefaults->mFontDescription.width;
1007 return TextAbstraction::FontWidth::NORMAL;
1010 void Controller::SetPlaceholderTextFontWidth( FontWidth width )
1012 if( NULL != mImpl->mEventData )
1014 if( NULL == mImpl->mEventData->mPlaceholderFont )
1016 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
1019 mImpl->mEventData->mPlaceholderFont->mFontDescription.width = width;
1020 mImpl->mEventData->mPlaceholderFont->widthDefined = true;
1022 mImpl->RequestRelayout();
1026 bool Controller::IsPlaceholderTextFontWidthDefined() const
1028 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1030 return mImpl->mEventData->mPlaceholderFont->widthDefined;
1035 FontWidth Controller::GetPlaceholderTextFontWidth() const
1037 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1039 return mImpl->mEventData->mPlaceholderFont->mFontDescription.width;
1042 return TextAbstraction::FontWidth::NORMAL;
1045 void Controller::SetDefaultFontSlant( FontSlant slant )
1047 if( NULL == mImpl->mFontDefaults )
1049 mImpl->mFontDefaults = new FontDefaults();
1052 mImpl->mFontDefaults->mFontDescription.slant = slant;
1053 mImpl->mFontDefaults->slantDefined = true;
1055 // Clear the font-specific data
1058 mImpl->RequestRelayout();
1061 bool Controller::IsDefaultFontSlantDefined() const
1063 if( NULL != mImpl->mFontDefaults )
1065 return mImpl->mFontDefaults->slantDefined;
1070 FontSlant Controller::GetDefaultFontSlant() const
1072 if( NULL != mImpl->mFontDefaults )
1074 return mImpl->mFontDefaults->mFontDescription.slant;
1077 return TextAbstraction::FontSlant::NORMAL;
1080 void Controller::SetPlaceholderTextFontSlant( FontSlant slant )
1082 if( NULL != mImpl->mEventData )
1084 if( NULL == mImpl->mEventData->mPlaceholderFont )
1086 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
1089 mImpl->mEventData->mPlaceholderFont->mFontDescription.slant = slant;
1090 mImpl->mEventData->mPlaceholderFont->slantDefined = true;
1092 mImpl->RequestRelayout();
1096 bool Controller::IsPlaceholderTextFontSlantDefined() const
1098 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1100 return mImpl->mEventData->mPlaceholderFont->slantDefined;
1105 FontSlant Controller::GetPlaceholderTextFontSlant() const
1107 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1109 return mImpl->mEventData->mPlaceholderFont->mFontDescription.slant;
1112 return TextAbstraction::FontSlant::NORMAL;
1115 void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
1117 if( NULL == mImpl->mFontDefaults )
1119 mImpl->mFontDefaults = new FontDefaults();
1126 mImpl->mFontDefaults->mDefaultPointSize = fontSize;
1127 mImpl->mFontDefaults->sizeDefined = true;
1132 // Point size = Pixel size * 72.f / DPI
1133 unsigned int horizontalDpi = 0u;
1134 unsigned int verticalDpi = 0u;
1135 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1136 fontClient.GetDpi( horizontalDpi, verticalDpi );
1138 mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
1139 mImpl->mFontDefaults->sizeDefined = true;
1144 // Clear the font-specific data
1147 mImpl->RequestRelayout();
1150 float Controller::GetDefaultFontSize( FontSizeType type ) const
1153 if( NULL != mImpl->mFontDefaults )
1159 value = mImpl->mFontDefaults->mDefaultPointSize;
1164 // Pixel size = Point size * DPI / 72.f
1165 unsigned int horizontalDpi = 0u;
1166 unsigned int verticalDpi = 0u;
1167 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1168 fontClient.GetDpi( horizontalDpi, verticalDpi );
1170 value = mImpl->mFontDefaults->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1180 void Controller::SetPlaceholderTextFontSize( float fontSize, FontSizeType type )
1182 if( NULL != mImpl->mEventData )
1184 if( NULL == mImpl->mEventData->mPlaceholderFont )
1186 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
1193 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = fontSize;
1194 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1195 mImpl->mEventData->mIsPlaceholderPixelSize = false; // Font size flag
1200 // Point size = Pixel size * 72.f / DPI
1201 unsigned int horizontalDpi = 0u;
1202 unsigned int verticalDpi = 0u;
1203 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1204 fontClient.GetDpi( horizontalDpi, verticalDpi );
1206 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
1207 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1208 mImpl->mEventData->mIsPlaceholderPixelSize = true; // Font size flag
1213 mImpl->RequestRelayout();
1217 float Controller::GetPlaceholderTextFontSize( FontSizeType type ) const
1220 if( NULL != mImpl->mEventData )
1226 if( NULL != mImpl->mEventData->mPlaceholderFont )
1228 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize;
1232 // If the placeholder text font size is not set, then return the default font size.
1233 value = GetDefaultFontSize( POINT_SIZE );
1239 if( NULL != mImpl->mEventData->mPlaceholderFont )
1241 // Pixel size = Point size * DPI / 72.f
1242 unsigned int horizontalDpi = 0u;
1243 unsigned int verticalDpi = 0u;
1244 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1245 fontClient.GetDpi( horizontalDpi, verticalDpi );
1247 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1251 // If the placeholder text font size is not set, then return the default font size.
1252 value = GetDefaultFontSize( PIXEL_SIZE );
1263 void Controller::SetDefaultColor( const Vector4& color )
1265 mImpl->mTextColor = color;
1267 if( !mImpl->IsShowingPlaceholderText() )
1269 mImpl->mModel->mVisualModel->SetTextColor( color );
1271 mImpl->RequestRelayout();
1275 const Vector4& Controller::GetDefaultColor() const
1277 return mImpl->mTextColor;
1280 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
1282 if( NULL != mImpl->mEventData )
1284 mImpl->mEventData->mPlaceholderTextColor = textColor;
1287 if( mImpl->IsShowingPlaceholderText() )
1289 mImpl->mModel->mVisualModel->SetTextColor( textColor );
1290 mImpl->RequestRelayout();
1294 const Vector4& Controller::GetPlaceholderTextColor() const
1296 if( NULL != mImpl->mEventData )
1298 return mImpl->mEventData->mPlaceholderTextColor;
1301 return Color::BLACK;
1304 void Controller::SetShadowOffset( const Vector2& shadowOffset )
1306 mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
1308 mImpl->RequestRelayout();
1311 const Vector2& Controller::GetShadowOffset() const
1313 return mImpl->mModel->mVisualModel->GetShadowOffset();
1316 void Controller::SetShadowColor( const Vector4& shadowColor )
1318 mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
1320 mImpl->RequestRelayout();
1323 const Vector4& Controller::GetShadowColor() const
1325 return mImpl->mModel->mVisualModel->GetShadowColor();
1328 void Controller::SetShadowBlurRadius( const float& shadowBlurRadius )
1330 if ( fabsf( GetShadowBlurRadius() - shadowBlurRadius ) > Math::MACHINE_EPSILON_1 )
1332 mImpl->mModel->mVisualModel->SetShadowBlurRadius( shadowBlurRadius );
1334 mImpl->RequestRelayout();
1338 const float& Controller::GetShadowBlurRadius() const
1340 return mImpl->mModel->mVisualModel->GetShadowBlurRadius();
1343 void Controller::SetUnderlineColor( const Vector4& color )
1345 mImpl->mModel->mVisualModel->SetUnderlineColor( color );
1347 mImpl->RequestRelayout();
1350 const Vector4& Controller::GetUnderlineColor() const
1352 return mImpl->mModel->mVisualModel->GetUnderlineColor();
1355 void Controller::SetUnderlineEnabled( bool enabled )
1357 mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
1359 mImpl->RequestRelayout();
1362 bool Controller::IsUnderlineEnabled() const
1364 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
1367 void Controller::SetUnderlineHeight( float height )
1369 mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
1371 mImpl->RequestRelayout();
1374 float Controller::GetUnderlineHeight() const
1376 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
1379 void Controller::SetOutlineColor( const Vector4& color )
1381 mImpl->mModel->mVisualModel->SetOutlineColor( color );
1383 mImpl->RequestRelayout();
1386 const Vector4& Controller::GetOutlineColor() const
1388 return mImpl->mModel->mVisualModel->GetOutlineColor();
1391 void Controller::SetOutlineWidth( uint16_t width )
1393 mImpl->mModel->mVisualModel->SetOutlineWidth( width );
1395 mImpl->RequestRelayout();
1398 uint16_t Controller::GetOutlineWidth() const
1400 return mImpl->mModel->mVisualModel->GetOutlineWidth();
1403 void Controller::SetBackgroundColor( const Vector4& color )
1405 mImpl->mModel->mVisualModel->SetBackgroundColor( color );
1407 mImpl->RequestRelayout();
1410 const Vector4& Controller::GetBackgroundColor() const
1412 return mImpl->mModel->mVisualModel->GetBackgroundColor();
1415 void Controller::SetBackgroundEnabled( bool enabled )
1417 mImpl->mModel->mVisualModel->SetBackgroundEnabled( enabled );
1419 mImpl->RequestRelayout();
1422 bool Controller::IsBackgroundEnabled() const
1424 return mImpl->mModel->mVisualModel->IsBackgroundEnabled();
1427 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
1429 if( NULL == mImpl->mEmbossDefaults )
1431 mImpl->mEmbossDefaults = new EmbossDefaults();
1434 mImpl->mEmbossDefaults->properties = embossProperties;
1437 const std::string& Controller::GetDefaultEmbossProperties() const
1439 if( NULL != mImpl->mEmbossDefaults )
1441 return mImpl->mEmbossDefaults->properties;
1444 return EMPTY_STRING;
1447 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
1449 if( NULL == mImpl->mOutlineDefaults )
1451 mImpl->mOutlineDefaults = new OutlineDefaults();
1454 mImpl->mOutlineDefaults->properties = outlineProperties;
1457 const std::string& Controller::GetDefaultOutlineProperties() const
1459 if( NULL != mImpl->mOutlineDefaults )
1461 return mImpl->mOutlineDefaults->properties;
1464 return EMPTY_STRING;
1467 bool Controller::SetDefaultLineSpacing( float lineSpacing )
1469 if( std::fabs( lineSpacing - mImpl->mLayoutEngine.GetDefaultLineSpacing() ) > Math::MACHINE_EPSILON_1000 )
1471 mImpl->mLayoutEngine.SetDefaultLineSpacing(lineSpacing);
1472 mImpl->mRecalculateNaturalSize = true;
1478 float Controller::GetDefaultLineSpacing() const
1480 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
1483 void Controller::SetInputColor( const Vector4& color )
1485 if( NULL != mImpl->mEventData )
1487 mImpl->mEventData->mInputStyle.textColor = color;
1488 mImpl->mEventData->mInputStyle.isDefaultColor = false;
1490 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1492 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
1494 // Get start and end position of selection
1495 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
1496 const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
1498 // Add the color run.
1499 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1500 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
1502 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
1503 colorRun.color = color;
1504 colorRun.characterRun.characterIndex = startOfSelectedText;
1505 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1507 // Request to relayout.
1508 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1509 mImpl->RequestRelayout();
1511 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1512 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1513 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1518 const Vector4& Controller::GetInputColor() const
1520 if( NULL != mImpl->mEventData )
1522 return mImpl->mEventData->mInputStyle.textColor;
1525 // Return the default text's color if there is no EventData.
1526 return mImpl->mTextColor;
1530 void Controller::SetInputFontFamily( const std::string& fontFamily )
1532 if( NULL != mImpl->mEventData )
1534 mImpl->mEventData->mInputStyle.familyName = fontFamily;
1535 mImpl->mEventData->mInputStyle.isFamilyDefined = true;
1537 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1539 CharacterIndex startOfSelectedText = 0u;
1540 Length lengthOfSelectedText = 0u;
1541 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1542 mImpl->mModel->mLogicalModel,
1543 startOfSelectedText,
1544 lengthOfSelectedText );
1546 fontDescriptionRun.familyLength = fontFamily.size();
1547 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
1548 memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength );
1549 fontDescriptionRun.familyDefined = true;
1551 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
1553 // Request to relayout.
1554 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1559 UPDATE_LAYOUT_SIZE |
1562 mImpl->mRecalculateNaturalSize = true;
1563 mImpl->RequestRelayout();
1565 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1566 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1567 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1569 // As the font changes, recalculate the handle positions is needed.
1570 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1571 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1572 mImpl->mEventData->mUpdateHighlightBox = true;
1573 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1578 const std::string& Controller::GetInputFontFamily() const
1580 if( NULL != mImpl->mEventData )
1582 return mImpl->mEventData->mInputStyle.familyName;
1585 // Return the default font's family if there is no EventData.
1586 return GetDefaultFontFamily();
1589 void Controller::SetInputFontWeight( FontWeight weight )
1591 if( NULL != mImpl->mEventData )
1593 mImpl->mEventData->mInputStyle.weight = weight;
1594 mImpl->mEventData->mInputStyle.isWeightDefined = true;
1596 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1598 CharacterIndex startOfSelectedText = 0u;
1599 Length lengthOfSelectedText = 0u;
1600 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1601 mImpl->mModel->mLogicalModel,
1602 startOfSelectedText,
1603 lengthOfSelectedText );
1605 fontDescriptionRun.weight = weight;
1606 fontDescriptionRun.weightDefined = true;
1608 // Request to relayout.
1609 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1614 UPDATE_LAYOUT_SIZE |
1617 mImpl->mRecalculateNaturalSize = true;
1618 mImpl->RequestRelayout();
1620 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1621 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1622 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1624 // As the font might change, recalculate the handle positions is needed.
1625 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1626 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1627 mImpl->mEventData->mUpdateHighlightBox = true;
1628 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1633 bool Controller::IsInputFontWeightDefined() const
1635 bool defined = false;
1637 if( NULL != mImpl->mEventData )
1639 defined = mImpl->mEventData->mInputStyle.isWeightDefined;
1645 FontWeight Controller::GetInputFontWeight() const
1647 if( NULL != mImpl->mEventData )
1649 return mImpl->mEventData->mInputStyle.weight;
1652 return GetDefaultFontWeight();
1655 void Controller::SetInputFontWidth( FontWidth width )
1657 if( NULL != mImpl->mEventData )
1659 mImpl->mEventData->mInputStyle.width = width;
1660 mImpl->mEventData->mInputStyle.isWidthDefined = true;
1662 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1664 CharacterIndex startOfSelectedText = 0u;
1665 Length lengthOfSelectedText = 0u;
1666 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1667 mImpl->mModel->mLogicalModel,
1668 startOfSelectedText,
1669 lengthOfSelectedText );
1671 fontDescriptionRun.width = width;
1672 fontDescriptionRun.widthDefined = true;
1674 // Request to relayout.
1675 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1680 UPDATE_LAYOUT_SIZE |
1683 mImpl->mRecalculateNaturalSize = true;
1684 mImpl->RequestRelayout();
1686 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1687 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1688 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1690 // As the font might change, recalculate the handle positions is needed.
1691 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1692 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1693 mImpl->mEventData->mUpdateHighlightBox = true;
1694 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1699 bool Controller::IsInputFontWidthDefined() const
1701 bool defined = false;
1703 if( NULL != mImpl->mEventData )
1705 defined = mImpl->mEventData->mInputStyle.isWidthDefined;
1711 FontWidth Controller::GetInputFontWidth() const
1713 if( NULL != mImpl->mEventData )
1715 return mImpl->mEventData->mInputStyle.width;
1718 return GetDefaultFontWidth();
1721 void Controller::SetInputFontSlant( FontSlant slant )
1723 if( NULL != mImpl->mEventData )
1725 mImpl->mEventData->mInputStyle.slant = slant;
1726 mImpl->mEventData->mInputStyle.isSlantDefined = true;
1728 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1730 CharacterIndex startOfSelectedText = 0u;
1731 Length lengthOfSelectedText = 0u;
1732 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1733 mImpl->mModel->mLogicalModel,
1734 startOfSelectedText,
1735 lengthOfSelectedText );
1737 fontDescriptionRun.slant = slant;
1738 fontDescriptionRun.slantDefined = true;
1740 // Request to relayout.
1741 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1746 UPDATE_LAYOUT_SIZE |
1749 mImpl->mRecalculateNaturalSize = true;
1750 mImpl->RequestRelayout();
1752 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1753 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1754 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1756 // As the font might change, recalculate the handle positions is needed.
1757 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1758 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1759 mImpl->mEventData->mUpdateHighlightBox = true;
1760 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1765 bool Controller::IsInputFontSlantDefined() const
1767 bool defined = false;
1769 if( NULL != mImpl->mEventData )
1771 defined = mImpl->mEventData->mInputStyle.isSlantDefined;
1777 FontSlant Controller::GetInputFontSlant() const
1779 if( NULL != mImpl->mEventData )
1781 return mImpl->mEventData->mInputStyle.slant;
1784 return GetDefaultFontSlant();
1787 void Controller::SetInputFontPointSize( float size )
1789 if( NULL != mImpl->mEventData )
1791 mImpl->mEventData->mInputStyle.size = size;
1792 mImpl->mEventData->mInputStyle.isSizeDefined = true;
1794 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1796 CharacterIndex startOfSelectedText = 0u;
1797 Length lengthOfSelectedText = 0u;
1798 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1799 mImpl->mModel->mLogicalModel,
1800 startOfSelectedText,
1801 lengthOfSelectedText );
1803 fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
1804 fontDescriptionRun.sizeDefined = true;
1806 // Request to relayout.
1807 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1812 UPDATE_LAYOUT_SIZE |
1815 mImpl->mRecalculateNaturalSize = true;
1816 mImpl->RequestRelayout();
1818 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1819 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1820 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1822 // As the font might change, recalculate the handle positions is needed.
1823 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1824 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1825 mImpl->mEventData->mUpdateHighlightBox = true;
1826 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1831 float Controller::GetInputFontPointSize() const
1833 if( NULL != mImpl->mEventData )
1835 return mImpl->mEventData->mInputStyle.size;
1838 // Return the default font's point size if there is no EventData.
1839 return GetDefaultFontSize( Text::Controller::POINT_SIZE );
1842 void Controller::SetInputLineSpacing( float lineSpacing )
1844 if( NULL != mImpl->mEventData )
1846 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1847 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1851 float Controller::GetInputLineSpacing() const
1853 if( NULL != mImpl->mEventData )
1855 return mImpl->mEventData->mInputStyle.lineSpacing;
1861 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1863 if( NULL != mImpl->mEventData )
1865 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1869 const std::string& Controller::GetInputShadowProperties() const
1871 if( NULL != mImpl->mEventData )
1873 return mImpl->mEventData->mInputStyle.shadowProperties;
1876 return EMPTY_STRING;
1879 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1881 if( NULL != mImpl->mEventData )
1883 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1887 const std::string& Controller::GetInputUnderlineProperties() const
1889 if( NULL != mImpl->mEventData )
1891 return mImpl->mEventData->mInputStyle.underlineProperties;
1894 return EMPTY_STRING;
1897 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
1899 if( NULL != mImpl->mEventData )
1901 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1905 const std::string& Controller::GetInputEmbossProperties() const
1907 if( NULL != mImpl->mEventData )
1909 return mImpl->mEventData->mInputStyle.embossProperties;
1912 return GetDefaultEmbossProperties();
1915 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
1917 if( NULL != mImpl->mEventData )
1919 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1923 const std::string& Controller::GetInputOutlineProperties() const
1925 if( NULL != mImpl->mEventData )
1927 return mImpl->mEventData->mInputStyle.outlineProperties;
1930 return GetDefaultOutlineProperties();
1933 void Controller::SetInputModePassword( bool passwordInput )
1935 if( NULL != mImpl->mEventData )
1937 mImpl->mEventData->mPasswordInput = passwordInput;
1941 bool Controller::IsInputModePassword()
1943 if( NULL != mImpl->mEventData )
1945 return mImpl->mEventData->mPasswordInput;
1950 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
1952 if( NULL != mImpl->mEventData )
1954 mImpl->mEventData->mDoubleTapAction = action;
1958 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1960 NoTextTap::Action action = NoTextTap::NO_ACTION;
1962 if( NULL != mImpl->mEventData )
1964 action = mImpl->mEventData->mDoubleTapAction;
1970 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
1972 if( NULL != mImpl->mEventData )
1974 mImpl->mEventData->mLongPressAction = action;
1978 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1980 NoTextTap::Action action = NoTextTap::NO_ACTION;
1982 if( NULL != mImpl->mEventData )
1984 action = mImpl->mEventData->mLongPressAction;
1990 bool Controller::IsUnderlineSetByString()
1992 return mImpl->mUnderlineSetByString;
1995 void Controller::UnderlineSetByString( bool setByString )
1997 mImpl->mUnderlineSetByString = setByString;
2000 bool Controller::IsShadowSetByString()
2002 return mImpl->mShadowSetByString;
2005 void Controller::ShadowSetByString( bool setByString )
2007 mImpl->mShadowSetByString = setByString;
2010 bool Controller::IsOutlineSetByString()
2012 return mImpl->mOutlineSetByString;
2015 void Controller::OutlineSetByString( bool setByString )
2017 mImpl->mOutlineSetByString = setByString;
2020 bool Controller::IsFontStyleSetByString()
2022 return mImpl->mFontStyleSetByString;
2025 void Controller::FontStyleSetByString( bool setByString )
2027 mImpl->mFontStyleSetByString = setByString;
2030 // public : Queries & retrieves.
2032 Layout::Engine& Controller::GetLayoutEngine()
2034 return mImpl->mLayoutEngine;
2037 View& Controller::GetView()
2039 return mImpl->mView;
2042 Vector3 Controller::GetNaturalSize()
2044 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
2045 Vector3 naturalSize;
2047 // Make sure the model is up-to-date before layouting
2048 ProcessModifyEvents();
2050 if( mImpl->mRecalculateNaturalSize )
2052 // Operations that can be done only once until the text changes.
2053 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2060 GET_GLYPH_METRICS );
2062 // Set the update info to relayout the whole text.
2063 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2064 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2066 // Make sure the model is up-to-date before layouting
2067 mImpl->UpdateModel( onlyOnceOperations );
2069 // Layout the text for the new width.
2070 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT | REORDER );
2072 // Store the actual control's size to restore later.
2073 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
2075 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
2076 static_cast<OperationsMask>( onlyOnceOperations |
2078 naturalSize.GetVectorXY() );
2080 // Do not do again the only once operations.
2081 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2083 // Do the size related operations again.
2084 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
2087 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
2089 // Stores the natural size to avoid recalculate it again
2090 // unless the text/style changes.
2091 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
2093 mImpl->mRecalculateNaturalSize = false;
2095 // Clear the update info. This info will be set the next time the text is updated.
2096 mImpl->mTextUpdateInfo.Clear();
2097 mImpl->mTextUpdateInfo.mClearAll = true;
2099 // Restore the actual control's size.
2100 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
2102 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
2106 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
2108 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
2111 naturalSize.x = ConvertToEven( naturalSize.x );
2112 naturalSize.y = ConvertToEven( naturalSize.y );
2117 bool Controller::CheckForTextFit( float pointSize, Size& layoutSize )
2120 mImpl->mFontDefaults->mFitPointSize = pointSize;
2121 mImpl->mFontDefaults->sizeDefined = true;
2124 // Operations that can be done only once until the text changes.
2125 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2132 GET_GLYPH_METRICS );
2134 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2135 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2137 // Make sure the model is up-to-date before layouting
2138 mImpl->UpdateModel( onlyOnceOperations );
2140 DoRelayout( Size( layoutSize.width, MAX_FLOAT ),
2141 static_cast<OperationsMask>( onlyOnceOperations | LAYOUT),
2144 // Clear the update info. This info will be set the next time the text is updated.
2145 mImpl->mTextUpdateInfo.Clear();
2146 mImpl->mTextUpdateInfo.mClearAll = true;
2148 if( textSize.width > layoutSize.width || textSize.height > layoutSize.height )
2155 void Controller::FitPointSizeforLayout( Size layoutSize )
2157 const OperationsMask operations = mImpl->mOperationsPending;
2158 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
2160 bool actualellipsis = mImpl->mModel->mElideEnabled;
2161 float minPointSize = mImpl->mTextFitMinSize;
2162 float maxPointSize = mImpl->mTextFitMaxSize;
2163 float pointInterval = mImpl->mTextFitStepSize;
2165 mImpl->mModel->mElideEnabled = false;
2166 Vector<float> pointSizeArray;
2169 if( pointInterval < 1.f )
2171 mImpl->mTextFitStepSize = pointInterval = 1.0f;
2174 pointSizeArray.Reserve( static_cast< unsigned int >( ceil( ( maxPointSize - minPointSize ) / pointInterval ) ) );
2176 for( float i = minPointSize; i < maxPointSize; i += pointInterval )
2178 pointSizeArray.PushBack( i );
2181 pointSizeArray.PushBack( maxPointSize );
2183 int bestSizeIndex = 0;
2184 int min = bestSizeIndex + 1;
2185 int max = pointSizeArray.Size() - 1;
2188 int destI = ( min + max ) / 2;
2190 if( CheckForTextFit( pointSizeArray[destI], layoutSize ) )
2192 bestSizeIndex = min;
2198 bestSizeIndex = max;
2202 mImpl->mModel->mElideEnabled = actualellipsis;
2203 mImpl->mFontDefaults->mFitPointSize = pointSizeArray[bestSizeIndex];
2204 mImpl->mFontDefaults->sizeDefined = true;
2209 float Controller::GetHeightForWidth( float width )
2211 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
2212 // Make sure the model is up-to-date before layouting
2213 ProcessModifyEvents();
2216 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ||
2217 mImpl->mTextUpdateInfo.mFullRelayoutNeeded ||
2218 mImpl->mTextUpdateInfo.mClearAll )
2220 // Operations that can be done only once until the text changes.
2221 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2228 GET_GLYPH_METRICS );
2230 // Set the update info to relayout the whole text.
2231 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2232 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2234 // Make sure the model is up-to-date before layouting
2235 mImpl->UpdateModel( onlyOnceOperations );
2238 // Layout the text for the new width.
2239 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
2241 // Store the actual control's width.
2242 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
2244 DoRelayout( Size( width, MAX_FLOAT ),
2245 static_cast<OperationsMask>( onlyOnceOperations |
2249 // Do not do again the only once operations.
2250 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2252 // Do the size related operations again.
2253 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
2257 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
2259 // Clear the update info. This info will be set the next time the text is updated.
2260 mImpl->mTextUpdateInfo.Clear();
2261 mImpl->mTextUpdateInfo.mClearAll = true;
2263 // Restore the actual control's width.
2264 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
2266 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
2270 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
2271 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
2274 return layoutSize.height;
2277 int Controller::GetLineCount( float width )
2279 GetHeightForWidth( width );
2280 int numberofLines = mImpl->mModel->GetNumberOfLines();
2281 return numberofLines;
2284 const ModelInterface* const Controller::GetTextModel() const
2286 return mImpl->mModel.Get();
2289 float Controller::GetScrollAmountByUserInput()
2291 float scrollAmount = 0.0f;
2293 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
2295 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
2296 mImpl->mEventData->mCheckScrollAmount = false;
2298 return scrollAmount;
2301 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
2303 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
2306 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
2307 layoutHeight = layout.height;
2308 scrollPosition = mImpl->mModel->mScrollPosition.y;
2309 isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
2313 void Controller::SetHiddenInputOption(const Property::Map& options )
2315 if( NULL == mImpl->mHiddenInput )
2317 mImpl->mHiddenInput = new HiddenText( this );
2319 mImpl->mHiddenInput->SetProperties(options);
2322 void Controller::GetHiddenInputOption(Property::Map& options )
2324 if( NULL != mImpl->mHiddenInput )
2326 mImpl->mHiddenInput->GetProperties(options);
2330 void Controller::SetPlaceholderProperty( const Property::Map& map )
2332 const Property::Map::SizeType count = map.Count();
2334 for( Property::Map::SizeType position = 0; position < count; ++position )
2336 KeyValuePair keyValue = map.GetKeyValue( position );
2337 Property::Key& key = keyValue.first;
2338 Property::Value& value = keyValue.second;
2340 if( key == Toolkit::Text::PlaceHolder::Property::TEXT || key == PLACEHOLDER_TEXT )
2342 std::string text = "";
2344 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
2346 else if( key == Toolkit::Text::PlaceHolder::Property::TEXT_FOCUSED || key == PLACEHOLDER_TEXT_FOCUSED )
2348 std::string text = "";
2350 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
2352 else if( key == Toolkit::Text::PlaceHolder::Property::COLOR || key == PLACEHOLDER_COLOR )
2355 value.Get( textColor );
2356 if( GetPlaceholderTextColor() != textColor )
2358 SetPlaceholderTextColor( textColor );
2361 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_FAMILY || key == PLACEHOLDER_FONT_FAMILY )
2363 std::string fontFamily = "";
2364 value.Get( fontFamily );
2365 SetPlaceholderFontFamily( fontFamily );
2367 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_STYLE || key == PLACEHOLDER_FONT_STYLE )
2369 SetFontStyleProperty( this, value, Text::FontStyle::PLACEHOLDER );
2371 else if( key == Toolkit::Text::PlaceHolder::Property::POINT_SIZE || key == PLACEHOLDER_POINT_SIZE )
2374 value.Get( pointSize );
2375 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
2377 SetPlaceholderTextFontSize( pointSize, Text::Controller::POINT_SIZE );
2380 else if( key == Toolkit::Text::PlaceHolder::Property::PIXEL_SIZE || key == PLACEHOLDER_PIXEL_SIZE )
2383 value.Get( pixelSize );
2384 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
2386 SetPlaceholderTextFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
2389 else if( key == Toolkit::Text::PlaceHolder::Property::ELLIPSIS || key == PLACEHOLDER_ELLIPSIS )
2392 value.Get( ellipsis );
2393 SetPlaceholderTextElideEnabled( ellipsis );
2398 void Controller::GetPlaceholderProperty( Property::Map& map )
2400 if( NULL != mImpl->mEventData )
2402 if( !mImpl->mEventData->mPlaceholderTextActive.empty() )
2404 map[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = mImpl->mEventData->mPlaceholderTextActive;
2406 if( !mImpl->mEventData->mPlaceholderTextInactive.empty() )
2408 map[ Text::PlaceHolder::Property::TEXT ] = mImpl->mEventData->mPlaceholderTextInactive;
2411 map[ Text::PlaceHolder::Property::COLOR ] = mImpl->mEventData->mPlaceholderTextColor;
2412 map[ Text::PlaceHolder::Property::FONT_FAMILY ] = GetPlaceholderFontFamily();
2414 Property::Value fontStyleMapGet;
2415 GetFontStyleProperty( this, fontStyleMapGet, Text::FontStyle::PLACEHOLDER );
2416 map[ Text::PlaceHolder::Property::FONT_STYLE ] = fontStyleMapGet;
2418 // Choose font size : POINT_SIZE or PIXEL_SIZE
2419 if( !mImpl->mEventData->mIsPlaceholderPixelSize )
2421 map[ Text::PlaceHolder::Property::POINT_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE );
2425 map[ Text::PlaceHolder::Property::PIXEL_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE );
2428 if( mImpl->mEventData->mPlaceholderEllipsisFlag )
2430 map[ Text::PlaceHolder::Property::ELLIPSIS ] = IsPlaceholderTextElideEnabled();
2435 Toolkit::DevelText::TextDirection::Type Controller::GetTextDirection()
2437 // Make sure the model is up-to-date before layouting
2438 ProcessModifyEvents();
2440 if ( mImpl->mUpdateTextDirection )
2442 // Operations that can be done only once until the text changes.
2443 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2450 GET_GLYPH_METRICS );
2452 // Set the update info to relayout the whole text.
2453 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2454 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2456 // Make sure the model is up-to-date before layouting
2457 mImpl->UpdateModel( onlyOnceOperations );
2459 Vector3 naturalSize;
2460 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
2461 static_cast<OperationsMask>( onlyOnceOperations |
2462 LAYOUT | REORDER | UPDATE_DIRECTION ),
2463 naturalSize.GetVectorXY() );
2465 // Do not do again the only once operations.
2466 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2468 // Clear the update info. This info will be set the next time the text is updated.
2469 mImpl->mTextUpdateInfo.Clear();
2471 mImpl->mUpdateTextDirection = false;
2474 return mImpl->mIsTextDirectionRTL ? Toolkit::DevelText::TextDirection::RIGHT_TO_LEFT : Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT;
2477 Toolkit::DevelText::VerticalLineAlignment::Type Controller::GetVerticalLineAlignment() const
2479 return mImpl->mModel->GetVerticalLineAlignment();
2482 void Controller::SetVerticalLineAlignment( Toolkit::DevelText::VerticalLineAlignment::Type alignment )
2484 mImpl->mModel->mVerticalLineAlignment = alignment;
2487 // public : Relayout.
2489 Controller::UpdateTextType Controller::Relayout( const Size& size, Dali::LayoutDirection::Type layoutDirection )
2491 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
2493 UpdateTextType updateTextType = NONE_UPDATED;
2495 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
2497 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
2499 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
2500 updateTextType = MODEL_UPDATED;
2503 // Clear the update info. This info will be set the next time the text is updated.
2504 mImpl->mTextUpdateInfo.Clear();
2506 // Not worth to relayout if width or height is equal to zero.
2507 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
2509 return updateTextType;
2512 // Whether a new size has been set.
2513 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
2517 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
2519 if( ( 0 == mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd ) &&
2520 ( 0 == mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) &&
2521 ( ( mImpl->mModel->mVisualModel->mControlSize.width < Math::MACHINE_EPSILON_1000 ) || ( mImpl->mModel->mVisualModel->mControlSize.height < Math::MACHINE_EPSILON_1000 ) ) )
2523 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
2526 // Layout operations that need to be done if the size changes.
2527 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2530 UPDATE_LAYOUT_SIZE |
2532 // Set the update info to relayout the whole text.
2533 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2534 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2536 // Store the size used to layout the text.
2537 mImpl->mModel->mVisualModel->mControlSize = size;
2540 // Whether there are modify events.
2541 if( 0u != mImpl->mModifyEvents.Count() )
2543 // Style operations that need to be done if the text is modified.
2544 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2548 // Set the update info to elide the text.
2549 if( mImpl->mModel->mElideEnabled ||
2550 ( ( NULL != mImpl->mEventData ) && mImpl->mEventData->mIsPlaceholderElideEnabled ) )
2552 // Update Text layout for applying elided
2553 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2556 UPDATE_LAYOUT_SIZE |
2558 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2559 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2562 if( mImpl->mModel->mMatchSystemLanguageDirection && mImpl->mLayoutDirection != layoutDirection )
2564 // Clear the update info. This info will be set the next time the text is updated.
2565 mImpl->mTextUpdateInfo.mClearAll = true;
2566 // Apply modifications to the model
2567 // Shape the text again is needed because characters like '()[]{}' have to be mirrored and the glyphs generated again.
2568 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2575 mImpl->mLayoutDirection = layoutDirection;
2578 // Make sure the model is up-to-date before layouting.
2579 ProcessModifyEvents();
2580 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
2584 updated = DoRelayout( size,
2585 mImpl->mOperationsPending,
2586 layoutSize ) || updated;
2591 updateTextType = MODEL_UPDATED;
2594 // Do not re-do any operation until something changes.
2595 mImpl->mOperationsPending = NO_OPERATION;
2596 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
2598 // Whether the text control is editable
2599 const bool isEditable = NULL != mImpl->mEventData;
2601 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
2603 if( newSize && isEditable )
2605 offset = mImpl->mModel->mScrollPosition;
2608 if( !isEditable || !IsMultiLineEnabled() )
2610 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
2611 CalculateVerticalOffset( size );
2618 // If there is a new size, the scroll position needs to be clamped.
2619 mImpl->ClampHorizontalScroll( layoutSize );
2621 // Update the decorator's positions is needed if there is a new size.
2622 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
2625 // Move the cursor, grab handle etc.
2626 if( mImpl->ProcessInputEvents() )
2628 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
2632 // Clear the update info. This info will be set the next time the text is updated.
2633 mImpl->mTextUpdateInfo.Clear();
2634 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
2636 return updateTextType;
2639 void Controller::RequestRelayout()
2641 mImpl->RequestRelayout();
2644 // public : Input style change signals.
2646 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
2648 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
2651 void Controller::ProcessInputStyleChangedSignals()
2653 if( NULL == mImpl->mEventData )
2659 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
2660 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
2664 const InputStyle::Mask mask = *it;
2666 if( NULL != mImpl->mEditableControlInterface )
2668 // Emit the input style changed signal.
2669 mImpl->mEditableControlInterface->InputStyleChanged( mask );
2673 mImpl->mEventData->mInputStyleChangedQueue.Clear();
2676 // public : Text-input Event Queuing.
2678 void Controller::KeyboardFocusGainEvent()
2680 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
2682 if( NULL != mImpl->mEventData )
2684 if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
2685 ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
2687 mImpl->ChangeState( EventData::EDITING );
2688 mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
2689 mImpl->mEventData->mUpdateInputStyle = true;
2690 mImpl->mEventData->mScrollAfterUpdatePosition = true;
2692 mImpl->NotifyInputMethodContextMultiLineStatus();
2693 if( mImpl->IsShowingPlaceholderText() )
2695 // Show alternative placeholder-text when editing
2696 ShowPlaceholderText();
2699 mImpl->RequestRelayout();
2703 void Controller::KeyboardFocusLostEvent()
2705 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
2707 if( NULL != mImpl->mEventData )
2709 if( EventData::INTERRUPTED != mImpl->mEventData->mState )
2711 mImpl->ChangeState( EventData::INACTIVE );
2713 if( !mImpl->IsShowingRealText() )
2715 // Revert to regular placeholder-text when not editing
2716 ShowPlaceholderText();
2720 mImpl->RequestRelayout();
2723 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
2725 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
2727 bool textChanged = false;
2728 bool relayoutNeeded = false;
2730 if( ( NULL != mImpl->mEventData ) &&
2731 ( keyEvent.state == KeyEvent::Down ) )
2733 int keyCode = keyEvent.keyCode;
2734 const std::string& keyString = keyEvent.keyPressed;
2735 const std::string keyName = keyEvent.keyPressedName;
2737 const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
2739 // Pre-process to separate modifying events from non-modifying input events.
2742 // In some platforms arrive key events with no key code.
2746 else if( Dali::DALI_KEY_ESCAPE == keyCode || Dali::DALI_KEY_BACK == keyCode || Dali::DALI_KEY_SEARCH == keyCode )
2751 else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) ||
2752 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
2753 ( Dali::DALI_KEY_CURSOR_UP == keyCode ) ||
2754 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) )
2756 // If don't have any text, do nothing.
2757 if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
2762 uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition;
2763 uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2764 uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition );
2765 uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines();
2767 // Logic to determine whether this text control will lose focus or not.
2768 if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2769 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2770 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) ||
2771 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) ||
2772 ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) ||
2773 ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) )
2775 // Release the active highlight.
2776 if( mImpl->mEventData->mState == EventData::SELECTING )
2778 mImpl->ChangeState( EventData::EDITING );
2780 // Update selection position.
2781 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2782 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2783 mImpl->mEventData->mUpdateCursorPosition = true;
2784 mImpl->RequestRelayout();
2789 mImpl->mEventData->mCheckScrollAmount = true;
2790 Event event( Event::CURSOR_KEY_EVENT );
2791 event.p1.mInt = keyCode;
2792 event.p2.mBool = keyEvent.IsShiftModifier();
2793 mImpl->mEventData->mEventQueue.push_back( event );
2795 // Will request for relayout.
2796 relayoutNeeded = true;
2798 else if ( Dali::DevelKey::DALI_KEY_CONTROL_LEFT == keyCode || Dali::DevelKey::DALI_KEY_CONTROL_RIGHT == keyCode )
2800 // Left or Right Control key event is received before Ctrl-C/V/X key event is received
2801 // If not handle it here, any selected text will be deleted
2806 else if ( keyEvent.IsCtrlModifier() )
2808 bool consumed = false;
2809 if (keyName == KEY_C_NAME)
2811 // Ctrl-C to copy the selected text
2812 TextPopupButtonTouched( Toolkit::TextSelectionPopup::COPY );
2815 else if (keyName == KEY_V_NAME)
2817 // Ctrl-V to paste the copied text
2818 TextPopupButtonTouched( Toolkit::TextSelectionPopup::PASTE );
2821 else if (keyName == KEY_X_NAME)
2823 // Ctrl-X to cut the selected text
2824 TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
2829 else if( ( Dali::DALI_KEY_BACKSPACE == keyCode ) ||
2830 ( Dali::DevelKey::DALI_KEY_DELETE == keyCode ) )
2832 textChanged = DeleteEvent( keyCode );
2834 // Will request for relayout.
2835 relayoutNeeded = true;
2837 else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
2838 IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
2839 IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
2841 // Power key/Menu/Home key behaviour does not allow edit mode to resume.
2842 mImpl->ChangeState( EventData::INACTIVE );
2844 // Will request for relayout.
2845 relayoutNeeded = true;
2847 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2849 else if( ( Dali::DALI_KEY_SHIFT_LEFT == keyCode ) || ( Dali::DALI_KEY_SHIFT_RIGHT == keyCode ) )
2851 // 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
2852 // and a character is typed after the type of a upper case latin character.
2857 else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
2859 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2865 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
2867 if( !keyString.empty() )
2869 // InputMethodContext is no longer handling key-events
2870 mImpl->ClearPreEditFlag();
2872 InsertText( keyString, COMMIT );
2876 // Will request for relayout.
2877 relayoutNeeded = true;
2882 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
2883 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
2885 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
2886 ( Dali::DALI_KEY_SHIFT_RIGHT != keyCode ) &&
2887 ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
2888 ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
2890 // Should not change the state if the key is the shift send by the InputMethodContext.
2891 // Otherwise, when the state is SELECTING the text controller can't send the right
2892 // surrounding info to the InputMethodContext.
2893 mImpl->ChangeState( EventData::EDITING );
2895 // Will request for relayout.
2896 relayoutNeeded = true;
2899 if( relayoutNeeded )
2901 mImpl->RequestRelayout();
2906 ( NULL != mImpl->mEditableControlInterface ) )
2908 // Do this last since it provides callbacks into application code
2909 mImpl->mEditableControlInterface->TextChanged();
2915 void Controller::TapEvent( unsigned int tapCount, float x, float y )
2917 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
2919 if( NULL != mImpl->mEventData )
2921 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
2922 EventData::State state( mImpl->mEventData->mState );
2923 bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
2925 if( mImpl->IsClipboardVisible() )
2927 if( EventData::INACTIVE == state || EventData::EDITING == state)
2929 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2931 relayoutNeeded = true;
2933 else if( 1u == tapCount )
2935 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
2937 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
2940 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
2942 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2943 relayoutNeeded = true;
2947 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
2949 // Hide placeholder text
2953 if( EventData::INACTIVE == state )
2955 mImpl->ChangeState( EventData::EDITING );
2957 else if( !mImpl->IsClipboardEmpty() )
2959 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
2961 relayoutNeeded = true;
2964 else if( 2u == tapCount )
2966 if( mImpl->mEventData->mSelectionEnabled &&
2967 mImpl->IsShowingRealText() )
2969 relayoutNeeded = true;
2970 mImpl->mEventData->mIsLeftHandleSelected = true;
2971 mImpl->mEventData->mIsRightHandleSelected = true;
2975 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
2976 if( relayoutNeeded )
2978 Event event( Event::TAP_EVENT );
2979 event.p1.mUint = tapCount;
2980 event.p2.mFloat = x;
2981 event.p3.mFloat = y;
2982 mImpl->mEventData->mEventQueue.push_back( event );
2984 mImpl->RequestRelayout();
2988 // Reset keyboard as tap event has occurred.
2989 mImpl->ResetInputMethodContext();
2992 void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
2994 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
2996 if( NULL != mImpl->mEventData )
2998 Event event( Event::PAN_EVENT );
2999 event.p1.mInt = state;
3000 event.p2.mFloat = displacement.x;
3001 event.p3.mFloat = displacement.y;
3002 mImpl->mEventData->mEventQueue.push_back( event );
3004 mImpl->RequestRelayout();
3008 void Controller::LongPressEvent( Gesture::State state, float x, float y )
3010 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
3012 if( ( state == Gesture::Started ) &&
3013 ( NULL != mImpl->mEventData ) )
3015 // The 1st long-press on inactive text-field is treated as tap
3016 if( EventData::INACTIVE == mImpl->mEventData->mState )
3018 mImpl->ChangeState( EventData::EDITING );
3020 Event event( Event::TAP_EVENT );
3022 event.p2.mFloat = x;
3023 event.p3.mFloat = y;
3024 mImpl->mEventData->mEventQueue.push_back( event );
3026 mImpl->RequestRelayout();
3028 else if( !mImpl->IsShowingRealText() )
3030 Event event( Event::LONG_PRESS_EVENT );
3031 event.p1.mInt = state;
3032 event.p2.mFloat = x;
3033 event.p3.mFloat = y;
3034 mImpl->mEventData->mEventQueue.push_back( event );
3035 mImpl->RequestRelayout();
3037 else if( !mImpl->IsClipboardVisible() )
3039 // Reset the InputMethodContext to commit the pre-edit before selecting the text.
3040 mImpl->ResetInputMethodContext();
3042 Event event( Event::LONG_PRESS_EVENT );
3043 event.p1.mInt = state;
3044 event.p2.mFloat = x;
3045 event.p3.mFloat = y;
3046 mImpl->mEventData->mEventQueue.push_back( event );
3047 mImpl->RequestRelayout();
3049 mImpl->mEventData->mIsLeftHandleSelected = true;
3050 mImpl->mEventData->mIsRightHandleSelected = true;
3055 void Controller::SelectEvent( float x, float y, bool selectAll )
3057 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
3059 if( NULL != mImpl->mEventData )
3063 Event event( Event::SELECT_ALL );
3064 mImpl->mEventData->mEventQueue.push_back( event );
3068 Event event( Event::SELECT );
3069 event.p2.mFloat = x;
3070 event.p3.mFloat = y;
3071 mImpl->mEventData->mEventQueue.push_back( event );
3074 mImpl->mEventData->mCheckScrollAmount = true;
3075 mImpl->mEventData->mIsLeftHandleSelected = true;
3076 mImpl->mEventData->mIsRightHandleSelected = true;
3077 mImpl->RequestRelayout();
3081 InputMethodContext::CallbackData Controller::OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
3083 // Whether the text needs to be relaid-out.
3084 bool requestRelayout = false;
3086 // Whether to retrieve the text and cursor position to be sent to the InputMethodContext.
3087 bool retrieveText = false;
3088 bool retrieveCursor = false;
3090 switch( inputMethodContextEvent.eventName )
3092 case InputMethodContext::COMMIT:
3094 InsertText( inputMethodContextEvent.predictiveString, Text::Controller::COMMIT );
3095 requestRelayout = true;
3096 retrieveCursor = true;
3099 case InputMethodContext::PRE_EDIT:
3101 InsertText( inputMethodContextEvent.predictiveString, Text::Controller::PRE_EDIT );
3102 requestRelayout = true;
3103 retrieveCursor = true;
3106 case InputMethodContext::DELETE_SURROUNDING:
3108 const bool textDeleted = RemoveText( inputMethodContextEvent.cursorOffset,
3109 inputMethodContextEvent.numberOfChars,
3110 DONT_UPDATE_INPUT_STYLE );
3114 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3115 !mImpl->IsPlaceholderAvailable() )
3117 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3121 ShowPlaceholderText();
3123 mImpl->mEventData->mUpdateCursorPosition = true;
3124 mImpl->mEventData->mScrollAfterDelete = true;
3126 requestRelayout = true;
3130 case InputMethodContext::GET_SURROUNDING:
3132 retrieveText = true;
3133 retrieveCursor = true;
3136 case InputMethodContext::PRIVATE_COMMAND:
3138 // PRIVATECOMMAND event is just for getting the private command message
3139 retrieveText = true;
3140 retrieveCursor = true;
3143 case InputMethodContext::VOID:
3150 if( requestRelayout )
3152 mImpl->mOperationsPending = ALL_OPERATIONS;
3153 mImpl->RequestRelayout();
3157 CharacterIndex cursorPosition = 0u;
3158 Length numberOfWhiteSpaces = 0u;
3160 if( retrieveCursor )
3162 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
3164 cursorPosition = mImpl->GetLogicalCursorPosition();
3166 if( cursorPosition < numberOfWhiteSpaces )
3168 cursorPosition = 0u;
3172 cursorPosition -= numberOfWhiteSpaces;
3178 if( !mImpl->IsShowingPlaceholderText() )
3180 // Retrieves the normal text string.
3181 mImpl->GetText( numberOfWhiteSpaces, text );
3185 // When the current text is Placeholder Text, the surrounding text should be empty string.
3186 // It means DALi should send empty string ("") to IME.
3191 InputMethodContext::CallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
3193 if( requestRelayout &&
3194 ( NULL != mImpl->mEditableControlInterface ) )
3196 // Do this last since it provides callbacks into application code
3197 mImpl->mEditableControlInterface->TextChanged();
3200 return callbackData;
3203 void Controller::PasteClipboardItemEvent()
3205 // Retrieve the clipboard contents first
3206 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
3207 std::string stringToPaste( notifier.GetContent() );
3209 // Commit the current pre-edit text; the contents of the clipboard should be appended
3210 mImpl->ResetInputMethodContext();
3212 // Temporary disable hiding clipboard
3213 mImpl->SetClipboardHideEnable( false );
3216 PasteText( stringToPaste );
3218 mImpl->SetClipboardHideEnable( true );
3221 // protected : Inherit from Text::Decorator::ControllerInterface.
3223 void Controller::GetTargetSize( Vector2& targetSize )
3225 targetSize = mImpl->mModel->mVisualModel->mControlSize;
3228 void Controller::AddDecoration( Actor& actor, bool needsClipping )
3230 if( NULL != mImpl->mEditableControlInterface )
3232 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
3236 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
3238 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
3240 if( NULL != mImpl->mEventData )
3242 switch( handleType )
3246 Event event( Event::GRAB_HANDLE_EVENT );
3247 event.p1.mUint = state;
3248 event.p2.mFloat = x;
3249 event.p3.mFloat = y;
3251 mImpl->mEventData->mEventQueue.push_back( event );
3254 case LEFT_SELECTION_HANDLE:
3256 Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
3257 event.p1.mUint = state;
3258 event.p2.mFloat = x;
3259 event.p3.mFloat = y;
3261 mImpl->mEventData->mEventQueue.push_back( event );
3264 case RIGHT_SELECTION_HANDLE:
3266 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
3267 event.p1.mUint = state;
3268 event.p2.mFloat = x;
3269 event.p3.mFloat = y;
3271 mImpl->mEventData->mEventQueue.push_back( event );
3274 case LEFT_SELECTION_HANDLE_MARKER:
3275 case RIGHT_SELECTION_HANDLE_MARKER:
3277 // Markers do not move the handles.
3280 case HANDLE_TYPE_COUNT:
3282 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
3286 mImpl->RequestRelayout();
3290 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
3292 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
3294 if( NULL == mImpl->mEventData )
3301 case Toolkit::TextSelectionPopup::CUT:
3303 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
3304 mImpl->mOperationsPending = ALL_OPERATIONS;
3306 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3307 !mImpl->IsPlaceholderAvailable() )
3309 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3313 ShowPlaceholderText();
3316 mImpl->mEventData->mUpdateCursorPosition = true;
3317 mImpl->mEventData->mScrollAfterDelete = true;
3319 mImpl->RequestRelayout();
3321 if( NULL != mImpl->mEditableControlInterface )
3323 mImpl->mEditableControlInterface->TextChanged();
3327 case Toolkit::TextSelectionPopup::COPY:
3329 mImpl->SendSelectionToClipboard( false ); // Text not modified
3331 mImpl->mEventData->mUpdateCursorPosition = true;
3333 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
3336 case Toolkit::TextSelectionPopup::PASTE:
3338 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
3341 case Toolkit::TextSelectionPopup::SELECT:
3343 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
3345 if( mImpl->mEventData->mSelectionEnabled )
3347 // Creates a SELECT event.
3348 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
3352 case Toolkit::TextSelectionPopup::SELECT_ALL:
3354 // Creates a SELECT_ALL event
3355 SelectEvent( 0.f, 0.f, true );
3358 case Toolkit::TextSelectionPopup::CLIPBOARD:
3360 mImpl->ShowClipboard();
3363 case Toolkit::TextSelectionPopup::NONE:
3371 void Controller::DisplayTimeExpired()
3373 mImpl->mEventData->mUpdateCursorPosition = true;
3374 // Apply modifications to the model
3375 mImpl->mOperationsPending = ALL_OPERATIONS;
3377 mImpl->RequestRelayout();
3380 // private : Update.
3382 void Controller::InsertText( const std::string& text, Controller::InsertType type )
3384 bool removedPrevious = false;
3385 bool removedSelected = false;
3386 bool maxLengthReached = false;
3388 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
3390 if( NULL == mImpl->mEventData )
3395 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
3396 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
3397 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3399 // TODO: At the moment the underline runs are only for pre-edit.
3400 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
3402 // Remove the previous InputMethodContext pre-edit.
3403 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
3405 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
3406 mImpl->mEventData->mPreEditLength,
3407 DONT_UPDATE_INPUT_STYLE );
3409 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
3410 mImpl->mEventData->mPreEditLength = 0u;
3414 // Remove the previous Selection.
3415 removedSelected = RemoveSelectedText();
3419 Vector<Character> utf32Characters;
3420 Length characterCount = 0u;
3424 // Convert text into UTF-32
3425 utf32Characters.Resize( text.size() );
3427 // This is a bit horrible but std::string returns a (signed) char*
3428 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
3430 // Transform a text array encoded in utf8 into an array encoded in utf32.
3431 // It returns the actual number of characters.
3432 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
3433 utf32Characters.Resize( characterCount );
3435 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
3436 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
3439 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
3441 // The placeholder text is no longer needed
3442 if( mImpl->IsShowingPlaceholderText() )
3447 mImpl->ChangeState( EventData::EDITING );
3449 // Handle the InputMethodContext (predicitive text) state changes
3450 if( COMMIT == type )
3452 // InputMethodContext is no longer handling key-events
3453 mImpl->ClearPreEditFlag();
3457 if( !mImpl->mEventData->mPreEditFlag )
3459 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
3461 // Record the start of the pre-edit text
3462 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
3465 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
3466 mImpl->mEventData->mPreEditFlag = true;
3468 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3471 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
3473 // Restrict new text to fit within Maximum characters setting.
3474 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
3475 maxLengthReached = ( characterCount > maxSizeOfNewText );
3477 // The cursor position.
3478 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3480 // Update the text's style.
3482 // Updates the text style runs by adding characters.
3483 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
3485 // Get the character index from the cursor index.
3486 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
3488 // Retrieve the text's style for the given index.
3490 mImpl->RetrieveDefaultInputStyle( style );
3491 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
3493 // Whether to add a new text color run.
3494 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor ) && !mImpl->mEventData->mInputStyle.isDefaultColor;
3496 // Whether to add a new font run.
3497 const bool addFontNameRun = ( style.familyName != mImpl->mEventData->mInputStyle.familyName ) && mImpl->mEventData->mInputStyle.isFamilyDefined;
3498 const bool addFontWeightRun = ( style.weight != mImpl->mEventData->mInputStyle.weight ) && mImpl->mEventData->mInputStyle.isWeightDefined;
3499 const bool addFontWidthRun = ( style.width != mImpl->mEventData->mInputStyle.width ) && mImpl->mEventData->mInputStyle.isWidthDefined;
3500 const bool addFontSlantRun = ( style.slant != mImpl->mEventData->mInputStyle.slant ) && mImpl->mEventData->mInputStyle.isSlantDefined;
3501 const bool addFontSizeRun = ( style.size != mImpl->mEventData->mInputStyle.size ) && mImpl->mEventData->mInputStyle.isSizeDefined ;
3506 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
3507 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
3509 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
3510 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
3511 colorRun.characterRun.characterIndex = cursorIndex;
3512 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3515 if( addFontNameRun ||
3521 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
3522 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
3524 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
3526 if( addFontNameRun )
3528 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
3529 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
3530 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
3531 fontDescriptionRun.familyDefined = true;
3533 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
3536 if( addFontWeightRun )
3538 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
3539 fontDescriptionRun.weightDefined = true;
3542 if( addFontWidthRun )
3544 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
3545 fontDescriptionRun.widthDefined = true;
3548 if( addFontSlantRun )
3550 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
3551 fontDescriptionRun.slantDefined = true;
3554 if( addFontSizeRun )
3556 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
3557 fontDescriptionRun.sizeDefined = true;
3560 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
3561 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3564 // Insert at current cursor position.
3565 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
3567 auto pos = modifyText.End();
3568 if( cursorIndex < numberOfCharactersInModel )
3570 pos = modifyText.Begin() + cursorIndex;
3572 unsigned int realPos = pos - modifyText.Begin();
3573 modifyText.Insert( pos, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3575 if( NULL != mImpl->mEditableControlInterface )
3577 mImpl->mEditableControlInterface->TextInserted( realPos, maxSizeOfNewText, text );
3580 // Mark the first paragraph to be updated.
3581 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3583 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3584 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3585 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
3586 mImpl->mTextUpdateInfo.mClearAll = true;
3590 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3591 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
3594 // Update the cursor index.
3595 cursorIndex += maxSizeOfNewText;
3597 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 );
3600 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
3601 mImpl->IsPlaceholderAvailable() )
3603 // Show place-holder if empty after removing the pre-edit text
3604 ShowPlaceholderText();
3605 mImpl->mEventData->mUpdateCursorPosition = true;
3606 mImpl->ClearPreEditFlag();
3608 else if( removedPrevious ||
3610 ( 0 != utf32Characters.Count() ) )
3612 // Queue an inserted event
3613 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
3615 mImpl->mEventData->mUpdateCursorPosition = true;
3616 if( removedSelected )
3618 mImpl->mEventData->mScrollAfterDelete = true;
3622 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3626 if( maxLengthReached )
3628 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
3630 mImpl->ResetInputMethodContext();
3632 if( NULL != mImpl->mEditableControlInterface )
3634 // Do this last since it provides callbacks into application code
3635 mImpl->mEditableControlInterface->MaxLengthReached();
3640 void Controller::PasteText( const std::string& stringToPaste )
3642 InsertText( stringToPaste, Text::Controller::COMMIT );
3643 mImpl->ChangeState( EventData::EDITING );
3644 mImpl->RequestRelayout();
3646 if( NULL != mImpl->mEditableControlInterface )
3648 // Do this last since it provides callbacks into application code
3649 mImpl->mEditableControlInterface->TextChanged();
3653 bool Controller::RemoveText( int cursorOffset,
3654 int numberOfCharacters,
3655 UpdateInputStyleType type )
3657 bool removed = false;
3659 if( NULL == mImpl->mEventData )
3664 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
3665 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
3667 if( !mImpl->IsShowingPlaceholderText() )
3669 // Delete at current cursor position
3670 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
3671 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3673 CharacterIndex cursorIndex = 0;
3675 // Validate the cursor position & number of characters
3676 if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
3678 cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
3681 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
3683 numberOfCharacters = currentText.Count() - cursorIndex;
3686 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.
3687 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
3689 // Mark the paragraphs to be updated.
3690 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3692 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3693 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3694 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
3695 mImpl->mTextUpdateInfo.mClearAll = true;
3699 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3700 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
3703 // Update the input style and remove the text's style before removing the text.
3705 if( UPDATE_INPUT_STYLE == type )
3707 // Keep a copy of the current input style.
3708 InputStyle currentInputStyle;
3709 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
3711 // Set first the default input style.
3712 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
3714 // Update the input style.
3715 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
3717 // Compare if the input style has changed.
3718 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
3720 if( hasInputStyleChanged )
3722 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
3723 // Queue the input style changed signal.
3724 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
3728 // Updates the text style runs by removing characters. Runs with no characters are removed.
3729 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
3731 // Remove the characters.
3732 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
3733 Vector<Character>::Iterator last = first + numberOfCharacters;
3735 currentText.Erase( first, last );
3737 if( NULL != mImpl->mEditableControlInterface )
3740 Utf32ToUtf8( first, numberOfCharacters, utf8 );
3741 mImpl->mEditableControlInterface->TextDeleted( cursorIndex, numberOfCharacters, utf8 );
3744 // Cursor position retreat
3745 oldCursorIndex = cursorIndex;
3747 mImpl->mEventData->mScrollAfterDelete = true;
3749 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
3757 bool Controller::RemoveSelectedText()
3759 bool textRemoved( false );
3761 if( EventData::SELECTING == mImpl->mEventData->mState )
3763 std::string removedString;
3764 mImpl->RetrieveSelection( removedString, true );
3766 if( !removedString.empty() )
3769 mImpl->ChangeState( EventData::EDITING );
3776 // private : Relayout.
3778 bool Controller::DoRelayout( const Size& size,
3779 OperationsMask operationsRequired,
3782 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
3783 bool viewUpdated( false );
3785 // Calculate the operations to be done.
3786 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
3788 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
3789 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
3791 // Get the current layout size.
3792 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3794 if( NO_OPERATION != ( LAYOUT & operations ) )
3796 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
3798 // Some vectors with data needed to layout and reorder may be void
3799 // after the first time the text has been laid out.
3800 // Fill the vectors again.
3802 // Calculate the number of glyphs to layout.
3803 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
3804 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
3805 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
3806 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
3808 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
3809 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
3811 // Make sure the index is not out of bound
3812 if ( charactersToGlyph.Count() != glyphsPerCharacter.Count() ||
3813 requestedNumberOfCharacters > charactersToGlyph.Count() ||
3814 ( lastIndex >= charactersToGlyph.Count() && charactersToGlyph.Count() > 0u ) )
3816 std::string currentText;
3817 GetText( currentText );
3819 DALI_LOG_ERROR( "Controller::DoRelayout: Attempting to access invalid buffer\n" );
3820 DALI_LOG_ERROR( "Current text is: %s\n", currentText.c_str() );
3821 DALI_LOG_ERROR( "startIndex: %u, lastIndex: %u, requestedNumberOfCharacters: %u, charactersToGlyph.Count = %lu, glyphsPerCharacter.Count = %lu\n", startIndex, lastIndex, requestedNumberOfCharacters, charactersToGlyph.Count(), glyphsPerCharacter.Count());
3826 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
3827 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
3829 if( 0u == totalNumberOfGlyphs )
3831 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3833 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
3836 // Nothing else to do if there is no glyphs.
3837 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
3841 const Vector<LineBreakInfo>& lineBreakInfo = mImpl->mModel->mLogicalModel->mLineBreakInfo;
3842 const Vector<WordBreakInfo>& wordBreakInfo = mImpl->mModel->mLogicalModel->mWordBreakInfo;
3843 const Vector<CharacterDirection>& characterDirection = mImpl->mModel->mLogicalModel->mCharacterDirections;
3844 const Vector<GlyphInfo>& glyphs = mImpl->mModel->mVisualModel->mGlyphs;
3845 const Vector<CharacterIndex>& glyphsToCharactersMap = mImpl->mModel->mVisualModel->mGlyphsToCharacters;
3846 const Vector<Length>& charactersPerGlyph = mImpl->mModel->mVisualModel->mCharactersPerGlyph;
3847 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
3848 const float outlineWidth = static_cast<float>( mImpl->mModel->GetOutlineWidth() );
3850 // Set the layout parameters.
3851 Layout::Parameters layoutParameters( size,
3853 lineBreakInfo.Begin(),
3854 wordBreakInfo.Begin(),
3855 ( 0u != characterDirection.Count() ) ? characterDirection.Begin() : NULL,
3857 glyphsToCharactersMap.Begin(),
3858 charactersPerGlyph.Begin(),
3859 charactersToGlyphBuffer,
3860 glyphsPerCharacterBuffer,
3861 totalNumberOfGlyphs,
3862 mImpl->mModel->mHorizontalAlignment,
3863 mImpl->mModel->mLineWrapMode,
3865 mImpl->mModel->mIgnoreSpacesAfterText,
3866 mImpl->mModel->mMatchSystemLanguageDirection );
3868 // Resize the vector of positions to have the same size than the vector of glyphs.
3869 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
3870 glyphPositions.Resize( totalNumberOfGlyphs );
3872 // Whether the last character is a new paragraph character.
3873 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
3874 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
3876 // The initial glyph and the number of glyphs to layout.
3877 layoutParameters.startGlyphIndex = startGlyphIndex;
3878 layoutParameters.numberOfGlyphs = numberOfGlyphs;
3879 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
3880 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
3882 // Update the ellipsis
3883 bool elideTextEnabled = mImpl->mModel->mElideEnabled;
3885 if( NULL != mImpl->mEventData )
3887 if( mImpl->mEventData->mPlaceholderEllipsisFlag && mImpl->IsShowingPlaceholderText() )
3889 elideTextEnabled = mImpl->mEventData->mIsPlaceholderElideEnabled;
3891 else if( EventData::INACTIVE != mImpl->mEventData->mState )
3893 // Disable ellipsis when editing
3894 elideTextEnabled = false;
3897 // Reset the scroll position in inactive state
3898 if( elideTextEnabled && ( mImpl->mEventData->mState == EventData::INACTIVE ) )
3900 ResetScrollPosition();
3904 // Update the visual model.
3905 bool isAutoScrollEnabled = mImpl->mIsAutoScrollEnabled;
3907 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
3909 mImpl->mModel->mVisualModel->mLines,
3912 isAutoScrollEnabled );
3913 mImpl->mIsAutoScrollEnabled = isAutoScrollEnabled;
3915 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
3919 layoutSize = newLayoutSize;
3921 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
3923 mImpl->mIsTextDirectionRTL = false;
3926 // Reorder the lines
3927 if( NO_OPERATION != ( REORDER & operations ) )
3929 Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = mImpl->mModel->mLogicalModel->mBidirectionalParagraphInfo;
3930 Vector<BidirectionalLineInfoRun>& bidirectionalLineInfo = mImpl->mModel->mLogicalModel->mBidirectionalLineInfo;
3932 // Check first if there are paragraphs with bidirectional info.
3933 if( 0u != bidirectionalInfo.Count() )
3936 const Length numberOfLines = mImpl->mModel->mVisualModel->mLines.Count();
3938 // Reorder the lines.
3939 bidirectionalLineInfo.Reserve( numberOfLines ); // Reserve because is not known yet how many lines have right to left characters.
3940 ReorderLines( bidirectionalInfo,
3942 requestedNumberOfCharacters,
3943 mImpl->mModel->mVisualModel->mLines,
3944 bidirectionalLineInfo );
3946 // Set the bidirectional info per line into the layout parameters.
3947 layoutParameters.lineBidirectionalInfoRunsBuffer = bidirectionalLineInfo.Begin();
3948 layoutParameters.numberOfBidirectionalInfoRuns = bidirectionalLineInfo.Count();
3950 // Re-layout the text. Reorder those lines with right to left characters.
3951 mImpl->mLayoutEngine.ReLayoutRightToLeftLines( layoutParameters,
3953 requestedNumberOfCharacters,
3956 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && ( numberOfLines > 0 ) )
3958 const LineRun* const firstline = mImpl->mModel->mVisualModel->mLines.Begin();
3961 mImpl->mIsTextDirectionRTL = firstline->direction;
3967 // Sets the layout size.
3968 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3970 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
3975 if( NO_OPERATION != ( ALIGN & operations ) )
3977 // The laid-out lines.
3978 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
3980 // Need to align with the control's size as the text may contain lines
3981 // starting either with left to right text or right to left.
3982 mImpl->mLayoutEngine.Align( size,
3984 requestedNumberOfCharacters,
3985 mImpl->mModel->mHorizontalAlignment,
3987 mImpl->mModel->mAlignmentOffset,
3988 mImpl->mLayoutDirection,
3989 mImpl->mModel->mMatchSystemLanguageDirection );
3993 #if defined(DEBUG_ENABLED)
3994 std::string currentText;
3995 GetText( currentText );
3996 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mIsTextDirectionRTL[%s] [%s]\n", this, (mImpl->mIsTextDirectionRTL)?"true":"false", currentText.c_str() );
3998 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
4002 void Controller::CalculateVerticalOffset( const Size& controlSize )
4004 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
4006 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
4008 // Get the line height of the default font.
4009 layoutSize.height = mImpl->GetDefaultFontLineHeight();
4012 switch( mImpl->mModel->mVerticalAlignment )
4014 case VerticalAlignment::TOP:
4016 mImpl->mModel->mScrollPosition.y = 0.f;
4019 case VerticalAlignment::CENTER:
4021 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
4024 case VerticalAlignment::BOTTOM:
4026 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
4032 // private : Events.
4034 void Controller::ProcessModifyEvents()
4036 Vector<ModifyEvent>& events = mImpl->mModifyEvents;
4038 if( 0u == events.Count() )
4044 for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
4045 endIt = events.End();
4049 const ModifyEvent& event = *it;
4051 if( ModifyEvent::TEXT_REPLACED == event.type )
4053 // A (single) replace event should come first, otherwise we wasted time processing NOOP events
4054 DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
4056 TextReplacedEvent();
4058 else if( ModifyEvent::TEXT_INSERTED == event.type )
4060 TextInsertedEvent();
4062 else if( ModifyEvent::TEXT_DELETED == event.type )
4064 // Placeholder-text cannot be deleted
4065 if( !mImpl->IsShowingPlaceholderText() )
4072 if( NULL != mImpl->mEventData )
4074 // When the text is being modified, delay cursor blinking
4075 mImpl->mEventData->mDecorator->DelayCursorBlink();
4077 // Update selection position after modifying the text
4078 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
4079 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
4082 // Discard temporary text
4086 void Controller::TextReplacedEvent()
4088 // The natural size needs to be re-calculated.
4089 mImpl->mRecalculateNaturalSize = true;
4091 // The text direction needs to be updated.
4092 mImpl->mUpdateTextDirection = true;
4094 // Apply modifications to the model
4095 mImpl->mOperationsPending = ALL_OPERATIONS;
4098 void Controller::TextInsertedEvent()
4100 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
4102 if( NULL == mImpl->mEventData )
4107 mImpl->mEventData->mCheckScrollAmount = true;
4109 // The natural size needs to be re-calculated.
4110 mImpl->mRecalculateNaturalSize = true;
4112 // The text direction needs to be updated.
4113 mImpl->mUpdateTextDirection = true;
4115 // Apply modifications to the model; TODO - Optimize this
4116 mImpl->mOperationsPending = ALL_OPERATIONS;
4119 void Controller::TextDeletedEvent()
4121 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
4123 if( NULL == mImpl->mEventData )
4128 mImpl->mEventData->mCheckScrollAmount = true;
4130 // The natural size needs to be re-calculated.
4131 mImpl->mRecalculateNaturalSize = true;
4133 // The text direction needs to be updated.
4134 mImpl->mUpdateTextDirection = true;
4136 // Apply modifications to the model; TODO - Optimize this
4137 mImpl->mOperationsPending = ALL_OPERATIONS;
4140 bool Controller::DeleteEvent( int keyCode )
4142 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p KeyCode : %d \n", this, keyCode );
4144 bool removed = false;
4146 if( NULL == mImpl->mEventData )
4151 // InputMethodContext is no longer handling key-events
4152 mImpl->ClearPreEditFlag();
4154 if( EventData::SELECTING == mImpl->mEventData->mState )
4156 removed = RemoveSelectedText();
4158 else if( ( mImpl->mEventData->mPrimaryCursorPosition > 0 ) && ( keyCode == Dali::DALI_KEY_BACKSPACE) )
4160 // Remove the character before the current cursor position
4161 removed = RemoveText( -1,
4163 UPDATE_INPUT_STYLE );
4165 else if( keyCode == Dali::DevelKey::DALI_KEY_DELETE )
4167 // Remove the character after the current cursor position
4168 removed = RemoveText( 0,
4170 UPDATE_INPUT_STYLE );
4175 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
4176 !mImpl->IsPlaceholderAvailable() )
4178 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
4182 ShowPlaceholderText();
4184 mImpl->mEventData->mUpdateCursorPosition = true;
4185 mImpl->mEventData->mScrollAfterDelete = true;
4191 // private : Helpers.
4193 void Controller::ResetText()
4196 mImpl->mModel->mLogicalModel->mText.Clear();
4198 // Reset the embedded images buffer.
4199 mImpl->mModel->mLogicalModel->ClearEmbeddedImages();
4201 // We have cleared everything including the placeholder-text
4202 mImpl->PlaceholderCleared();
4204 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4205 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4206 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
4208 // Clear any previous text.
4209 mImpl->mTextUpdateInfo.mClearAll = true;
4211 // The natural size needs to be re-calculated.
4212 mImpl->mRecalculateNaturalSize = true;
4214 // The text direction needs to be updated.
4215 mImpl->mUpdateTextDirection = true;
4217 // Apply modifications to the model
4218 mImpl->mOperationsPending = ALL_OPERATIONS;
4221 void Controller::ShowPlaceholderText()
4223 if( mImpl->IsPlaceholderAvailable() )
4225 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
4227 if( NULL == mImpl->mEventData )
4232 mImpl->mEventData->mIsShowingPlaceholderText = true;
4234 // Disable handles when showing place-holder text
4235 mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
4236 mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
4237 mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
4239 const char* text( NULL );
4242 // TODO - Switch Placeholder text when changing state
4243 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
4244 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
4246 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
4247 size = mImpl->mEventData->mPlaceholderTextActive.size();
4251 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
4252 size = mImpl->mEventData->mPlaceholderTextInactive.size();
4255 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4256 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4258 // Reset model for showing placeholder.
4259 mImpl->mModel->mLogicalModel->mText.Clear();
4260 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
4262 // Convert text into UTF-32
4263 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
4264 utf32Characters.Resize( size );
4266 // This is a bit horrible but std::string returns a (signed) char*
4267 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
4269 // Transform a text array encoded in utf8 into an array encoded in utf32.
4270 // It returns the actual number of characters.
4271 const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
4272 utf32Characters.Resize( characterCount );
4274 // The characters to be added.
4275 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
4277 // Reset the cursor position
4278 mImpl->mEventData->mPrimaryCursorPosition = 0;
4280 // The natural size needs to be re-calculated.
4281 mImpl->mRecalculateNaturalSize = true;
4283 // The text direction needs to be updated.
4284 mImpl->mUpdateTextDirection = true;
4286 // Apply modifications to the model
4287 mImpl->mOperationsPending = ALL_OPERATIONS;
4289 // Update the rest of the model during size negotiation
4290 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
4294 void Controller::ClearFontData()
4296 if( mImpl->mFontDefaults )
4298 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
4301 // Set flags to update the model.
4302 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4303 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4304 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
4306 mImpl->mTextUpdateInfo.mClearAll = true;
4307 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
4308 mImpl->mRecalculateNaturalSize = true;
4310 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
4316 UPDATE_LAYOUT_SIZE |
4321 void Controller::ClearStyleData()
4323 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
4324 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
4327 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
4329 // Reset the cursor position
4330 if( NULL != mImpl->mEventData )
4332 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
4334 // Update the cursor if it's in editing mode.
4335 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
4337 mImpl->mEventData->mUpdateCursorPosition = true;
4342 CharacterIndex Controller::GetCursorPosition()
4344 if( !mImpl->mEventData )
4347 return mImpl->mEventData->mPrimaryCursorPosition;
4350 void Controller::ResetScrollPosition()
4352 if( NULL != mImpl->mEventData )
4354 // Reset the scroll position.
4355 mImpl->mModel->mScrollPosition = Vector2::ZERO;
4356 mImpl->mEventData->mScrollAfterUpdatePosition = true;
4360 void Controller::SetControlInterface( ControlInterface* controlInterface )
4362 mImpl->mControlInterface = controlInterface;
4365 bool Controller::ShouldClearFocusOnEscape() const
4367 return mImpl->mShouldClearFocusOnEscape;
4370 // private : Private contructors & copy operator.
4372 Controller::Controller()
4375 mImpl = new Controller::Impl( NULL, NULL );
4378 Controller::Controller( ControlInterface* controlInterface )
4380 mImpl = new Controller::Impl( controlInterface, NULL );
4383 Controller::Controller( ControlInterface* controlInterface,
4384 EditableControlInterface* editableControlInterface )
4386 mImpl = new Controller::Impl( controlInterface,
4387 editableControlInterface );
4390 // The copy constructor and operator are left unimplemented.
4392 // protected : Destructor.
4394 Controller::~Controller()
4401 } // namespace Toolkit