2 * Copyright (c) 2017 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>
24 #include <dali/public-api/adaptor-framework/key.h>
25 #include <dali/integration-api/debug.h>
26 #include <dali/devel-api/adaptor-framework/clipboard-event-notifier.h>
27 #include <dali/devel-api/text-abstraction/font-client.h>
30 #include <dali-toolkit/internal/text/bidirectional-support.h>
31 #include <dali-toolkit/internal/text/character-set-conversion.h>
32 #include <dali-toolkit/internal/text/layouts/layout-parameters.h>
33 #include <dali-toolkit/internal/text/markup-processor.h>
34 #include <dali-toolkit/internal/text/text-controller-impl.h>
35 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
40 #if defined(DEBUG_ENABLED)
41 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
44 const float MAX_FLOAT = std::numeric_limits<float>::max();
46 const std::string EMPTY_STRING("");
48 float ConvertToEven( float value )
50 int intValue(static_cast<int>( value ));
51 return static_cast<float>(intValue % 2 == 0) ? intValue : (intValue + 1);
66 * @brief Adds a new font description run for the selected text.
68 * The new font parameters are added after the call to this method.
70 * @param[in] eventData The event data pointer.
71 * @param[in] logicalModel The logical model where to add the new font description run.
72 * @param[out] startOfSelectedText Index to the first selected character.
73 * @param[out] lengthOfSelectedText Number of selected characters.
75 FontDescriptionRun& UpdateSelectionFontStyleRun( EventData* eventData,
76 LogicalModelPtr logicalModel,
77 CharacterIndex& startOfSelectedText,
78 Length& lengthOfSelectedText )
80 const bool handlesCrossed = eventData->mLeftSelectionPosition > eventData->mRightSelectionPosition;
82 // Get start and end position of selection
83 startOfSelectedText = handlesCrossed ? eventData->mRightSelectionPosition : eventData->mLeftSelectionPosition;
84 lengthOfSelectedText = ( handlesCrossed ? eventData->mLeftSelectionPosition : eventData->mRightSelectionPosition ) - startOfSelectedText;
87 const VectorBase::SizeType numberOfRuns = logicalModel->mFontDescriptionRuns.Count();
88 logicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
90 FontDescriptionRun& fontDescriptionRun = *( logicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
92 fontDescriptionRun.characterRun.characterIndex = startOfSelectedText;
93 fontDescriptionRun.characterRun.numberOfCharacters = lengthOfSelectedText;
95 // Recalculate the selection highlight as the metrics may have changed.
96 eventData->mUpdateLeftSelectionPosition = true;
97 eventData->mUpdateRightSelectionPosition = true;
98 eventData->mUpdateHighlightBox = true;
100 return fontDescriptionRun;
103 // public : Constructor.
105 ControllerPtr Controller::New()
107 return ControllerPtr( new Controller() );
110 ControllerPtr Controller::New( ControlInterface* controlInterface )
112 return ControllerPtr( new Controller( controlInterface ) );
115 ControllerPtr Controller::New( ControlInterface* controlInterface,
116 EditableControlInterface* editableControlInterface )
118 return ControllerPtr( new Controller( controlInterface,
119 editableControlInterface ) );
122 // public : Configure the text controller.
124 void Controller::EnableTextInput( DecoratorPtr decorator )
128 delete mImpl->mEventData;
129 mImpl->mEventData = NULL;
131 // Nothing else to do.
135 if( NULL == mImpl->mEventData )
137 mImpl->mEventData = new EventData( decorator );
141 void Controller::SetGlyphType( TextAbstraction::GlyphType glyphType )
143 // Metrics for bitmap & vector based glyphs are different
144 mImpl->mMetrics->SetGlyphType( glyphType );
146 // Clear the font-specific data
149 mImpl->RequestRelayout();
152 void Controller::SetMarkupProcessorEnabled( bool enable )
154 mImpl->mMarkupProcessorEnabled = enable;
157 bool Controller::IsMarkupProcessorEnabled() const
159 return mImpl->mMarkupProcessorEnabled;
162 void Controller::SetAutoScrollEnabled( bool enable )
164 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 );
166 if( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX )
170 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled for SINGLE_LINE_BOX\n" );
171 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
181 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled Disabling autoscroll\n");
182 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
189 mImpl->mIsAutoScrollEnabled = enable;
190 mImpl->RequestRelayout();
194 DALI_LOG_WARNING( "Attempted AutoScrolling on a non SINGLE_LINE_BOX, request ignored\n" );
195 mImpl->mIsAutoScrollEnabled = false;
199 bool Controller::IsAutoScrollEnabled() const
201 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::IsAutoScrollEnabled[%s]\n", mImpl->mIsAutoScrollEnabled?"true":"false" );
203 return mImpl->mIsAutoScrollEnabled;
206 CharacterDirection Controller::GetAutoScrollDirection() const
208 return mImpl->mAutoScrollDirectionRTL;
211 float Controller::GetAutoScrollLineAlignment() const
215 if( mImpl->mModel->mVisualModel &&
216 ( 0u != mImpl->mModel->mVisualModel->mLines.Count() ) )
218 offset = ( *mImpl->mModel->mVisualModel->mLines.Begin() ).alignmentOffset;
224 void Controller::SetHorizontalScrollEnabled( bool enable )
226 if( ( NULL != mImpl->mEventData ) &&
227 mImpl->mEventData->mDecorator )
229 mImpl->mEventData->mDecorator->SetHorizontalScrollEnabled( enable );
232 bool Controller::IsHorizontalScrollEnabled() const
234 if( ( NULL != mImpl->mEventData ) &&
235 mImpl->mEventData->mDecorator )
237 return mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
243 void Controller::SetVerticalScrollEnabled( bool enable )
245 if( ( NULL != mImpl->mEventData ) &&
246 mImpl->mEventData->mDecorator )
248 if( mImpl->mEventData->mDecorator )
250 mImpl->mEventData->mDecorator->SetVerticalScrollEnabled( enable );
255 bool Controller::IsVerticalScrollEnabled() const
257 if( ( NULL != mImpl->mEventData ) &&
258 mImpl->mEventData->mDecorator )
260 return mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
266 void Controller::SetSmoothHandlePanEnabled( bool enable )
268 if( ( NULL != mImpl->mEventData ) &&
269 mImpl->mEventData->mDecorator )
271 mImpl->mEventData->mDecorator->SetSmoothHandlePanEnabled( enable );
275 bool Controller::IsSmoothHandlePanEnabled() const
277 if( ( NULL != mImpl->mEventData ) &&
278 mImpl->mEventData->mDecorator )
280 return mImpl->mEventData->mDecorator->IsSmoothHandlePanEnabled();
286 void Controller::SetMaximumNumberOfCharacters( Length maxCharacters )
288 mImpl->mMaximumNumberOfCharacters = maxCharacters;
291 int Controller::GetMaximumNumberOfCharacters()
293 return mImpl->mMaximumNumberOfCharacters;
296 void Controller::SetEnableCursorBlink( bool enable )
298 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "TextInput disabled" );
300 if( NULL != mImpl->mEventData )
302 mImpl->mEventData->mCursorBlinkEnabled = enable;
305 mImpl->mEventData->mDecorator )
307 mImpl->mEventData->mDecorator->StopCursorBlink();
312 bool Controller::GetEnableCursorBlink() const
314 if( NULL != mImpl->mEventData )
316 return mImpl->mEventData->mCursorBlinkEnabled;
322 void Controller::SetMultiLineEnabled( bool enable )
324 const Layout::Engine::Type layout = enable ? Layout::Engine::MULTI_LINE_BOX : Layout::Engine::SINGLE_LINE_BOX;
326 if( layout != mImpl->mLayoutEngine.GetLayout() )
328 // Set the layout type.
329 mImpl->mLayoutEngine.SetLayout( layout );
331 // Set the flags to redo the layout operations
332 const OperationsMask layoutOperations = static_cast<OperationsMask>( LAYOUT |
337 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | layoutOperations );
339 mImpl->RequestRelayout();
343 bool Controller::IsMultiLineEnabled() const
345 return Layout::Engine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
348 void Controller::SetHorizontalAlignment( Layout::HorizontalAlignment alignment )
350 if( alignment != mImpl->mModel->mHorizontalAlignment )
352 // Set the alignment.
353 mImpl->mModel->mHorizontalAlignment = alignment;
355 // Set the flag to redo the alignment operation.
356 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
358 mImpl->RequestRelayout();
362 Layout::HorizontalAlignment Controller::GetHorizontalAlignment() const
364 return mImpl->mModel->mHorizontalAlignment;
367 void Controller::SetVerticalAlignment( Layout::VerticalAlignment alignment )
369 if( alignment != mImpl->mModel->mVerticalAlignment )
371 // Set the alignment.
372 mImpl->mModel->mVerticalAlignment = alignment;
374 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
376 mImpl->RequestRelayout();
380 Layout::VerticalAlignment Controller::GetVerticalAlignment() const
382 return mImpl->mModel->mVerticalAlignment;
385 void Controller::SetTextElideEnabled( bool enabled )
387 mImpl->mModel->mElideEnabled = enabled;
390 bool Controller::IsTextElideEnabled() const
392 return mImpl->mModel->mElideEnabled;
397 void Controller::SetText( const std::string& text )
399 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" );
401 // Reset keyboard as text changed
402 mImpl->ResetImfManager();
404 // Remove the previously set text and style.
410 CharacterIndex lastCursorIndex = 0u;
412 if( NULL != mImpl->mEventData )
414 // If popup shown then hide it by switching to Editing state
415 if( ( EventData::SELECTING == mImpl->mEventData->mState ) ||
416 ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
417 ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) ||
418 ( EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState ) )
420 mImpl->ChangeState( EventData::EDITING );
426 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mTextColor );
428 MarkupProcessData markupProcessData( mImpl->mModel->mLogicalModel->mColorRuns,
429 mImpl->mModel->mLogicalModel->mFontDescriptionRuns );
431 Length textSize = 0u;
432 const uint8_t* utf8 = NULL;
433 if( mImpl->mMarkupProcessorEnabled )
435 ProcessMarkupString( text, markupProcessData );
436 textSize = markupProcessData.markupProcessedText.size();
438 // This is a bit horrible but std::string returns a (signed) char*
439 utf8 = reinterpret_cast<const uint8_t*>( markupProcessData.markupProcessedText.c_str() );
443 textSize = text.size();
445 // This is a bit horrible but std::string returns a (signed) char*
446 utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
449 // Convert text into UTF-32
450 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
451 utf32Characters.Resize( textSize );
453 // Transform a text array encoded in utf8 into an array encoded in utf32.
454 // It returns the actual number of characters.
455 Length characterCount = Utf8ToUtf32( utf8, textSize, utf32Characters.Begin() );
456 utf32Characters.Resize( characterCount );
458 DALI_ASSERT_DEBUG( textSize >= characterCount && "Invalid UTF32 conversion length" );
459 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", this, textSize, mImpl->mModel->mLogicalModel->mText.Count() );
461 // The characters to be added.
462 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
464 // To reset the cursor position
465 lastCursorIndex = characterCount;
467 // Update the rest of the model during size negotiation
468 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
470 // The natural size needs to be re-calculated.
471 mImpl->mRecalculateNaturalSize = true;
473 // Apply modifications to the model
474 mImpl->mOperationsPending = ALL_OPERATIONS;
478 ShowPlaceholderText();
481 // Resets the cursor position.
482 ResetCursorPosition( lastCursorIndex );
484 // Scrolls the text to make the cursor visible.
485 ResetScrollPosition();
487 mImpl->RequestRelayout();
489 if( NULL != mImpl->mEventData )
491 // Cancel previously queued events
492 mImpl->mEventData->mEventQueue.clear();
495 // Do this last since it provides callbacks into application code.
496 if( NULL != mImpl->mEditableControlInterface )
498 mImpl->mEditableControlInterface->TextChanged();
502 void Controller::GetText( std::string& text ) const
504 if( !mImpl->IsShowingPlaceholderText() )
506 // Retrieves the text string.
507 mImpl->GetText( 0u, text );
511 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this );
515 void Controller::SetPlaceholderText( PlaceholderType type, const std::string& text )
517 if( NULL != mImpl->mEventData )
519 if( PLACEHOLDER_TYPE_INACTIVE == type )
521 mImpl->mEventData->mPlaceholderTextInactive = text;
525 mImpl->mEventData->mPlaceholderTextActive = text;
528 // Update placeholder if there is no text
529 if( mImpl->IsShowingPlaceholderText() ||
530 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
532 ShowPlaceholderText();
537 void Controller::GetPlaceholderText( PlaceholderType type, std::string& text ) const
539 if( NULL != mImpl->mEventData )
541 if( PLACEHOLDER_TYPE_INACTIVE == type )
543 text = mImpl->mEventData->mPlaceholderTextInactive;
547 text = mImpl->mEventData->mPlaceholderTextActive;
552 void Controller::UpdateAfterFontChange( const std::string& newDefaultFont )
554 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
556 if( !mImpl->mFontDefaults->familyDefined ) // If user defined font then should not update when system font changes
558 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
559 mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
563 mImpl->RequestRelayout();
567 // public : Default style & Input style
569 void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
571 if( NULL == mImpl->mFontDefaults )
573 mImpl->mFontDefaults = new FontDefaults();
576 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
577 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
578 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
580 // Clear the font-specific data
583 mImpl->RequestRelayout();
586 const std::string& Controller::GetDefaultFontFamily() const
588 if( NULL != mImpl->mFontDefaults )
590 return mImpl->mFontDefaults->mFontDescription.family;
596 void Controller::SetDefaultFontWeight( FontWeight weight )
598 if( NULL == mImpl->mFontDefaults )
600 mImpl->mFontDefaults = new FontDefaults();
603 mImpl->mFontDefaults->mFontDescription.weight = weight;
604 mImpl->mFontDefaults->weightDefined = true;
606 // Clear the font-specific data
609 mImpl->RequestRelayout();
612 bool Controller::IsDefaultFontWeightDefined() const
614 return mImpl->mFontDefaults->weightDefined;
617 FontWeight Controller::GetDefaultFontWeight() const
619 if( NULL != mImpl->mFontDefaults )
621 return mImpl->mFontDefaults->mFontDescription.weight;
624 return TextAbstraction::FontWeight::NORMAL;
627 void Controller::SetDefaultFontWidth( FontWidth width )
629 if( NULL == mImpl->mFontDefaults )
631 mImpl->mFontDefaults = new FontDefaults();
634 mImpl->mFontDefaults->mFontDescription.width = width;
635 mImpl->mFontDefaults->widthDefined = true;
637 // Clear the font-specific data
640 mImpl->RequestRelayout();
643 bool Controller::IsDefaultFontWidthDefined() const
645 return mImpl->mFontDefaults->widthDefined;
648 FontWidth Controller::GetDefaultFontWidth() const
650 if( NULL != mImpl->mFontDefaults )
652 return mImpl->mFontDefaults->mFontDescription.width;
655 return TextAbstraction::FontWidth::NORMAL;
658 void Controller::SetDefaultFontSlant( FontSlant slant )
660 if( NULL == mImpl->mFontDefaults )
662 mImpl->mFontDefaults = new FontDefaults();
665 mImpl->mFontDefaults->mFontDescription.slant = slant;
666 mImpl->mFontDefaults->slantDefined = true;
668 // Clear the font-specific data
671 mImpl->RequestRelayout();
674 bool Controller::IsDefaultFontSlantDefined() const
676 return mImpl->mFontDefaults->slantDefined;
679 FontSlant Controller::GetDefaultFontSlant() const
681 if( NULL != mImpl->mFontDefaults )
683 return mImpl->mFontDefaults->mFontDescription.slant;
686 return TextAbstraction::FontSlant::NORMAL;
689 void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
691 if( NULL == mImpl->mFontDefaults )
693 mImpl->mFontDefaults = new FontDefaults();
700 mImpl->mFontDefaults->mDefaultPointSize = fontSize;
701 mImpl->mFontDefaults->sizeDefined = true;
706 // Point size = Pixel size * 72 / DPI
707 unsigned int horizontalDpi = 0u;
708 unsigned int verticalDpi = 0u;
709 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
710 fontClient.GetDpi( horizontalDpi, verticalDpi );
712 mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72 ) / horizontalDpi;
713 mImpl->mFontDefaults->sizeDefined = true;
718 DALI_ASSERT_ALWAYS( false );
722 // Clear the font-specific data
725 mImpl->RequestRelayout();
728 float Controller::GetDefaultFontSize( FontSizeType type ) const
731 if( NULL != mImpl->mFontDefaults )
737 value = mImpl->mFontDefaults->mDefaultPointSize;
742 // Pixel size = Point size * DPI / 72
743 unsigned int horizontalDpi = 0u;
744 unsigned int verticalDpi = 0u;
745 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
746 fontClient.GetDpi( horizontalDpi, verticalDpi );
748 value = mImpl->mFontDefaults->mDefaultPointSize * horizontalDpi / 72;
753 DALI_ASSERT_ALWAYS( false );
762 void Controller::SetDefaultColor( const Vector4& color )
764 mImpl->mTextColor = color;
766 if( !mImpl->IsShowingPlaceholderText() )
768 mImpl->mModel->mVisualModel->SetTextColor( color );
770 mImpl->RequestRelayout();
774 const Vector4& Controller::GetDefaultColor() const
776 return mImpl->mTextColor;
779 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
781 if( NULL != mImpl->mEventData )
783 mImpl->mEventData->mPlaceholderTextColor = textColor;
786 if( mImpl->IsShowingPlaceholderText() )
788 mImpl->mModel->mVisualModel->SetTextColor( textColor );
789 mImpl->RequestRelayout();
793 const Vector4& Controller::GetPlaceholderTextColor() const
795 if( NULL != mImpl->mEventData )
797 return mImpl->mEventData->mPlaceholderTextColor;
803 void Controller::SetShadowOffset( const Vector2& shadowOffset )
805 mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
807 mImpl->RequestRelayout();
810 const Vector2& Controller::GetShadowOffset() const
812 return mImpl->mModel->mVisualModel->GetShadowOffset();
815 void Controller::SetShadowColor( const Vector4& shadowColor )
817 mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
819 mImpl->RequestRelayout();
822 const Vector4& Controller::GetShadowColor() const
824 return mImpl->mModel->mVisualModel->GetShadowColor();
827 void Controller::SetUnderlineColor( const Vector4& color )
829 mImpl->mModel->mVisualModel->SetUnderlineColor( color );
831 mImpl->RequestRelayout();
834 const Vector4& Controller::GetUnderlineColor() const
836 return mImpl->mModel->mVisualModel->GetUnderlineColor();
839 void Controller::SetUnderlineEnabled( bool enabled )
841 mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
843 mImpl->RequestRelayout();
846 bool Controller::IsUnderlineEnabled() const
848 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
851 void Controller::SetUnderlineHeight( float height )
853 mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
855 mImpl->RequestRelayout();
858 float Controller::GetUnderlineHeight() const
860 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
863 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
865 if( NULL == mImpl->mEmbossDefaults )
867 mImpl->mEmbossDefaults = new EmbossDefaults();
870 mImpl->mEmbossDefaults->properties = embossProperties;
873 const std::string& Controller::GetDefaultEmbossProperties() const
875 if( NULL != mImpl->mEmbossDefaults )
877 return mImpl->mEmbossDefaults->properties;
883 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
885 if( NULL == mImpl->mOutlineDefaults )
887 mImpl->mOutlineDefaults = new OutlineDefaults();
890 mImpl->mOutlineDefaults->properties = outlineProperties;
893 const std::string& Controller::GetDefaultOutlineProperties() const
895 if( NULL != mImpl->mOutlineDefaults )
897 return mImpl->mOutlineDefaults->properties;
903 void Controller::SetDefaultLineSpacing( float lineSpacing )
905 //TODO finish implementation
906 mImpl->mLayoutEngine.SetDefaultLineSpacing( lineSpacing );
909 float Controller::GetDefaultLineSpacing() const
911 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
914 void Controller::SetInputColor( const Vector4& color )
916 if( NULL != mImpl->mEventData )
918 mImpl->mEventData->mInputStyle.textColor = color;
919 mImpl->mEventData->mInputStyle.isDefaultColor = false;
921 if( EventData::SELECTING == mImpl->mEventData->mState )
923 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
925 // Get start and end position of selection
926 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
927 const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
929 // Add the color run.
930 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
931 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
933 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
934 colorRun.color = color;
935 colorRun.characterRun.characterIndex = startOfSelectedText;
936 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
938 // Request to relayout.
939 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
940 mImpl->RequestRelayout();
942 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
943 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
944 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
949 const Vector4& Controller::GetInputColor() const
951 if( NULL != mImpl->mEventData )
953 return mImpl->mEventData->mInputStyle.textColor;
956 // Return the default text's color if there is no EventData.
957 return mImpl->mTextColor;
961 void Controller::SetInputFontFamily( const std::string& fontFamily )
963 if( NULL != mImpl->mEventData )
965 mImpl->mEventData->mInputStyle.familyName = fontFamily;
966 mImpl->mEventData->mInputStyle.isFamilyDefined = true;
968 if( EventData::SELECTING == mImpl->mEventData->mState )
970 CharacterIndex startOfSelectedText = 0u;
971 Length lengthOfSelectedText = 0u;
972 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
973 mImpl->mModel->mLogicalModel,
975 lengthOfSelectedText );
977 fontDescriptionRun.familyLength = fontFamily.size();
978 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
979 memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength );
980 fontDescriptionRun.familyDefined = true;
982 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
984 // Request to relayout.
985 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
993 mImpl->mRecalculateNaturalSize = true;
994 mImpl->RequestRelayout();
996 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
997 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
998 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1000 // As the font changes, recalculate the handle positions is needed.
1001 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1002 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1003 mImpl->mEventData->mUpdateHighlightBox = true;
1004 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1009 const std::string& Controller::GetInputFontFamily() const
1011 if( NULL != mImpl->mEventData )
1013 return mImpl->mEventData->mInputStyle.familyName;
1016 // Return the default font's family if there is no EventData.
1017 return GetDefaultFontFamily();
1020 void Controller::SetInputFontWeight( FontWeight weight )
1022 if( NULL != mImpl->mEventData )
1024 mImpl->mEventData->mInputStyle.weight = weight;
1025 mImpl->mEventData->mInputStyle.isWeightDefined = true;
1027 if( EventData::SELECTING == mImpl->mEventData->mState )
1029 CharacterIndex startOfSelectedText = 0u;
1030 Length lengthOfSelectedText = 0u;
1031 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1032 mImpl->mModel->mLogicalModel,
1033 startOfSelectedText,
1034 lengthOfSelectedText );
1036 fontDescriptionRun.weight = weight;
1037 fontDescriptionRun.weightDefined = true;
1039 // Request to relayout.
1040 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1045 UPDATE_LAYOUT_SIZE |
1048 mImpl->mRecalculateNaturalSize = true;
1049 mImpl->RequestRelayout();
1051 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1052 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1053 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1055 // As the font might change, recalculate the handle positions is needed.
1056 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1057 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1058 mImpl->mEventData->mUpdateHighlightBox = true;
1059 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1064 bool Controller::IsInputFontWeightDefined() const
1066 bool defined = false;
1068 if( NULL != mImpl->mEventData )
1070 defined = mImpl->mEventData->mInputStyle.isWeightDefined;
1076 FontWeight Controller::GetInputFontWeight() const
1078 if( NULL != mImpl->mEventData )
1080 return mImpl->mEventData->mInputStyle.weight;
1083 return GetDefaultFontWeight();
1086 void Controller::SetInputFontWidth( FontWidth width )
1088 if( NULL != mImpl->mEventData )
1090 mImpl->mEventData->mInputStyle.width = width;
1091 mImpl->mEventData->mInputStyle.isWidthDefined = true;
1093 if( EventData::SELECTING == mImpl->mEventData->mState )
1095 CharacterIndex startOfSelectedText = 0u;
1096 Length lengthOfSelectedText = 0u;
1097 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1098 mImpl->mModel->mLogicalModel,
1099 startOfSelectedText,
1100 lengthOfSelectedText );
1102 fontDescriptionRun.width = width;
1103 fontDescriptionRun.widthDefined = true;
1105 // Request to relayout.
1106 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1111 UPDATE_LAYOUT_SIZE |
1114 mImpl->mRecalculateNaturalSize = true;
1115 mImpl->RequestRelayout();
1117 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1118 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1119 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1121 // As the font might change, recalculate the handle positions is needed.
1122 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1123 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1124 mImpl->mEventData->mUpdateHighlightBox = true;
1125 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1130 bool Controller::IsInputFontWidthDefined() const
1132 bool defined = false;
1134 if( NULL != mImpl->mEventData )
1136 defined = mImpl->mEventData->mInputStyle.isWidthDefined;
1142 FontWidth Controller::GetInputFontWidth() const
1144 if( NULL != mImpl->mEventData )
1146 return mImpl->mEventData->mInputStyle.width;
1149 return GetDefaultFontWidth();
1152 void Controller::SetInputFontSlant( FontSlant slant )
1154 if( NULL != mImpl->mEventData )
1156 mImpl->mEventData->mInputStyle.slant = slant;
1157 mImpl->mEventData->mInputStyle.isSlantDefined = true;
1159 if( EventData::SELECTING == mImpl->mEventData->mState )
1161 CharacterIndex startOfSelectedText = 0u;
1162 Length lengthOfSelectedText = 0u;
1163 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1164 mImpl->mModel->mLogicalModel,
1165 startOfSelectedText,
1166 lengthOfSelectedText );
1168 fontDescriptionRun.slant = slant;
1169 fontDescriptionRun.slantDefined = true;
1171 // Request to relayout.
1172 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1177 UPDATE_LAYOUT_SIZE |
1180 mImpl->mRecalculateNaturalSize = true;
1181 mImpl->RequestRelayout();
1183 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1184 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1185 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1187 // As the font might change, recalculate the handle positions is needed.
1188 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1189 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1190 mImpl->mEventData->mUpdateHighlightBox = true;
1191 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1196 bool Controller::IsInputFontSlantDefined() const
1198 bool defined = false;
1200 if( NULL != mImpl->mEventData )
1202 defined = mImpl->mEventData->mInputStyle.isSlantDefined;
1208 FontSlant Controller::GetInputFontSlant() const
1210 if( NULL != mImpl->mEventData )
1212 return mImpl->mEventData->mInputStyle.slant;
1215 return GetDefaultFontSlant();
1218 void Controller::SetInputFontPointSize( float size )
1220 if( NULL != mImpl->mEventData )
1222 mImpl->mEventData->mInputStyle.size = size;
1223 mImpl->mEventData->mInputStyle.isSizeDefined = true;
1225 if( EventData::SELECTING == mImpl->mEventData->mState )
1227 CharacterIndex startOfSelectedText = 0u;
1228 Length lengthOfSelectedText = 0u;
1229 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1230 mImpl->mModel->mLogicalModel,
1231 startOfSelectedText,
1232 lengthOfSelectedText );
1234 fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
1235 fontDescriptionRun.sizeDefined = true;
1237 // Request to relayout.
1238 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1243 UPDATE_LAYOUT_SIZE |
1246 mImpl->mRecalculateNaturalSize = true;
1247 mImpl->RequestRelayout();
1249 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1250 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1251 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1253 // As the font might change, recalculate the handle positions is needed.
1254 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1255 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1256 mImpl->mEventData->mUpdateHighlightBox = true;
1257 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1262 float Controller::GetInputFontPointSize() const
1264 if( NULL != mImpl->mEventData )
1266 return mImpl->mEventData->mInputStyle.size;
1269 // Return the default font's point size if there is no EventData.
1270 return GetDefaultFontSize( Text::Controller::POINT_SIZE );
1273 void Controller::SetInputLineSpacing( float lineSpacing )
1275 if( NULL != mImpl->mEventData )
1277 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1278 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1282 float Controller::GetInputLineSpacing() const
1284 if( NULL != mImpl->mEventData )
1286 return mImpl->mEventData->mInputStyle.lineSpacing;
1292 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1294 if( NULL != mImpl->mEventData )
1296 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1300 const std::string& Controller::GetInputShadowProperties() const
1302 if( NULL != mImpl->mEventData )
1304 return mImpl->mEventData->mInputStyle.shadowProperties;
1307 return EMPTY_STRING;
1310 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1312 if( NULL != mImpl->mEventData )
1314 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1318 const std::string& Controller::GetInputUnderlineProperties() const
1320 if( NULL != mImpl->mEventData )
1322 return mImpl->mEventData->mInputStyle.underlineProperties;
1325 return EMPTY_STRING;
1328 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
1330 if( NULL != mImpl->mEventData )
1332 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1336 const std::string& Controller::GetInputEmbossProperties() const
1338 if( NULL != mImpl->mEventData )
1340 return mImpl->mEventData->mInputStyle.embossProperties;
1343 return GetDefaultEmbossProperties();
1346 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
1348 if( NULL != mImpl->mEventData )
1350 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1354 const std::string& Controller::GetInputOutlineProperties() const
1356 if( NULL != mImpl->mEventData )
1358 return mImpl->mEventData->mInputStyle.outlineProperties;
1361 return GetDefaultOutlineProperties();
1364 void Controller::SetInputModePassword( bool passwordInput )
1366 if( NULL != mImpl->mEventData )
1368 mImpl->mEventData->mPasswordInput = passwordInput;
1372 bool Controller::IsInputModePassword()
1374 if( NULL != mImpl->mEventData )
1376 return mImpl->mEventData->mPasswordInput;
1381 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
1383 if( NULL != mImpl->mEventData )
1385 mImpl->mEventData->mDoubleTapAction = action;
1389 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1391 NoTextTap::Action action = NoTextTap::NO_ACTION;
1393 if( NULL != mImpl->mEventData )
1395 action = mImpl->mEventData->mDoubleTapAction;
1401 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
1403 if( NULL != mImpl->mEventData )
1405 mImpl->mEventData->mLongPressAction = action;
1409 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1411 NoTextTap::Action action = NoTextTap::NO_ACTION;
1413 if( NULL != mImpl->mEventData )
1415 action = mImpl->mEventData->mLongPressAction;
1421 bool Controller::IsUnderlineSetByString()
1423 return mImpl->mUnderlineSetByString;
1426 void Controller::UnderlineSetByString( bool setByString )
1428 mImpl->mUnderlineSetByString = setByString;
1431 bool Controller::IsShadowSetByString()
1433 return mImpl->mShadowSetByString;
1436 void Controller::ShadowSetByString( bool setByString )
1438 mImpl->mShadowSetByString = setByString;
1441 bool Controller::IsFontStyleSetByString()
1443 return mImpl->mFontStyleSetByString;
1446 void Controller::FontStyleSetByString( bool setByString )
1448 mImpl->mFontStyleSetByString = setByString;
1451 // public : Queries & retrieves.
1453 Layout::Engine& Controller::GetLayoutEngine()
1455 return mImpl->mLayoutEngine;
1458 View& Controller::GetView()
1460 return mImpl->mView;
1463 Vector3 Controller::GetNaturalSize()
1465 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
1466 Vector3 naturalSize;
1468 // Make sure the model is up-to-date before layouting
1469 ProcessModifyEvents();
1471 if( mImpl->mRecalculateNaturalSize )
1473 // Operations that can be done only once until the text changes.
1474 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1481 GET_GLYPH_METRICS );
1483 // Set the update info to relayout the whole text.
1484 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1485 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1487 // Make sure the model is up-to-date before layouting
1488 mImpl->UpdateModel( onlyOnceOperations );
1490 // Layout the text for the new width.
1491 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
1493 // Store the actual control's size to restore later.
1494 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
1496 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
1497 static_cast<OperationsMask>( onlyOnceOperations |
1499 naturalSize.GetVectorXY() );
1501 // Do not do again the only once operations.
1502 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1504 // Do the size related operations again.
1505 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1508 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1510 // Stores the natural size to avoid recalculate it again
1511 // unless the text/style changes.
1512 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
1514 mImpl->mRecalculateNaturalSize = false;
1516 // Clear the update info. This info will be set the next time the text is updated.
1517 mImpl->mTextUpdateInfo.Clear();
1519 // Restore the actual control's size.
1520 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
1522 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1526 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
1528 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1531 naturalSize.x = ConvertToEven( naturalSize.x );
1532 naturalSize.y = ConvertToEven( naturalSize.y );
1537 float Controller::GetHeightForWidth( float width )
1539 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
1540 // Make sure the model is up-to-date before layouting
1541 ProcessModifyEvents();
1544 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 )
1546 // Operations that can be done only once until the text changes.
1547 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1554 GET_GLYPH_METRICS );
1556 // Set the update info to relayout the whole text.
1557 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1558 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1560 // Make sure the model is up-to-date before layouting
1561 mImpl->UpdateModel( onlyOnceOperations );
1564 // Layout the text for the new width.
1565 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
1567 // Store the actual control's width.
1568 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
1570 DoRelayout( Size( width, MAX_FLOAT ),
1571 static_cast<OperationsMask>( onlyOnceOperations |
1575 // Do not do again the only once operations.
1576 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1578 // Do the size related operations again.
1579 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1583 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1585 // Clear the update info. This info will be set the next time the text is updated.
1586 mImpl->mTextUpdateInfo.Clear();
1588 // Restore the actual control's width.
1589 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
1591 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
1595 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
1596 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
1599 return layoutSize.height;
1602 int Controller::GetLineCount( float width )
1604 GetHeightForWidth( width );
1605 int numberofLines = mImpl->mModel->GetNumberOfLines();
1606 return numberofLines;
1609 const ModelInterface* const Controller::GetTextModel() const
1611 return mImpl->mModel.Get();
1614 float Controller::GetScrollAmountByUserInput()
1616 float scrollAmount = 0.0f;
1618 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
1620 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
1621 mImpl->mEventData->mCheckScrollAmount = false;
1623 return scrollAmount;
1626 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
1628 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
1631 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
1632 layoutHeight = layout.height;
1633 scrollPosition = mImpl->mModel->mScrollPosition.y;
1634 isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
1638 void Controller::SetHiddenInputOption(const Property::Map& options )
1640 if( NULL == mImpl->mHiddenInput )
1642 mImpl->mHiddenInput = new HiddenText( this );
1644 mImpl->mHiddenInput->SetProperties(options);
1647 void Controller::GetHiddenInputOption(Property::Map& options )
1649 if( NULL != mImpl->mHiddenInput )
1651 mImpl->mHiddenInput->GetProperties(options);
1655 // public : Relayout.
1657 Controller::UpdateTextType Controller::Relayout( const Size& size )
1659 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
1661 UpdateTextType updateTextType = NONE_UPDATED;
1663 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
1665 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
1667 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
1668 updateTextType = MODEL_UPDATED;
1671 // Clear the update info. This info will be set the next time the text is updated.
1672 mImpl->mTextUpdateInfo.Clear();
1674 // Not worth to relayout if width or height is equal to zero.
1675 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
1677 return updateTextType;
1680 // Whether a new size has been set.
1681 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
1685 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
1687 // Layout operations that need to be done if the size changes.
1688 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1691 UPDATE_LAYOUT_SIZE |
1693 // Set the update info to relayout the whole text.
1694 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
1695 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
1697 // Store the size used to layout the text.
1698 mImpl->mModel->mVisualModel->mControlSize = size;
1701 // Whether there are modify events.
1702 if( 0u != mImpl->mModifyEvents.Count() )
1704 // Style operations that need to be done if the text is modified.
1705 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1709 // Make sure the model is up-to-date before layouting.
1710 ProcessModifyEvents();
1711 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
1715 updated = DoRelayout( size,
1716 mImpl->mOperationsPending,
1717 layoutSize ) || updated;
1721 updateTextType = MODEL_UPDATED;
1724 // Do not re-do any operation until something changes.
1725 mImpl->mOperationsPending = NO_OPERATION;
1726 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
1728 // Whether the text control is editable
1729 const bool isEditable = NULL != mImpl->mEventData;
1731 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
1733 if( newSize && isEditable )
1735 offset = mImpl->mModel->mScrollPosition;
1738 if( !isEditable || !IsMultiLineEnabled() )
1740 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
1741 CalculateVerticalOffset( size );
1748 // If there is a new size, the scroll position needs to be clamped.
1749 mImpl->ClampHorizontalScroll( layoutSize );
1751 // Update the decorator's positions is needed if there is a new size.
1752 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
1755 // Move the cursor, grab handle etc.
1756 if( mImpl->ProcessInputEvents() )
1758 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
1762 // Clear the update info. This info will be set the next time the text is updated.
1763 mImpl->mTextUpdateInfo.Clear();
1764 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
1766 return updateTextType;
1769 void Controller::RequestRelayout()
1771 mImpl->RequestRelayout();
1774 // public : Input style change signals.
1776 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
1778 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
1781 void Controller::ProcessInputStyleChangedSignals()
1783 if( NULL == mImpl->mEventData )
1789 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
1790 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
1794 const InputStyle::Mask mask = *it;
1796 if( NULL != mImpl->mEditableControlInterface )
1798 // Emit the input style changed signal.
1799 mImpl->mEditableControlInterface->InputStyleChanged( mask );
1803 mImpl->mEventData->mInputStyleChangedQueue.Clear();
1806 // public : Text-input Event Queuing.
1808 void Controller::KeyboardFocusGainEvent()
1810 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
1812 if( NULL != mImpl->mEventData )
1814 if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
1815 ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
1817 mImpl->ChangeState( EventData::EDITING );
1818 mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
1819 mImpl->mEventData->mUpdateInputStyle = true;
1821 mImpl->NotifyImfMultiLineStatus();
1822 if( mImpl->IsShowingPlaceholderText() )
1824 // Show alternative placeholder-text when editing
1825 ShowPlaceholderText();
1828 mImpl->RequestRelayout();
1832 void Controller::KeyboardFocusLostEvent()
1834 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
1836 if( NULL != mImpl->mEventData )
1838 if( EventData::INTERRUPTED != mImpl->mEventData->mState )
1840 mImpl->ChangeState( EventData::INACTIVE );
1842 if( !mImpl->IsShowingRealText() )
1844 // Revert to regular placeholder-text when not editing
1845 ShowPlaceholderText();
1849 mImpl->RequestRelayout();
1852 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
1854 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
1856 bool textChanged = false;
1857 bool relayoutNeeded = false;
1859 if( ( NULL != mImpl->mEventData ) &&
1860 ( keyEvent.state == KeyEvent::Down ) )
1862 int keyCode = keyEvent.keyCode;
1863 const std::string& keyString = keyEvent.keyPressed;
1865 const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
1867 // Pre-process to separate modifying events from non-modifying input events.
1870 // In some platforms arrive key events with no key code.
1873 else if( Dali::DALI_KEY_ESCAPE == keyCode )
1875 // Escape key is a special case which causes focus loss
1876 KeyboardFocusLostEvent();
1878 // Will request for relayout.
1879 relayoutNeeded = true;
1881 else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) ||
1882 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
1883 ( Dali::DALI_KEY_CURSOR_UP == keyCode ) ||
1884 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) )
1886 // If don't have any text, do nothing.
1887 if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
1892 uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition;
1893 uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
1894 uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition );
1895 uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines();
1897 // Logic to determine whether this text control will lose focus or not.
1898 if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition ) ||
1899 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition) ||
1900 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) ||
1901 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) ||
1902 ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) ||
1903 ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) )
1908 mImpl->mEventData->mCheckScrollAmount = true;
1909 Event event( Event::CURSOR_KEY_EVENT );
1910 event.p1.mInt = keyCode;
1911 mImpl->mEventData->mEventQueue.push_back( event );
1913 // Will request for relayout.
1914 relayoutNeeded = true;
1916 else if( Dali::DALI_KEY_BACKSPACE == keyCode )
1918 textChanged = BackspaceKeyEvent();
1920 // Will request for relayout.
1921 relayoutNeeded = true;
1923 else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
1924 IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
1925 IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
1927 // Power key/Menu/Home key behaviour does not allow edit mode to resume.
1928 mImpl->ChangeState( EventData::INACTIVE );
1930 // Will request for relayout.
1931 relayoutNeeded = true;
1933 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
1935 else if( Dali::DALI_KEY_SHIFT_LEFT == keyCode )
1937 // DALI_KEY_SHIFT_LEFT is the key code for the Left Shift. It's sent (by the imf?) when the predictive text is enabled
1938 // and a character is typed after the type of a upper case latin character.
1942 else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
1944 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
1949 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
1951 // IMF manager is no longer handling key-events
1952 mImpl->ClearPreEditFlag();
1954 InsertText( keyString, COMMIT );
1957 // Will request for relayout.
1958 relayoutNeeded = true;
1961 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
1962 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
1964 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
1965 ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
1966 ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
1968 // Should not change the state if the key is the shift send by the imf manager.
1969 // Otherwise, when the state is SELECTING the text controller can't send the right
1970 // surrounding info to the imf.
1971 mImpl->ChangeState( EventData::EDITING );
1973 // Will request for relayout.
1974 relayoutNeeded = true;
1977 if( relayoutNeeded )
1979 mImpl->RequestRelayout();
1984 ( NULL != mImpl->mEditableControlInterface ) )
1986 // Do this last since it provides callbacks into application code
1987 mImpl->mEditableControlInterface->TextChanged();
1993 void Controller::TapEvent( unsigned int tapCount, float x, float y )
1995 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
1997 if( NULL != mImpl->mEventData )
1999 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
2000 EventData::State state( mImpl->mEventData->mState );
2001 bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
2003 if( mImpl->IsClipboardVisible() )
2005 if( EventData::INACTIVE == state || EventData::EDITING == state)
2007 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2009 relayoutNeeded = true;
2011 else if( 1u == tapCount )
2013 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
2015 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
2018 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
2020 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2021 relayoutNeeded = true;
2025 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
2027 // Hide placeholder text
2031 if( EventData::INACTIVE == state )
2033 mImpl->ChangeState( EventData::EDITING );
2035 else if( !mImpl->IsClipboardEmpty() )
2037 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
2039 relayoutNeeded = true;
2042 else if( 2u == tapCount )
2044 if( mImpl->mEventData->mSelectionEnabled &&
2045 mImpl->IsShowingRealText() )
2047 relayoutNeeded = true;
2048 mImpl->mEventData->mIsLeftHandleSelected = true;
2049 mImpl->mEventData->mIsRightHandleSelected = true;
2053 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
2054 if( relayoutNeeded )
2056 Event event( Event::TAP_EVENT );
2057 event.p1.mUint = tapCount;
2058 event.p2.mFloat = x;
2059 event.p3.mFloat = y;
2060 mImpl->mEventData->mEventQueue.push_back( event );
2062 mImpl->RequestRelayout();
2066 // Reset keyboard as tap event has occurred.
2067 mImpl->ResetImfManager();
2070 void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
2072 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
2074 if( NULL != mImpl->mEventData )
2076 Event event( Event::PAN_EVENT );
2077 event.p1.mInt = state;
2078 event.p2.mFloat = displacement.x;
2079 event.p3.mFloat = displacement.y;
2080 mImpl->mEventData->mEventQueue.push_back( event );
2082 mImpl->RequestRelayout();
2086 void Controller::LongPressEvent( Gesture::State state, float x, float y )
2088 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
2090 if( ( state == Gesture::Started ) &&
2091 ( NULL != mImpl->mEventData ) )
2093 // The 1st long-press on inactive text-field is treated as tap
2094 if( EventData::INACTIVE == mImpl->mEventData->mState )
2096 mImpl->ChangeState( EventData::EDITING );
2098 Event event( Event::TAP_EVENT );
2100 event.p2.mFloat = x;
2101 event.p3.mFloat = y;
2102 mImpl->mEventData->mEventQueue.push_back( event );
2104 mImpl->RequestRelayout();
2106 else if( !mImpl->IsShowingRealText() )
2108 Event event( Event::LONG_PRESS_EVENT );
2109 event.p1.mInt = state;
2110 event.p2.mFloat = x;
2111 event.p3.mFloat = y;
2112 mImpl->mEventData->mEventQueue.push_back( event );
2113 mImpl->RequestRelayout();
2115 else if( !mImpl->IsClipboardVisible() )
2117 // Reset the imf manager to commit the pre-edit before selecting the text.
2118 mImpl->ResetImfManager();
2120 Event event( Event::LONG_PRESS_EVENT );
2121 event.p1.mInt = state;
2122 event.p2.mFloat = x;
2123 event.p3.mFloat = y;
2124 mImpl->mEventData->mEventQueue.push_back( event );
2125 mImpl->RequestRelayout();
2127 mImpl->mEventData->mIsLeftHandleSelected = true;
2128 mImpl->mEventData->mIsRightHandleSelected = true;
2133 ImfManager::ImfCallbackData Controller::OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
2135 // Whether the text needs to be relaid-out.
2136 bool requestRelayout = false;
2138 // Whether to retrieve the text and cursor position to be sent to the IMF manager.
2139 bool retrieveText = false;
2140 bool retrieveCursor = false;
2142 switch( imfEvent.eventName )
2144 case ImfManager::COMMIT:
2146 InsertText( imfEvent.predictiveString, Text::Controller::COMMIT );
2147 requestRelayout = true;
2148 retrieveCursor = true;
2151 case ImfManager::PREEDIT:
2153 InsertText( imfEvent.predictiveString, Text::Controller::PRE_EDIT );
2154 requestRelayout = true;
2155 retrieveCursor = true;
2158 case ImfManager::DELETESURROUNDING:
2160 const bool textDeleted = RemoveText( imfEvent.cursorOffset,
2161 imfEvent.numberOfChars,
2162 DONT_UPDATE_INPUT_STYLE );
2166 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2167 !mImpl->IsPlaceholderAvailable() )
2169 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2173 ShowPlaceholderText();
2175 mImpl->mEventData->mUpdateCursorPosition = true;
2176 mImpl->mEventData->mScrollAfterDelete = true;
2178 requestRelayout = true;
2182 case ImfManager::GETSURROUNDING:
2184 retrieveText = true;
2185 retrieveCursor = true;
2188 case ImfManager::PRIVATECOMMAND:
2190 // PRIVATECOMMAND event is just for getting the private command message
2191 retrieveText = true;
2192 retrieveCursor = true;
2195 case ImfManager::VOID:
2202 if( requestRelayout )
2204 mImpl->mOperationsPending = ALL_OPERATIONS;
2205 mImpl->RequestRelayout();
2209 CharacterIndex cursorPosition = 0u;
2210 Length numberOfWhiteSpaces = 0u;
2212 if( retrieveCursor )
2214 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
2216 cursorPosition = mImpl->GetLogicalCursorPosition();
2218 if( cursorPosition < numberOfWhiteSpaces )
2220 cursorPosition = 0u;
2224 cursorPosition -= numberOfWhiteSpaces;
2230 mImpl->GetText( numberOfWhiteSpaces, text );
2233 ImfManager::ImfCallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
2235 if( requestRelayout &&
2236 ( NULL != mImpl->mEditableControlInterface ) )
2238 // Do this last since it provides callbacks into application code
2239 mImpl->mEditableControlInterface->TextChanged();
2242 return callbackData;
2245 void Controller::PasteClipboardItemEvent()
2247 // Retrieve the clipboard contents first
2248 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
2249 std::string stringToPaste( notifier.GetContent() );
2251 // Commit the current pre-edit text; the contents of the clipboard should be appended
2252 mImpl->ResetImfManager();
2254 // Temporary disable hiding clipboard
2255 mImpl->SetClipboardHideEnable( false );
2258 PasteText( stringToPaste );
2260 mImpl->SetClipboardHideEnable( true );
2263 // protected : Inherit from Text::Decorator::ControllerInterface.
2265 void Controller::GetTargetSize( Vector2& targetSize )
2267 targetSize = mImpl->mModel->mVisualModel->mControlSize;
2270 void Controller::AddDecoration( Actor& actor, bool needsClipping )
2272 if( NULL != mImpl->mEditableControlInterface )
2274 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
2278 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
2280 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
2282 if( NULL != mImpl->mEventData )
2284 switch( handleType )
2288 Event event( Event::GRAB_HANDLE_EVENT );
2289 event.p1.mUint = state;
2290 event.p2.mFloat = x;
2291 event.p3.mFloat = y;
2293 mImpl->mEventData->mEventQueue.push_back( event );
2296 case LEFT_SELECTION_HANDLE:
2298 Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
2299 event.p1.mUint = state;
2300 event.p2.mFloat = x;
2301 event.p3.mFloat = y;
2303 mImpl->mEventData->mEventQueue.push_back( event );
2306 case RIGHT_SELECTION_HANDLE:
2308 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
2309 event.p1.mUint = state;
2310 event.p2.mFloat = x;
2311 event.p3.mFloat = y;
2313 mImpl->mEventData->mEventQueue.push_back( event );
2316 case LEFT_SELECTION_HANDLE_MARKER:
2317 case RIGHT_SELECTION_HANDLE_MARKER:
2319 // Markers do not move the handles.
2322 case HANDLE_TYPE_COUNT:
2324 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
2328 mImpl->RequestRelayout();
2332 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
2334 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
2336 if( NULL == mImpl->mEventData )
2343 case Toolkit::TextSelectionPopup::CUT:
2345 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
2346 mImpl->mOperationsPending = ALL_OPERATIONS;
2348 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2349 !mImpl->IsPlaceholderAvailable() )
2351 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2355 ShowPlaceholderText();
2358 mImpl->mEventData->mUpdateCursorPosition = true;
2359 mImpl->mEventData->mScrollAfterDelete = true;
2361 mImpl->RequestRelayout();
2363 if( NULL != mImpl->mEditableControlInterface )
2365 mImpl->mEditableControlInterface->TextChanged();
2369 case Toolkit::TextSelectionPopup::COPY:
2371 mImpl->SendSelectionToClipboard( false ); // Text not modified
2373 mImpl->mEventData->mUpdateCursorPosition = true;
2375 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
2378 case Toolkit::TextSelectionPopup::PASTE:
2380 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
2383 case Toolkit::TextSelectionPopup::SELECT:
2385 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
2387 if( mImpl->mEventData->mSelectionEnabled )
2389 // Creates a SELECT event.
2390 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
2394 case Toolkit::TextSelectionPopup::SELECT_ALL:
2396 // Creates a SELECT_ALL event
2397 SelectEvent( 0.f, 0.f, true );
2400 case Toolkit::TextSelectionPopup::CLIPBOARD:
2402 mImpl->ShowClipboard();
2405 case Toolkit::TextSelectionPopup::NONE:
2413 void Controller::DisplayTimeExpired()
2415 mImpl->mEventData->mUpdateCursorPosition = true;
2416 // Apply modifications to the model
2417 mImpl->mOperationsPending = ALL_OPERATIONS;
2419 mImpl->RequestRelayout();
2422 // private : Update.
2424 void Controller::InsertText( const std::string& text, Controller::InsertType type )
2426 bool removedPrevious = false;
2427 bool removedSelected = false;
2428 bool maxLengthReached = false;
2430 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
2432 if( NULL == mImpl->mEventData )
2437 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
2438 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
2439 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
2441 // TODO: At the moment the underline runs are only for pre-edit.
2442 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
2444 // Remove the previous IMF pre-edit.
2445 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
2447 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
2448 mImpl->mEventData->mPreEditLength,
2449 DONT_UPDATE_INPUT_STYLE );
2451 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
2452 mImpl->mEventData->mPreEditLength = 0u;
2456 // Remove the previous Selection.
2457 removedSelected = RemoveSelectedText();
2461 Vector<Character> utf32Characters;
2462 Length characterCount = 0u;
2466 // Convert text into UTF-32
2467 utf32Characters.Resize( text.size() );
2469 // This is a bit horrible but std::string returns a (signed) char*
2470 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
2472 // Transform a text array encoded in utf8 into an array encoded in utf32.
2473 // It returns the actual number of characters.
2474 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
2475 utf32Characters.Resize( characterCount );
2477 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
2478 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
2481 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
2483 // The placeholder text is no longer needed
2484 if( mImpl->IsShowingPlaceholderText() )
2489 mImpl->ChangeState( EventData::EDITING );
2491 // Handle the IMF (predicitive text) state changes
2492 if( COMMIT == type )
2494 // IMF manager is no longer handling key-events
2495 mImpl->ClearPreEditFlag();
2499 if( !mImpl->mEventData->mPreEditFlag )
2501 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
2503 // Record the start of the pre-edit text
2504 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
2507 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
2508 mImpl->mEventData->mPreEditFlag = true;
2510 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
2513 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
2515 // Restrict new text to fit within Maximum characters setting.
2516 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
2517 maxLengthReached = ( characterCount > maxSizeOfNewText );
2519 // The cursor position.
2520 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
2522 // Update the text's style.
2524 // Updates the text style runs by adding characters.
2525 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
2527 // Get the character index from the cursor index.
2528 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
2530 // Retrieve the text's style for the given index.
2532 mImpl->RetrieveDefaultInputStyle( style );
2533 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
2535 // Whether to add a new text color run.
2536 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor );
2538 // Whether to add a new font run.
2539 const bool addFontNameRun = style.familyName != mImpl->mEventData->mInputStyle.familyName;
2540 const bool addFontWeightRun = style.weight != mImpl->mEventData->mInputStyle.weight;
2541 const bool addFontWidthRun = style.width != mImpl->mEventData->mInputStyle.width;
2542 const bool addFontSlantRun = style.slant != mImpl->mEventData->mInputStyle.slant;
2543 const bool addFontSizeRun = style.size != mImpl->mEventData->mInputStyle.size;
2548 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
2549 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
2551 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
2552 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
2553 colorRun.characterRun.characterIndex = cursorIndex;
2554 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
2557 if( addFontNameRun ||
2563 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
2564 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
2566 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
2568 if( addFontNameRun )
2570 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
2571 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
2572 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
2573 fontDescriptionRun.familyDefined = true;
2575 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
2578 if( addFontWeightRun )
2580 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
2581 fontDescriptionRun.weightDefined = true;
2584 if( addFontWidthRun )
2586 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
2587 fontDescriptionRun.widthDefined = true;
2590 if( addFontSlantRun )
2592 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
2593 fontDescriptionRun.slantDefined = true;
2596 if( addFontSizeRun )
2598 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
2599 fontDescriptionRun.sizeDefined = true;
2602 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
2603 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
2606 // Insert at current cursor position.
2607 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
2609 if( cursorIndex < numberOfCharactersInModel )
2611 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
2615 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
2618 // Mark the first paragraph to be updated.
2619 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
2620 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
2622 // Update the cursor index.
2623 cursorIndex += maxSizeOfNewText;
2625 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 );
2628 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
2629 mImpl->IsPlaceholderAvailable() )
2631 // Show place-holder if empty after removing the pre-edit text
2632 ShowPlaceholderText();
2633 mImpl->mEventData->mUpdateCursorPosition = true;
2634 mImpl->ClearPreEditFlag();
2636 else if( removedPrevious ||
2638 ( 0 != utf32Characters.Count() ) )
2640 // Queue an inserted event
2641 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
2643 mImpl->mEventData->mUpdateCursorPosition = true;
2644 if( removedSelected )
2646 mImpl->mEventData->mScrollAfterDelete = true;
2650 mImpl->mEventData->mScrollAfterUpdatePosition = true;
2654 if( maxLengthReached )
2656 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
2658 mImpl->ResetImfManager();
2660 if( NULL != mImpl->mEditableControlInterface )
2662 // Do this last since it provides callbacks into application code
2663 mImpl->mEditableControlInterface->MaxLengthReached();
2668 void Controller::PasteText( const std::string& stringToPaste )
2670 InsertText( stringToPaste, Text::Controller::COMMIT );
2671 mImpl->ChangeState( EventData::EDITING );
2672 mImpl->RequestRelayout();
2674 if( NULL != mImpl->mEditableControlInterface )
2676 // Do this last since it provides callbacks into application code
2677 mImpl->mEditableControlInterface->TextChanged();
2681 bool Controller::RemoveText( int cursorOffset,
2682 int numberOfCharacters,
2683 UpdateInputStyleType type )
2685 bool removed = false;
2687 if( NULL == mImpl->mEventData )
2692 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
2693 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
2695 if( !mImpl->IsShowingPlaceholderText() )
2697 // Delete at current cursor position
2698 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
2699 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
2701 CharacterIndex cursorIndex = 0;
2703 // Validate the cursor position & number of characters
2704 if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
2706 cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
2709 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
2711 numberOfCharacters = currentText.Count() - cursorIndex;
2714 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.
2715 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
2717 // Mark the paragraphs to be updated.
2718 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
2719 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
2721 // Update the input style and remove the text's style before removing the text.
2723 if( UPDATE_INPUT_STYLE == type )
2725 // Keep a copy of the current input style.
2726 InputStyle currentInputStyle;
2727 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
2729 // Set first the default input style.
2730 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
2732 // Update the input style.
2733 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
2735 // Compare if the input style has changed.
2736 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
2738 if( hasInputStyleChanged )
2740 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
2741 // Queue the input style changed signal.
2742 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
2746 // Updates the text style runs by removing characters. Runs with no characters are removed.
2747 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
2749 // Remove the characters.
2750 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
2751 Vector<Character>::Iterator last = first + numberOfCharacters;
2753 currentText.Erase( first, last );
2755 // Cursor position retreat
2756 oldCursorIndex = cursorIndex;
2758 mImpl->mEventData->mScrollAfterDelete = true;
2760 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
2768 bool Controller::RemoveSelectedText()
2770 bool textRemoved( false );
2772 if( EventData::SELECTING == mImpl->mEventData->mState )
2774 std::string removedString;
2775 mImpl->RetrieveSelection( removedString, true );
2777 if( !removedString.empty() )
2780 mImpl->ChangeState( EventData::EDITING );
2787 // private : Relayout.
2789 bool Controller::DoRelayout( const Size& size,
2790 OperationsMask operationsRequired,
2793 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
2794 bool viewUpdated( false );
2796 // Calculate the operations to be done.
2797 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
2799 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
2800 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
2802 // Get the current layout size.
2803 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
2805 if( NO_OPERATION != ( LAYOUT & operations ) )
2807 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
2809 // Some vectors with data needed to layout and reorder may be void
2810 // after the first time the text has been laid out.
2811 // Fill the vectors again.
2813 // Calculate the number of glyphs to layout.
2814 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
2815 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
2816 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
2817 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
2819 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
2820 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
2821 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
2822 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
2824 if( 0u == totalNumberOfGlyphs )
2826 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
2828 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
2831 // Nothing else to do if there is no glyphs.
2832 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
2836 const Vector<LineBreakInfo>& lineBreakInfo = mImpl->mModel->mLogicalModel->mLineBreakInfo;
2837 const Vector<WordBreakInfo>& wordBreakInfo = mImpl->mModel->mLogicalModel->mWordBreakInfo;
2838 const Vector<CharacterDirection>& characterDirection = mImpl->mModel->mLogicalModel->mCharacterDirections;
2839 const Vector<GlyphInfo>& glyphs = mImpl->mModel->mVisualModel->mGlyphs;
2840 const Vector<CharacterIndex>& glyphsToCharactersMap = mImpl->mModel->mVisualModel->mGlyphsToCharacters;
2841 const Vector<Length>& charactersPerGlyph = mImpl->mModel->mVisualModel->mCharactersPerGlyph;
2842 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
2844 // Set the layout parameters.
2845 Layout::Parameters layoutParameters( size,
2847 lineBreakInfo.Begin(),
2848 wordBreakInfo.Begin(),
2849 ( 0u != characterDirection.Count() ) ? characterDirection.Begin() : NULL,
2851 glyphsToCharactersMap.Begin(),
2852 charactersPerGlyph.Begin(),
2853 charactersToGlyphBuffer,
2854 glyphsPerCharacterBuffer,
2855 totalNumberOfGlyphs,
2856 mImpl->mModel->mHorizontalAlignment );
2858 // Resize the vector of positions to have the same size than the vector of glyphs.
2859 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
2860 glyphPositions.Resize( totalNumberOfGlyphs );
2862 // Whether the last character is a new paragraph character.
2863 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
2864 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
2866 // The initial glyph and the number of glyphs to layout.
2867 layoutParameters.startGlyphIndex = startGlyphIndex;
2868 layoutParameters.numberOfGlyphs = numberOfGlyphs;
2869 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
2870 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
2872 // Update the visual model.
2874 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
2876 mImpl->mModel->mVisualModel->mLines,
2878 mImpl->mModel->mElideEnabled );
2880 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
2884 layoutSize = newLayoutSize;
2886 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
2888 mImpl->mAutoScrollDirectionRTL = false;
2891 // Reorder the lines
2892 if( NO_OPERATION != ( REORDER & operations ) )
2894 Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = mImpl->mModel->mLogicalModel->mBidirectionalParagraphInfo;
2895 Vector<BidirectionalLineInfoRun>& bidirectionalLineInfo = mImpl->mModel->mLogicalModel->mBidirectionalLineInfo;
2897 // Check first if there are paragraphs with bidirectional info.
2898 if( 0u != bidirectionalInfo.Count() )
2901 const Length numberOfLines = mImpl->mModel->mVisualModel->mLines.Count();
2903 // Reorder the lines.
2904 bidirectionalLineInfo.Reserve( numberOfLines ); // Reserve because is not known yet how many lines have right to left characters.
2905 ReorderLines( bidirectionalInfo,
2907 requestedNumberOfCharacters,
2908 mImpl->mModel->mVisualModel->mLines,
2909 bidirectionalLineInfo );
2911 // Set the bidirectional info per line into the layout parameters.
2912 layoutParameters.lineBidirectionalInfoRunsBuffer = bidirectionalLineInfo.Begin();
2913 layoutParameters.numberOfBidirectionalInfoRuns = bidirectionalLineInfo.Count();
2915 // Re-layout the text. Reorder those lines with right to left characters.
2916 mImpl->mLayoutEngine.ReLayoutRightToLeftLines( layoutParameters,
2918 requestedNumberOfCharacters,
2921 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && ( numberOfLines > 0 ) )
2923 const LineRun* const firstline = mImpl->mModel->mVisualModel->mLines.Begin();
2926 mImpl->mAutoScrollDirectionRTL = firstline->direction;
2932 // Sets the layout size.
2933 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
2935 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
2940 if( NO_OPERATION != ( ALIGN & operations ) )
2942 // The laid-out lines.
2943 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
2945 // Need to align with the control's size as the text may contain lines
2946 // starting either with left to right text or right to left.
2947 mImpl->mLayoutEngine.Align( size,
2949 requestedNumberOfCharacters,
2950 mImpl->mModel->mHorizontalAlignment,
2952 mImpl->mModel->mAlignmentOffset );
2956 #if defined(DEBUG_ENABLED)
2957 std::string currentText;
2958 GetText( currentText );
2959 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mAutoScrollDirectionRTL[%s] [%s]\n", this, (mImpl->mAutoScrollDirectionRTL)?"true":"false", currentText.c_str() );
2961 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
2965 void Controller::CalculateVerticalOffset( const Size& controlSize )
2967 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
2969 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
2971 // Get the line height of the default font.
2972 layoutSize.height = mImpl->GetDefaultFontLineHeight();
2975 switch( mImpl->mModel->mVerticalAlignment )
2977 case Layout::VERTICAL_ALIGN_TOP:
2979 mImpl->mModel->mScrollPosition.y = 0.f;
2982 case Layout::VERTICAL_ALIGN_CENTER:
2984 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
2987 case Layout::VERTICAL_ALIGN_BOTTOM:
2989 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
2995 // private : Events.
2997 void Controller::ProcessModifyEvents()
2999 Vector<ModifyEvent>& events = mImpl->mModifyEvents;
3001 if( 0u == events.Count() )
3007 for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
3008 endIt = events.End();
3012 const ModifyEvent& event = *it;
3014 if( ModifyEvent::TEXT_REPLACED == event.type )
3016 // A (single) replace event should come first, otherwise we wasted time processing NOOP events
3017 DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
3019 TextReplacedEvent();
3021 else if( ModifyEvent::TEXT_INSERTED == event.type )
3023 TextInsertedEvent();
3025 else if( ModifyEvent::TEXT_DELETED == event.type )
3027 // Placeholder-text cannot be deleted
3028 if( !mImpl->IsShowingPlaceholderText() )
3035 if( NULL != mImpl->mEventData )
3037 // When the text is being modified, delay cursor blinking
3038 mImpl->mEventData->mDecorator->DelayCursorBlink();
3041 // Discard temporary text
3045 void Controller::TextReplacedEvent()
3047 // The natural size needs to be re-calculated.
3048 mImpl->mRecalculateNaturalSize = true;
3050 // Apply modifications to the model
3051 mImpl->mOperationsPending = ALL_OPERATIONS;
3054 void Controller::TextInsertedEvent()
3056 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
3058 if( NULL == mImpl->mEventData )
3063 mImpl->mEventData->mCheckScrollAmount = true;
3065 // The natural size needs to be re-calculated.
3066 mImpl->mRecalculateNaturalSize = true;
3068 // Apply modifications to the model; TODO - Optimize this
3069 mImpl->mOperationsPending = ALL_OPERATIONS;
3072 void Controller::TextDeletedEvent()
3074 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
3076 if( NULL == mImpl->mEventData )
3081 mImpl->mEventData->mCheckScrollAmount = true;
3083 // The natural size needs to be re-calculated.
3084 mImpl->mRecalculateNaturalSize = true;
3086 // Apply modifications to the model; TODO - Optimize this
3087 mImpl->mOperationsPending = ALL_OPERATIONS;
3090 void Controller::SelectEvent( float x, float y, bool selectAll )
3092 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
3094 if( NULL != mImpl->mEventData )
3098 Event event( Event::SELECT_ALL );
3099 mImpl->mEventData->mEventQueue.push_back( event );
3103 Event event( Event::SELECT );
3104 event.p2.mFloat = x;
3105 event.p3.mFloat = y;
3106 mImpl->mEventData->mEventQueue.push_back( event );
3109 mImpl->mEventData->mCheckScrollAmount = true;
3110 mImpl->mEventData->mIsLeftHandleSelected = true;
3111 mImpl->mEventData->mIsRightHandleSelected = true;
3112 mImpl->RequestRelayout();
3116 bool Controller::BackspaceKeyEvent()
3118 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p DALI_KEY_BACKSPACE\n", this );
3120 bool removed = false;
3122 if( NULL == mImpl->mEventData )
3127 // IMF manager is no longer handling key-events
3128 mImpl->ClearPreEditFlag();
3130 if( EventData::SELECTING == mImpl->mEventData->mState )
3132 removed = RemoveSelectedText();
3134 else if( mImpl->mEventData->mPrimaryCursorPosition > 0 )
3136 // Remove the character before the current cursor position
3137 removed = RemoveText( -1,
3139 UPDATE_INPUT_STYLE );
3144 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3145 !mImpl->IsPlaceholderAvailable() )
3147 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3151 ShowPlaceholderText();
3153 mImpl->mEventData->mUpdateCursorPosition = true;
3154 mImpl->mEventData->mScrollAfterDelete = true;
3160 // private : Helpers.
3162 void Controller::ResetText()
3165 mImpl->mModel->mLogicalModel->mText.Clear();
3167 // We have cleared everything including the placeholder-text
3168 mImpl->PlaceholderCleared();
3170 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3171 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3172 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
3174 // Clear any previous text.
3175 mImpl->mTextUpdateInfo.mClearAll = true;
3177 // The natural size needs to be re-calculated.
3178 mImpl->mRecalculateNaturalSize = true;
3180 // Apply modifications to the model
3181 mImpl->mOperationsPending = ALL_OPERATIONS;
3184 void Controller::ShowPlaceholderText()
3186 if( mImpl->IsPlaceholderAvailable() )
3188 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
3190 if( NULL == mImpl->mEventData )
3195 mImpl->mEventData->mIsShowingPlaceholderText = true;
3197 // Disable handles when showing place-holder text
3198 mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
3199 mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
3200 mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
3202 const char* text( NULL );
3205 // TODO - Switch placeholder text styles when changing state
3206 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
3207 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
3209 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
3210 size = mImpl->mEventData->mPlaceholderTextActive.size();
3214 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
3215 size = mImpl->mEventData->mPlaceholderTextInactive.size();
3218 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3219 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3221 // Reset model for showing placeholder.
3222 mImpl->mModel->mLogicalModel->mText.Clear();
3223 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
3225 // Convert text into UTF-32
3226 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
3227 utf32Characters.Resize( size );
3229 // This is a bit horrible but std::string returns a (signed) char*
3230 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
3232 // Transform a text array encoded in utf8 into an array encoded in utf32.
3233 // It returns the actual number of characters.
3234 const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
3235 utf32Characters.Resize( characterCount );
3237 // The characters to be added.
3238 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
3240 // Reset the cursor position
3241 mImpl->mEventData->mPrimaryCursorPosition = 0;
3243 // The natural size needs to be re-calculated.
3244 mImpl->mRecalculateNaturalSize = true;
3246 // Apply modifications to the model
3247 mImpl->mOperationsPending = ALL_OPERATIONS;
3249 // Update the rest of the model during size negotiation
3250 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
3254 void Controller::ClearFontData()
3256 if( mImpl->mFontDefaults )
3258 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
3261 // Set flags to update the model.
3262 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3263 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3264 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
3266 mImpl->mTextUpdateInfo.mClearAll = true;
3267 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
3268 mImpl->mRecalculateNaturalSize = true;
3270 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
3275 UPDATE_LAYOUT_SIZE |
3280 void Controller::ClearStyleData()
3282 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
3283 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
3286 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
3288 // Reset the cursor position
3289 if( NULL != mImpl->mEventData )
3291 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
3293 // Update the cursor if it's in editing mode.
3294 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
3296 mImpl->mEventData->mUpdateCursorPosition = true;
3301 void Controller::ResetScrollPosition()
3303 if( NULL != mImpl->mEventData )
3305 // Reset the scroll position.
3306 mImpl->mModel->mScrollPosition = Vector2::ZERO;
3307 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3311 // private : Private contructors & copy operator.
3313 Controller::Controller()
3316 mImpl = new Controller::Impl( NULL, NULL );
3319 Controller::Controller( ControlInterface* controlInterface )
3321 mImpl = new Controller::Impl( controlInterface, NULL );
3324 Controller::Controller( ControlInterface* controlInterface,
3325 EditableControlInterface* editableControlInterface )
3327 mImpl = new Controller::Impl( controlInterface,
3328 editableControlInterface );
3331 // The copy constructor and operator are left unimplemented.
3333 // protected : Destructor.
3335 Controller::~Controller()
3342 } // namespace Toolkit