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( const std::string& text )
517 if( NULL != mImpl->mEventData )
519 mImpl->mEventData->mPlaceholderText = text;
521 // Update placeholder if there is no text
522 if( mImpl->IsShowingPlaceholderText() ||
523 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
525 ShowPlaceholderText();
530 // This is overloading function for PLACEHOLDER_TEXT_FOCUSED in text-field
531 void Controller::SetPlaceholderText( PlaceholderType type, const std::string& text )
533 if( NULL != mImpl->mEventData )
535 if( PLACEHOLDER_TYPE_INACTIVE == type )
537 mImpl->mEventData->mPlaceholderTextInactive = text;
541 mImpl->mEventData->mPlaceholderTextActive = text;
544 // Update placeholder if there is no text
545 if( mImpl->IsShowingPlaceholderText() ||
546 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
548 ShowPlaceholderText();
553 void Controller::GetPlaceholderText( std::string& text ) const
555 if( NULL != mImpl->mEventData )
557 text = mImpl->mEventData->mPlaceholderText;
561 // This is overloading function for PLACEHOLDER_TEXT_FOCUSED in text-field
562 void Controller::GetPlaceholderText( PlaceholderType type, std::string& text ) const
564 if( NULL != mImpl->mEventData )
566 if( PLACEHOLDER_TYPE_INACTIVE == type )
568 text = mImpl->mEventData->mPlaceholderTextInactive;
572 text = mImpl->mEventData->mPlaceholderTextActive;
577 void Controller::UpdateAfterFontChange( const std::string& newDefaultFont )
579 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
581 if( !mImpl->mFontDefaults->familyDefined ) // If user defined font then should not update when system font changes
583 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
584 mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
588 mImpl->RequestRelayout();
592 // public : Default style & Input style
594 void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
596 if( NULL == mImpl->mFontDefaults )
598 mImpl->mFontDefaults = new FontDefaults();
601 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
602 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
603 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
605 // Clear the font-specific data
608 mImpl->RequestRelayout();
611 const std::string& Controller::GetDefaultFontFamily() const
613 if( NULL != mImpl->mFontDefaults )
615 return mImpl->mFontDefaults->mFontDescription.family;
621 void Controller::SetDefaultFontWeight( FontWeight weight )
623 if( NULL == mImpl->mFontDefaults )
625 mImpl->mFontDefaults = new FontDefaults();
628 mImpl->mFontDefaults->mFontDescription.weight = weight;
629 mImpl->mFontDefaults->weightDefined = true;
631 // Clear the font-specific data
634 mImpl->RequestRelayout();
637 bool Controller::IsDefaultFontWeightDefined() const
639 return mImpl->mFontDefaults->weightDefined;
642 FontWeight Controller::GetDefaultFontWeight() const
644 if( NULL != mImpl->mFontDefaults )
646 return mImpl->mFontDefaults->mFontDescription.weight;
649 return TextAbstraction::FontWeight::NORMAL;
652 void Controller::SetDefaultFontWidth( FontWidth width )
654 if( NULL == mImpl->mFontDefaults )
656 mImpl->mFontDefaults = new FontDefaults();
659 mImpl->mFontDefaults->mFontDescription.width = width;
660 mImpl->mFontDefaults->widthDefined = true;
662 // Clear the font-specific data
665 mImpl->RequestRelayout();
668 bool Controller::IsDefaultFontWidthDefined() const
670 return mImpl->mFontDefaults->widthDefined;
673 FontWidth Controller::GetDefaultFontWidth() const
675 if( NULL != mImpl->mFontDefaults )
677 return mImpl->mFontDefaults->mFontDescription.width;
680 return TextAbstraction::FontWidth::NORMAL;
683 void Controller::SetDefaultFontSlant( FontSlant slant )
685 if( NULL == mImpl->mFontDefaults )
687 mImpl->mFontDefaults = new FontDefaults();
690 mImpl->mFontDefaults->mFontDescription.slant = slant;
691 mImpl->mFontDefaults->slantDefined = true;
693 // Clear the font-specific data
696 mImpl->RequestRelayout();
699 bool Controller::IsDefaultFontSlantDefined() const
701 return mImpl->mFontDefaults->slantDefined;
704 FontSlant Controller::GetDefaultFontSlant() const
706 if( NULL != mImpl->mFontDefaults )
708 return mImpl->mFontDefaults->mFontDescription.slant;
711 return TextAbstraction::FontSlant::NORMAL;
714 void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
716 if( NULL == mImpl->mFontDefaults )
718 mImpl->mFontDefaults = new FontDefaults();
725 mImpl->mFontDefaults->mDefaultPointSize = fontSize;
726 mImpl->mFontDefaults->sizeDefined = true;
731 // Point size = Pixel size * 72 / DPI
732 unsigned int horizontalDpi = 0u;
733 unsigned int verticalDpi = 0u;
734 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
735 fontClient.GetDpi( horizontalDpi, verticalDpi );
737 mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72 ) / horizontalDpi;
738 mImpl->mFontDefaults->sizeDefined = true;
743 DALI_ASSERT_ALWAYS( false );
747 // Clear the font-specific data
750 mImpl->RequestRelayout();
753 float Controller::GetDefaultFontSize( FontSizeType type ) const
756 if( NULL != mImpl->mFontDefaults )
762 value = mImpl->mFontDefaults->mDefaultPointSize;
767 // Pixel size = Point size * DPI / 72
768 unsigned int horizontalDpi = 0u;
769 unsigned int verticalDpi = 0u;
770 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
771 fontClient.GetDpi( horizontalDpi, verticalDpi );
773 value = mImpl->mFontDefaults->mDefaultPointSize * horizontalDpi / 72;
778 DALI_ASSERT_ALWAYS( false );
787 void Controller::SetDefaultColor( const Vector4& color )
789 mImpl->mTextColor = color;
791 if( !mImpl->IsShowingPlaceholderText() )
793 mImpl->mModel->mVisualModel->SetTextColor( color );
795 mImpl->RequestRelayout();
799 const Vector4& Controller::GetDefaultColor() const
801 return mImpl->mTextColor;
804 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
806 if( NULL != mImpl->mEventData )
808 mImpl->mEventData->mPlaceholderTextColor = textColor;
811 if( mImpl->IsShowingPlaceholderText() )
813 mImpl->mModel->mVisualModel->SetTextColor( textColor );
814 mImpl->RequestRelayout();
818 const Vector4& Controller::GetPlaceholderTextColor() const
820 if( NULL != mImpl->mEventData )
822 return mImpl->mEventData->mPlaceholderTextColor;
828 void Controller::SetShadowOffset( const Vector2& shadowOffset )
830 mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
832 mImpl->RequestRelayout();
835 const Vector2& Controller::GetShadowOffset() const
837 return mImpl->mModel->mVisualModel->GetShadowOffset();
840 void Controller::SetShadowColor( const Vector4& shadowColor )
842 mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
844 mImpl->RequestRelayout();
847 const Vector4& Controller::GetShadowColor() const
849 return mImpl->mModel->mVisualModel->GetShadowColor();
852 void Controller::SetUnderlineColor( const Vector4& color )
854 mImpl->mModel->mVisualModel->SetUnderlineColor( color );
856 mImpl->RequestRelayout();
859 const Vector4& Controller::GetUnderlineColor() const
861 return mImpl->mModel->mVisualModel->GetUnderlineColor();
864 void Controller::SetUnderlineEnabled( bool enabled )
866 mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
868 mImpl->RequestRelayout();
871 bool Controller::IsUnderlineEnabled() const
873 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
876 void Controller::SetUnderlineHeight( float height )
878 mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
880 mImpl->RequestRelayout();
883 float Controller::GetUnderlineHeight() const
885 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
888 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
890 if( NULL == mImpl->mEmbossDefaults )
892 mImpl->mEmbossDefaults = new EmbossDefaults();
895 mImpl->mEmbossDefaults->properties = embossProperties;
898 const std::string& Controller::GetDefaultEmbossProperties() const
900 if( NULL != mImpl->mEmbossDefaults )
902 return mImpl->mEmbossDefaults->properties;
908 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
910 if( NULL == mImpl->mOutlineDefaults )
912 mImpl->mOutlineDefaults = new OutlineDefaults();
915 mImpl->mOutlineDefaults->properties = outlineProperties;
918 const std::string& Controller::GetDefaultOutlineProperties() const
920 if( NULL != mImpl->mOutlineDefaults )
922 return mImpl->mOutlineDefaults->properties;
928 void Controller::SetDefaultLineSpacing( float lineSpacing )
930 //TODO finish implementation
931 mImpl->mLayoutEngine.SetDefaultLineSpacing( lineSpacing );
934 float Controller::GetDefaultLineSpacing() const
936 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
939 void Controller::SetInputColor( const Vector4& color )
941 if( NULL != mImpl->mEventData )
943 mImpl->mEventData->mInputStyle.textColor = color;
944 mImpl->mEventData->mInputStyle.isDefaultColor = false;
946 if( EventData::SELECTING == mImpl->mEventData->mState )
948 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
950 // Get start and end position of selection
951 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
952 const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
954 // Add the color run.
955 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
956 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
958 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
959 colorRun.color = color;
960 colorRun.characterRun.characterIndex = startOfSelectedText;
961 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
963 // Request to relayout.
964 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
965 mImpl->RequestRelayout();
967 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
968 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
969 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
974 const Vector4& Controller::GetInputColor() const
976 if( NULL != mImpl->mEventData )
978 return mImpl->mEventData->mInputStyle.textColor;
981 // Return the default text's color if there is no EventData.
982 return mImpl->mTextColor;
986 void Controller::SetInputFontFamily( const std::string& fontFamily )
988 if( NULL != mImpl->mEventData )
990 mImpl->mEventData->mInputStyle.familyName = fontFamily;
991 mImpl->mEventData->mInputStyle.isFamilyDefined = true;
993 if( EventData::SELECTING == mImpl->mEventData->mState )
995 CharacterIndex startOfSelectedText = 0u;
996 Length lengthOfSelectedText = 0u;
997 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
998 mImpl->mModel->mLogicalModel,
1000 lengthOfSelectedText );
1002 fontDescriptionRun.familyLength = fontFamily.size();
1003 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
1004 memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength );
1005 fontDescriptionRun.familyDefined = true;
1007 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
1009 // Request to relayout.
1010 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1015 UPDATE_LAYOUT_SIZE |
1018 mImpl->mRecalculateNaturalSize = true;
1019 mImpl->RequestRelayout();
1021 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1022 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1023 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1025 // As the font changes, recalculate the handle positions is needed.
1026 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1027 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1028 mImpl->mEventData->mUpdateHighlightBox = true;
1029 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1034 const std::string& Controller::GetInputFontFamily() const
1036 if( NULL != mImpl->mEventData )
1038 return mImpl->mEventData->mInputStyle.familyName;
1041 // Return the default font's family if there is no EventData.
1042 return GetDefaultFontFamily();
1045 void Controller::SetInputFontWeight( FontWeight weight )
1047 if( NULL != mImpl->mEventData )
1049 mImpl->mEventData->mInputStyle.weight = weight;
1050 mImpl->mEventData->mInputStyle.isWeightDefined = true;
1052 if( EventData::SELECTING == mImpl->mEventData->mState )
1054 CharacterIndex startOfSelectedText = 0u;
1055 Length lengthOfSelectedText = 0u;
1056 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1057 mImpl->mModel->mLogicalModel,
1058 startOfSelectedText,
1059 lengthOfSelectedText );
1061 fontDescriptionRun.weight = weight;
1062 fontDescriptionRun.weightDefined = true;
1064 // Request to relayout.
1065 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1070 UPDATE_LAYOUT_SIZE |
1073 mImpl->mRecalculateNaturalSize = true;
1074 mImpl->RequestRelayout();
1076 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1077 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1078 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1080 // As the font might change, recalculate the handle positions is needed.
1081 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1082 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1083 mImpl->mEventData->mUpdateHighlightBox = true;
1084 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1089 bool Controller::IsInputFontWeightDefined() const
1091 bool defined = false;
1093 if( NULL != mImpl->mEventData )
1095 defined = mImpl->mEventData->mInputStyle.isWeightDefined;
1101 FontWeight Controller::GetInputFontWeight() const
1103 if( NULL != mImpl->mEventData )
1105 return mImpl->mEventData->mInputStyle.weight;
1108 return GetDefaultFontWeight();
1111 void Controller::SetInputFontWidth( FontWidth width )
1113 if( NULL != mImpl->mEventData )
1115 mImpl->mEventData->mInputStyle.width = width;
1116 mImpl->mEventData->mInputStyle.isWidthDefined = true;
1118 if( EventData::SELECTING == mImpl->mEventData->mState )
1120 CharacterIndex startOfSelectedText = 0u;
1121 Length lengthOfSelectedText = 0u;
1122 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1123 mImpl->mModel->mLogicalModel,
1124 startOfSelectedText,
1125 lengthOfSelectedText );
1127 fontDescriptionRun.width = width;
1128 fontDescriptionRun.widthDefined = true;
1130 // Request to relayout.
1131 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1136 UPDATE_LAYOUT_SIZE |
1139 mImpl->mRecalculateNaturalSize = true;
1140 mImpl->RequestRelayout();
1142 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1143 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1144 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1146 // As the font might change, recalculate the handle positions is needed.
1147 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1148 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1149 mImpl->mEventData->mUpdateHighlightBox = true;
1150 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1155 bool Controller::IsInputFontWidthDefined() const
1157 bool defined = false;
1159 if( NULL != mImpl->mEventData )
1161 defined = mImpl->mEventData->mInputStyle.isWidthDefined;
1167 FontWidth Controller::GetInputFontWidth() const
1169 if( NULL != mImpl->mEventData )
1171 return mImpl->mEventData->mInputStyle.width;
1174 return GetDefaultFontWidth();
1177 void Controller::SetInputFontSlant( FontSlant slant )
1179 if( NULL != mImpl->mEventData )
1181 mImpl->mEventData->mInputStyle.slant = slant;
1182 mImpl->mEventData->mInputStyle.isSlantDefined = true;
1184 if( EventData::SELECTING == mImpl->mEventData->mState )
1186 CharacterIndex startOfSelectedText = 0u;
1187 Length lengthOfSelectedText = 0u;
1188 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1189 mImpl->mModel->mLogicalModel,
1190 startOfSelectedText,
1191 lengthOfSelectedText );
1193 fontDescriptionRun.slant = slant;
1194 fontDescriptionRun.slantDefined = true;
1196 // Request to relayout.
1197 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1202 UPDATE_LAYOUT_SIZE |
1205 mImpl->mRecalculateNaturalSize = true;
1206 mImpl->RequestRelayout();
1208 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1209 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1210 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1212 // As the font might change, recalculate the handle positions is needed.
1213 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1214 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1215 mImpl->mEventData->mUpdateHighlightBox = true;
1216 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1221 bool Controller::IsInputFontSlantDefined() const
1223 bool defined = false;
1225 if( NULL != mImpl->mEventData )
1227 defined = mImpl->mEventData->mInputStyle.isSlantDefined;
1233 FontSlant Controller::GetInputFontSlant() const
1235 if( NULL != mImpl->mEventData )
1237 return mImpl->mEventData->mInputStyle.slant;
1240 return GetDefaultFontSlant();
1243 void Controller::SetInputFontPointSize( float size )
1245 if( NULL != mImpl->mEventData )
1247 mImpl->mEventData->mInputStyle.size = size;
1248 mImpl->mEventData->mInputStyle.isSizeDefined = true;
1250 if( EventData::SELECTING == mImpl->mEventData->mState )
1252 CharacterIndex startOfSelectedText = 0u;
1253 Length lengthOfSelectedText = 0u;
1254 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1255 mImpl->mModel->mLogicalModel,
1256 startOfSelectedText,
1257 lengthOfSelectedText );
1259 fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
1260 fontDescriptionRun.sizeDefined = true;
1262 // Request to relayout.
1263 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1268 UPDATE_LAYOUT_SIZE |
1271 mImpl->mRecalculateNaturalSize = true;
1272 mImpl->RequestRelayout();
1274 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1275 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1276 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1278 // As the font might change, recalculate the handle positions is needed.
1279 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1280 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1281 mImpl->mEventData->mUpdateHighlightBox = true;
1282 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1287 float Controller::GetInputFontPointSize() const
1289 if( NULL != mImpl->mEventData )
1291 return mImpl->mEventData->mInputStyle.size;
1294 // Return the default font's point size if there is no EventData.
1295 return GetDefaultFontSize( Text::Controller::POINT_SIZE );
1298 void Controller::SetInputLineSpacing( float lineSpacing )
1300 if( NULL != mImpl->mEventData )
1302 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1303 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1307 float Controller::GetInputLineSpacing() const
1309 if( NULL != mImpl->mEventData )
1311 return mImpl->mEventData->mInputStyle.lineSpacing;
1317 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1319 if( NULL != mImpl->mEventData )
1321 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1325 const std::string& Controller::GetInputShadowProperties() const
1327 if( NULL != mImpl->mEventData )
1329 return mImpl->mEventData->mInputStyle.shadowProperties;
1332 return EMPTY_STRING;
1335 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1337 if( NULL != mImpl->mEventData )
1339 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1343 const std::string& Controller::GetInputUnderlineProperties() const
1345 if( NULL != mImpl->mEventData )
1347 return mImpl->mEventData->mInputStyle.underlineProperties;
1350 return EMPTY_STRING;
1353 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
1355 if( NULL != mImpl->mEventData )
1357 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1361 const std::string& Controller::GetInputEmbossProperties() const
1363 if( NULL != mImpl->mEventData )
1365 return mImpl->mEventData->mInputStyle.embossProperties;
1368 return GetDefaultEmbossProperties();
1371 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
1373 if( NULL != mImpl->mEventData )
1375 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1379 const std::string& Controller::GetInputOutlineProperties() const
1381 if( NULL != mImpl->mEventData )
1383 return mImpl->mEventData->mInputStyle.outlineProperties;
1386 return GetDefaultOutlineProperties();
1389 void Controller::SetInputModePassword( bool passwordInput )
1391 if( NULL != mImpl->mEventData )
1393 mImpl->mEventData->mPasswordInput = passwordInput;
1397 bool Controller::IsInputModePassword()
1399 if( NULL != mImpl->mEventData )
1401 return mImpl->mEventData->mPasswordInput;
1406 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
1408 if( NULL != mImpl->mEventData )
1410 mImpl->mEventData->mDoubleTapAction = action;
1414 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1416 NoTextTap::Action action = NoTextTap::NO_ACTION;
1418 if( NULL != mImpl->mEventData )
1420 action = mImpl->mEventData->mDoubleTapAction;
1426 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
1428 if( NULL != mImpl->mEventData )
1430 mImpl->mEventData->mLongPressAction = action;
1434 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1436 NoTextTap::Action action = NoTextTap::NO_ACTION;
1438 if( NULL != mImpl->mEventData )
1440 action = mImpl->mEventData->mLongPressAction;
1446 bool Controller::IsUnderlineSetByString()
1448 return mImpl->mUnderlineSetByString;
1451 void Controller::UnderlineSetByString( bool setByString )
1453 mImpl->mUnderlineSetByString = setByString;
1456 bool Controller::IsShadowSetByString()
1458 return mImpl->mShadowSetByString;
1461 void Controller::ShadowSetByString( bool setByString )
1463 mImpl->mShadowSetByString = setByString;
1466 bool Controller::IsFontStyleSetByString()
1468 return mImpl->mFontStyleSetByString;
1471 void Controller::FontStyleSetByString( bool setByString )
1473 mImpl->mFontStyleSetByString = setByString;
1476 // public : Queries & retrieves.
1478 Layout::Engine& Controller::GetLayoutEngine()
1480 return mImpl->mLayoutEngine;
1483 View& Controller::GetView()
1485 return mImpl->mView;
1488 Vector3 Controller::GetNaturalSize()
1490 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
1491 Vector3 naturalSize;
1493 // Make sure the model is up-to-date before layouting
1494 ProcessModifyEvents();
1496 if( mImpl->mRecalculateNaturalSize )
1498 // Operations that can be done only once until the text changes.
1499 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1506 GET_GLYPH_METRICS );
1508 // Set the update info to relayout the whole text.
1509 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1510 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1512 // Make sure the model is up-to-date before layouting
1513 mImpl->UpdateModel( onlyOnceOperations );
1515 // Layout the text for the new width.
1516 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
1518 // Store the actual control's size to restore later.
1519 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
1521 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
1522 static_cast<OperationsMask>( onlyOnceOperations |
1524 naturalSize.GetVectorXY() );
1526 // Do not do again the only once operations.
1527 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1529 // Do the size related operations again.
1530 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1533 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1535 // Stores the natural size to avoid recalculate it again
1536 // unless the text/style changes.
1537 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
1539 mImpl->mRecalculateNaturalSize = false;
1541 // Clear the update info. This info will be set the next time the text is updated.
1542 mImpl->mTextUpdateInfo.Clear();
1544 // Restore the actual control's size.
1545 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
1547 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1551 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
1553 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1556 naturalSize.x = ConvertToEven( naturalSize.x );
1557 naturalSize.y = ConvertToEven( naturalSize.y );
1562 float Controller::GetHeightForWidth( float width )
1564 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
1565 // Make sure the model is up-to-date before layouting
1566 ProcessModifyEvents();
1569 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 )
1571 // Operations that can be done only once until the text changes.
1572 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1579 GET_GLYPH_METRICS );
1581 // Set the update info to relayout the whole text.
1582 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1583 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1585 // Make sure the model is up-to-date before layouting
1586 mImpl->UpdateModel( onlyOnceOperations );
1589 // Layout the text for the new width.
1590 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
1592 // Store the actual control's width.
1593 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
1595 DoRelayout( Size( width, MAX_FLOAT ),
1596 static_cast<OperationsMask>( onlyOnceOperations |
1600 // Do not do again the only once operations.
1601 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1603 // Do the size related operations again.
1604 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1608 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1610 // Clear the update info. This info will be set the next time the text is updated.
1611 mImpl->mTextUpdateInfo.Clear();
1613 // Restore the actual control's width.
1614 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
1616 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
1620 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
1621 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
1624 return layoutSize.height;
1627 int Controller::GetLineCount( float width )
1629 GetHeightForWidth( width );
1630 int numberofLines = mImpl->mModel->GetNumberOfLines();
1631 return numberofLines;
1634 const ModelInterface* const Controller::GetTextModel() const
1636 return mImpl->mModel.Get();
1639 float Controller::GetScrollAmountByUserInput()
1641 float scrollAmount = 0.0f;
1643 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
1645 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
1646 mImpl->mEventData->mCheckScrollAmount = false;
1648 return scrollAmount;
1651 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
1653 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
1656 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
1657 layoutHeight = layout.height;
1658 scrollPosition = mImpl->mModel->mScrollPosition.y;
1659 isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
1663 void Controller::SetHiddenInputOption(const Property::Map& options )
1665 if( NULL == mImpl->mHiddenInput )
1667 mImpl->mHiddenInput = new HiddenText( this );
1669 mImpl->mHiddenInput->SetProperties(options);
1672 void Controller::GetHiddenInputOption(Property::Map& options )
1674 if( NULL != mImpl->mHiddenInput )
1676 mImpl->mHiddenInput->GetProperties(options);
1680 // public : Relayout.
1682 Controller::UpdateTextType Controller::Relayout( const Size& size )
1684 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
1686 UpdateTextType updateTextType = NONE_UPDATED;
1688 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
1690 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
1692 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
1693 updateTextType = MODEL_UPDATED;
1696 // Clear the update info. This info will be set the next time the text is updated.
1697 mImpl->mTextUpdateInfo.Clear();
1699 // Not worth to relayout if width or height is equal to zero.
1700 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
1702 return updateTextType;
1705 // Whether a new size has been set.
1706 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
1710 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
1712 // Layout operations that need to be done if the size changes.
1713 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1716 UPDATE_LAYOUT_SIZE |
1718 // Set the update info to relayout the whole text.
1719 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
1720 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
1722 // Store the size used to layout the text.
1723 mImpl->mModel->mVisualModel->mControlSize = size;
1726 // Whether there are modify events.
1727 if( 0u != mImpl->mModifyEvents.Count() )
1729 // Style operations that need to be done if the text is modified.
1730 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1734 // Make sure the model is up-to-date before layouting.
1735 ProcessModifyEvents();
1736 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
1740 updated = DoRelayout( size,
1741 mImpl->mOperationsPending,
1742 layoutSize ) || updated;
1746 updateTextType = MODEL_UPDATED;
1749 // Do not re-do any operation until something changes.
1750 mImpl->mOperationsPending = NO_OPERATION;
1751 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
1753 // Whether the text control is editable
1754 const bool isEditable = NULL != mImpl->mEventData;
1756 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
1758 if( newSize && isEditable )
1760 offset = mImpl->mModel->mScrollPosition;
1763 if( !isEditable || !IsMultiLineEnabled() )
1765 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
1766 CalculateVerticalOffset( size );
1773 // If there is a new size, the scroll position needs to be clamped.
1774 mImpl->ClampHorizontalScroll( layoutSize );
1776 // Update the decorator's positions is needed if there is a new size.
1777 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
1780 // Move the cursor, grab handle etc.
1781 if( mImpl->ProcessInputEvents() )
1783 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
1787 // Clear the update info. This info will be set the next time the text is updated.
1788 mImpl->mTextUpdateInfo.Clear();
1789 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
1791 return updateTextType;
1794 void Controller::RequestRelayout()
1796 mImpl->RequestRelayout();
1799 // public : Input style change signals.
1801 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
1803 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
1806 void Controller::ProcessInputStyleChangedSignals()
1808 if( NULL == mImpl->mEventData )
1814 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
1815 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
1819 const InputStyle::Mask mask = *it;
1821 if( NULL != mImpl->mEditableControlInterface )
1823 // Emit the input style changed signal.
1824 mImpl->mEditableControlInterface->InputStyleChanged( mask );
1828 mImpl->mEventData->mInputStyleChangedQueue.Clear();
1831 // public : Text-input Event Queuing.
1833 void Controller::KeyboardFocusGainEvent()
1835 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
1837 if( NULL != mImpl->mEventData )
1839 if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
1840 ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
1842 mImpl->ChangeState( EventData::EDITING );
1843 mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
1844 mImpl->mEventData->mUpdateInputStyle = true;
1846 mImpl->NotifyImfMultiLineStatus();
1847 if( mImpl->IsShowingPlaceholderText() )
1849 // Show alternative placeholder-text when editing
1850 ShowPlaceholderText();
1853 mImpl->RequestRelayout();
1857 void Controller::KeyboardFocusLostEvent()
1859 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
1861 if( NULL != mImpl->mEventData )
1863 if( EventData::INTERRUPTED != mImpl->mEventData->mState )
1865 mImpl->ChangeState( EventData::INACTIVE );
1867 if( !mImpl->IsShowingRealText() )
1869 // Revert to regular placeholder-text when not editing
1870 ShowPlaceholderText();
1874 mImpl->RequestRelayout();
1877 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
1879 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
1881 bool textChanged = false;
1882 bool relayoutNeeded = false;
1884 if( ( NULL != mImpl->mEventData ) &&
1885 ( keyEvent.state == KeyEvent::Down ) )
1887 int keyCode = keyEvent.keyCode;
1888 const std::string& keyString = keyEvent.keyPressed;
1890 const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
1892 // Pre-process to separate modifying events from non-modifying input events.
1895 // In some platforms arrive key events with no key code.
1898 else if( Dali::DALI_KEY_ESCAPE == keyCode )
1900 // Escape key is a special case which causes focus loss
1901 KeyboardFocusLostEvent();
1903 // Will request for relayout.
1904 relayoutNeeded = true;
1906 else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) ||
1907 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
1908 ( Dali::DALI_KEY_CURSOR_UP == keyCode ) ||
1909 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) )
1911 // If don't have any text, do nothing.
1912 if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
1917 uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition;
1918 uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
1919 uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition );
1920 uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines();
1922 // Logic to determine whether this text control will lose focus or not.
1923 if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition ) ||
1924 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition) ||
1925 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) ||
1926 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) ||
1927 ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) ||
1928 ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) )
1933 mImpl->mEventData->mCheckScrollAmount = true;
1934 Event event( Event::CURSOR_KEY_EVENT );
1935 event.p1.mInt = keyCode;
1936 mImpl->mEventData->mEventQueue.push_back( event );
1938 // Will request for relayout.
1939 relayoutNeeded = true;
1941 else if( Dali::DALI_KEY_BACKSPACE == keyCode )
1943 textChanged = BackspaceKeyEvent();
1945 // Will request for relayout.
1946 relayoutNeeded = true;
1948 else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
1949 IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
1950 IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
1952 // Power key/Menu/Home key behaviour does not allow edit mode to resume.
1953 mImpl->ChangeState( EventData::INACTIVE );
1955 // Will request for relayout.
1956 relayoutNeeded = true;
1958 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
1960 else if( Dali::DALI_KEY_SHIFT_LEFT == keyCode )
1962 // DALI_KEY_SHIFT_LEFT is the key code for the Left Shift. It's sent (by the imf?) when the predictive text is enabled
1963 // and a character is typed after the type of a upper case latin character.
1967 else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
1969 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
1974 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
1976 // IMF manager is no longer handling key-events
1977 mImpl->ClearPreEditFlag();
1979 InsertText( keyString, COMMIT );
1982 // Will request for relayout.
1983 relayoutNeeded = true;
1986 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
1987 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
1989 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
1990 ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
1991 ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
1993 // Should not change the state if the key is the shift send by the imf manager.
1994 // Otherwise, when the state is SELECTING the text controller can't send the right
1995 // surrounding info to the imf.
1996 mImpl->ChangeState( EventData::EDITING );
1998 // Will request for relayout.
1999 relayoutNeeded = true;
2002 if( relayoutNeeded )
2004 mImpl->RequestRelayout();
2009 ( NULL != mImpl->mEditableControlInterface ) )
2011 // Do this last since it provides callbacks into application code
2012 mImpl->mEditableControlInterface->TextChanged();
2018 void Controller::TapEvent( unsigned int tapCount, float x, float y )
2020 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
2022 if( NULL != mImpl->mEventData )
2024 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
2025 EventData::State state( mImpl->mEventData->mState );
2026 bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
2028 if( mImpl->IsClipboardVisible() )
2030 if( EventData::INACTIVE == state || EventData::EDITING == state)
2032 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2034 relayoutNeeded = true;
2036 else if( 1u == tapCount )
2038 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
2040 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
2043 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
2045 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2046 relayoutNeeded = true;
2050 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
2052 // Hide placeholder text
2056 if( EventData::INACTIVE == state )
2058 mImpl->ChangeState( EventData::EDITING );
2060 else if( !mImpl->IsClipboardEmpty() )
2062 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
2064 relayoutNeeded = true;
2067 else if( 2u == tapCount )
2069 if( mImpl->mEventData->mSelectionEnabled &&
2070 mImpl->IsShowingRealText() )
2072 relayoutNeeded = true;
2073 mImpl->mEventData->mIsLeftHandleSelected = true;
2074 mImpl->mEventData->mIsRightHandleSelected = true;
2078 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
2079 if( relayoutNeeded )
2081 Event event( Event::TAP_EVENT );
2082 event.p1.mUint = tapCount;
2083 event.p2.mFloat = x;
2084 event.p3.mFloat = y;
2085 mImpl->mEventData->mEventQueue.push_back( event );
2087 mImpl->RequestRelayout();
2091 // Reset keyboard as tap event has occurred.
2092 mImpl->ResetImfManager();
2095 void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
2097 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
2099 if( NULL != mImpl->mEventData )
2101 Event event( Event::PAN_EVENT );
2102 event.p1.mInt = state;
2103 event.p2.mFloat = displacement.x;
2104 event.p3.mFloat = displacement.y;
2105 mImpl->mEventData->mEventQueue.push_back( event );
2107 mImpl->RequestRelayout();
2111 void Controller::LongPressEvent( Gesture::State state, float x, float y )
2113 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
2115 if( ( state == Gesture::Started ) &&
2116 ( NULL != mImpl->mEventData ) )
2118 // The 1st long-press on inactive text-field is treated as tap
2119 if( EventData::INACTIVE == mImpl->mEventData->mState )
2121 mImpl->ChangeState( EventData::EDITING );
2123 Event event( Event::TAP_EVENT );
2125 event.p2.mFloat = x;
2126 event.p3.mFloat = y;
2127 mImpl->mEventData->mEventQueue.push_back( event );
2129 mImpl->RequestRelayout();
2131 else if( !mImpl->IsShowingRealText() )
2133 Event event( Event::LONG_PRESS_EVENT );
2134 event.p1.mInt = state;
2135 event.p2.mFloat = x;
2136 event.p3.mFloat = y;
2137 mImpl->mEventData->mEventQueue.push_back( event );
2138 mImpl->RequestRelayout();
2140 else if( !mImpl->IsClipboardVisible() )
2142 // Reset the imf manager to commit the pre-edit before selecting the text.
2143 mImpl->ResetImfManager();
2145 Event event( Event::LONG_PRESS_EVENT );
2146 event.p1.mInt = state;
2147 event.p2.mFloat = x;
2148 event.p3.mFloat = y;
2149 mImpl->mEventData->mEventQueue.push_back( event );
2150 mImpl->RequestRelayout();
2152 mImpl->mEventData->mIsLeftHandleSelected = true;
2153 mImpl->mEventData->mIsRightHandleSelected = true;
2158 ImfManager::ImfCallbackData Controller::OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
2160 // Whether the text needs to be relaid-out.
2161 bool requestRelayout = false;
2163 // Whether to retrieve the text and cursor position to be sent to the IMF manager.
2164 bool retrieveText = false;
2165 bool retrieveCursor = false;
2167 switch( imfEvent.eventName )
2169 case ImfManager::COMMIT:
2171 InsertText( imfEvent.predictiveString, Text::Controller::COMMIT );
2172 requestRelayout = true;
2173 retrieveCursor = true;
2176 case ImfManager::PREEDIT:
2178 InsertText( imfEvent.predictiveString, Text::Controller::PRE_EDIT );
2179 requestRelayout = true;
2180 retrieveCursor = true;
2183 case ImfManager::DELETESURROUNDING:
2185 const bool textDeleted = RemoveText( imfEvent.cursorOffset,
2186 imfEvent.numberOfChars,
2187 DONT_UPDATE_INPUT_STYLE );
2191 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2192 !mImpl->IsPlaceholderAvailable() )
2194 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2198 ShowPlaceholderText();
2200 mImpl->mEventData->mUpdateCursorPosition = true;
2201 mImpl->mEventData->mScrollAfterDelete = true;
2203 requestRelayout = true;
2207 case ImfManager::GETSURROUNDING:
2209 retrieveText = true;
2210 retrieveCursor = true;
2213 case ImfManager::PRIVATECOMMAND:
2215 // PRIVATECOMMAND event is just for getting the private command message
2216 retrieveText = true;
2217 retrieveCursor = true;
2220 case ImfManager::VOID:
2227 if( requestRelayout )
2229 mImpl->mOperationsPending = ALL_OPERATIONS;
2230 mImpl->RequestRelayout();
2234 CharacterIndex cursorPosition = 0u;
2235 Length numberOfWhiteSpaces = 0u;
2237 if( retrieveCursor )
2239 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
2241 cursorPosition = mImpl->GetLogicalCursorPosition();
2243 if( cursorPosition < numberOfWhiteSpaces )
2245 cursorPosition = 0u;
2249 cursorPosition -= numberOfWhiteSpaces;
2255 mImpl->GetText( numberOfWhiteSpaces, text );
2258 ImfManager::ImfCallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
2260 if( requestRelayout &&
2261 ( NULL != mImpl->mEditableControlInterface ) )
2263 // Do this last since it provides callbacks into application code
2264 mImpl->mEditableControlInterface->TextChanged();
2267 return callbackData;
2270 void Controller::PasteClipboardItemEvent()
2272 // Retrieve the clipboard contents first
2273 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
2274 std::string stringToPaste( notifier.GetContent() );
2276 // Commit the current pre-edit text; the contents of the clipboard should be appended
2277 mImpl->ResetImfManager();
2279 // Temporary disable hiding clipboard
2280 mImpl->SetClipboardHideEnable( false );
2283 PasteText( stringToPaste );
2285 mImpl->SetClipboardHideEnable( true );
2288 // protected : Inherit from Text::Decorator::ControllerInterface.
2290 void Controller::GetTargetSize( Vector2& targetSize )
2292 targetSize = mImpl->mModel->mVisualModel->mControlSize;
2295 void Controller::AddDecoration( Actor& actor, bool needsClipping )
2297 if( NULL != mImpl->mEditableControlInterface )
2299 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
2303 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
2305 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
2307 if( NULL != mImpl->mEventData )
2309 switch( handleType )
2313 Event event( Event::GRAB_HANDLE_EVENT );
2314 event.p1.mUint = state;
2315 event.p2.mFloat = x;
2316 event.p3.mFloat = y;
2318 mImpl->mEventData->mEventQueue.push_back( event );
2321 case LEFT_SELECTION_HANDLE:
2323 Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
2324 event.p1.mUint = state;
2325 event.p2.mFloat = x;
2326 event.p3.mFloat = y;
2328 mImpl->mEventData->mEventQueue.push_back( event );
2331 case RIGHT_SELECTION_HANDLE:
2333 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
2334 event.p1.mUint = state;
2335 event.p2.mFloat = x;
2336 event.p3.mFloat = y;
2338 mImpl->mEventData->mEventQueue.push_back( event );
2341 case LEFT_SELECTION_HANDLE_MARKER:
2342 case RIGHT_SELECTION_HANDLE_MARKER:
2344 // Markers do not move the handles.
2347 case HANDLE_TYPE_COUNT:
2349 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
2353 mImpl->RequestRelayout();
2357 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
2359 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
2361 if( NULL == mImpl->mEventData )
2368 case Toolkit::TextSelectionPopup::CUT:
2370 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
2371 mImpl->mOperationsPending = ALL_OPERATIONS;
2373 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2374 !mImpl->IsPlaceholderAvailable() )
2376 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2380 ShowPlaceholderText();
2383 mImpl->mEventData->mUpdateCursorPosition = true;
2384 mImpl->mEventData->mScrollAfterDelete = true;
2386 mImpl->RequestRelayout();
2388 if( NULL != mImpl->mEditableControlInterface )
2390 mImpl->mEditableControlInterface->TextChanged();
2394 case Toolkit::TextSelectionPopup::COPY:
2396 mImpl->SendSelectionToClipboard( false ); // Text not modified
2398 mImpl->mEventData->mUpdateCursorPosition = true;
2400 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
2403 case Toolkit::TextSelectionPopup::PASTE:
2405 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
2408 case Toolkit::TextSelectionPopup::SELECT:
2410 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
2412 if( mImpl->mEventData->mSelectionEnabled )
2414 // Creates a SELECT event.
2415 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
2419 case Toolkit::TextSelectionPopup::SELECT_ALL:
2421 // Creates a SELECT_ALL event
2422 SelectEvent( 0.f, 0.f, true );
2425 case Toolkit::TextSelectionPopup::CLIPBOARD:
2427 mImpl->ShowClipboard();
2430 case Toolkit::TextSelectionPopup::NONE:
2438 void Controller::DisplayTimeExpired()
2440 mImpl->mEventData->mUpdateCursorPosition = true;
2441 // Apply modifications to the model
2442 mImpl->mOperationsPending = ALL_OPERATIONS;
2444 mImpl->RequestRelayout();
2447 // private : Update.
2449 void Controller::InsertText( const std::string& text, Controller::InsertType type )
2451 bool removedPrevious = false;
2452 bool removedSelected = false;
2453 bool maxLengthReached = false;
2455 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
2457 if( NULL == mImpl->mEventData )
2462 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
2463 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
2464 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
2466 // TODO: At the moment the underline runs are only for pre-edit.
2467 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
2469 // Remove the previous IMF pre-edit.
2470 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
2472 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
2473 mImpl->mEventData->mPreEditLength,
2474 DONT_UPDATE_INPUT_STYLE );
2476 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
2477 mImpl->mEventData->mPreEditLength = 0u;
2481 // Remove the previous Selection.
2482 removedSelected = RemoveSelectedText();
2486 Vector<Character> utf32Characters;
2487 Length characterCount = 0u;
2491 // Convert text into UTF-32
2492 utf32Characters.Resize( text.size() );
2494 // This is a bit horrible but std::string returns a (signed) char*
2495 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
2497 // Transform a text array encoded in utf8 into an array encoded in utf32.
2498 // It returns the actual number of characters.
2499 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
2500 utf32Characters.Resize( characterCount );
2502 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
2503 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
2506 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
2508 // The placeholder text is no longer needed
2509 if( mImpl->IsShowingPlaceholderText() )
2514 mImpl->ChangeState( EventData::EDITING );
2516 // Handle the IMF (predicitive text) state changes
2517 if( COMMIT == type )
2519 // IMF manager is no longer handling key-events
2520 mImpl->ClearPreEditFlag();
2524 if( !mImpl->mEventData->mPreEditFlag )
2526 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
2528 // Record the start of the pre-edit text
2529 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
2532 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
2533 mImpl->mEventData->mPreEditFlag = true;
2535 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
2538 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
2540 // Restrict new text to fit within Maximum characters setting.
2541 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
2542 maxLengthReached = ( characterCount > maxSizeOfNewText );
2544 // The cursor position.
2545 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
2547 // Update the text's style.
2549 // Updates the text style runs by adding characters.
2550 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
2552 // Get the character index from the cursor index.
2553 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
2555 // Retrieve the text's style for the given index.
2557 mImpl->RetrieveDefaultInputStyle( style );
2558 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
2560 // Whether to add a new text color run.
2561 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor );
2563 // Whether to add a new font run.
2564 const bool addFontNameRun = style.familyName != mImpl->mEventData->mInputStyle.familyName;
2565 const bool addFontWeightRun = style.weight != mImpl->mEventData->mInputStyle.weight;
2566 const bool addFontWidthRun = style.width != mImpl->mEventData->mInputStyle.width;
2567 const bool addFontSlantRun = style.slant != mImpl->mEventData->mInputStyle.slant;
2568 const bool addFontSizeRun = style.size != mImpl->mEventData->mInputStyle.size;
2573 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
2574 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
2576 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
2577 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
2578 colorRun.characterRun.characterIndex = cursorIndex;
2579 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
2582 if( addFontNameRun ||
2588 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
2589 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
2591 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
2593 if( addFontNameRun )
2595 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
2596 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
2597 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
2598 fontDescriptionRun.familyDefined = true;
2600 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
2603 if( addFontWeightRun )
2605 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
2606 fontDescriptionRun.weightDefined = true;
2609 if( addFontWidthRun )
2611 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
2612 fontDescriptionRun.widthDefined = true;
2615 if( addFontSlantRun )
2617 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
2618 fontDescriptionRun.slantDefined = true;
2621 if( addFontSizeRun )
2623 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
2624 fontDescriptionRun.sizeDefined = true;
2627 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
2628 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
2631 // Insert at current cursor position.
2632 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
2634 if( cursorIndex < numberOfCharactersInModel )
2636 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
2640 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
2643 // Mark the first paragraph to be updated.
2644 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
2645 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
2647 // Update the cursor index.
2648 cursorIndex += maxSizeOfNewText;
2650 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 );
2653 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
2654 mImpl->IsPlaceholderAvailable() )
2656 // Show place-holder if empty after removing the pre-edit text
2657 ShowPlaceholderText();
2658 mImpl->mEventData->mUpdateCursorPosition = true;
2659 mImpl->ClearPreEditFlag();
2661 else if( removedPrevious ||
2663 ( 0 != utf32Characters.Count() ) )
2665 // Queue an inserted event
2666 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
2668 mImpl->mEventData->mUpdateCursorPosition = true;
2669 if( removedSelected )
2671 mImpl->mEventData->mScrollAfterDelete = true;
2675 mImpl->mEventData->mScrollAfterUpdatePosition = true;
2679 if( maxLengthReached )
2681 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
2683 mImpl->ResetImfManager();
2685 if( NULL != mImpl->mEditableControlInterface )
2687 // Do this last since it provides callbacks into application code
2688 mImpl->mEditableControlInterface->MaxLengthReached();
2693 void Controller::PasteText( const std::string& stringToPaste )
2695 InsertText( stringToPaste, Text::Controller::COMMIT );
2696 mImpl->ChangeState( EventData::EDITING );
2697 mImpl->RequestRelayout();
2699 if( NULL != mImpl->mEditableControlInterface )
2701 // Do this last since it provides callbacks into application code
2702 mImpl->mEditableControlInterface->TextChanged();
2706 bool Controller::RemoveText( int cursorOffset,
2707 int numberOfCharacters,
2708 UpdateInputStyleType type )
2710 bool removed = false;
2712 if( NULL == mImpl->mEventData )
2717 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
2718 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
2720 if( !mImpl->IsShowingPlaceholderText() )
2722 // Delete at current cursor position
2723 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
2724 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
2726 CharacterIndex cursorIndex = 0;
2728 // Validate the cursor position & number of characters
2729 if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
2731 cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
2734 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
2736 numberOfCharacters = currentText.Count() - cursorIndex;
2739 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.
2740 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
2742 // Mark the paragraphs to be updated.
2743 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
2744 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
2746 // Update the input style and remove the text's style before removing the text.
2748 if( UPDATE_INPUT_STYLE == type )
2750 // Keep a copy of the current input style.
2751 InputStyle currentInputStyle;
2752 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
2754 // Set first the default input style.
2755 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
2757 // Update the input style.
2758 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
2760 // Compare if the input style has changed.
2761 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
2763 if( hasInputStyleChanged )
2765 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
2766 // Queue the input style changed signal.
2767 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
2771 // Updates the text style runs by removing characters. Runs with no characters are removed.
2772 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
2774 // Remove the characters.
2775 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
2776 Vector<Character>::Iterator last = first + numberOfCharacters;
2778 currentText.Erase( first, last );
2780 // Cursor position retreat
2781 oldCursorIndex = cursorIndex;
2783 mImpl->mEventData->mScrollAfterDelete = true;
2785 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
2793 bool Controller::RemoveSelectedText()
2795 bool textRemoved( false );
2797 if( EventData::SELECTING == mImpl->mEventData->mState )
2799 std::string removedString;
2800 mImpl->RetrieveSelection( removedString, true );
2802 if( !removedString.empty() )
2805 mImpl->ChangeState( EventData::EDITING );
2812 // private : Relayout.
2814 bool Controller::DoRelayout( const Size& size,
2815 OperationsMask operationsRequired,
2818 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
2819 bool viewUpdated( false );
2821 // Calculate the operations to be done.
2822 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
2824 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
2825 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
2827 // Get the current layout size.
2828 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
2830 if( NO_OPERATION != ( LAYOUT & operations ) )
2832 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
2834 // Some vectors with data needed to layout and reorder may be void
2835 // after the first time the text has been laid out.
2836 // Fill the vectors again.
2838 // Calculate the number of glyphs to layout.
2839 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
2840 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
2841 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
2842 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
2844 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
2845 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
2846 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
2847 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
2849 if( 0u == totalNumberOfGlyphs )
2851 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
2853 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
2856 // Nothing else to do if there is no glyphs.
2857 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
2861 const Vector<LineBreakInfo>& lineBreakInfo = mImpl->mModel->mLogicalModel->mLineBreakInfo;
2862 const Vector<WordBreakInfo>& wordBreakInfo = mImpl->mModel->mLogicalModel->mWordBreakInfo;
2863 const Vector<CharacterDirection>& characterDirection = mImpl->mModel->mLogicalModel->mCharacterDirections;
2864 const Vector<GlyphInfo>& glyphs = mImpl->mModel->mVisualModel->mGlyphs;
2865 const Vector<CharacterIndex>& glyphsToCharactersMap = mImpl->mModel->mVisualModel->mGlyphsToCharacters;
2866 const Vector<Length>& charactersPerGlyph = mImpl->mModel->mVisualModel->mCharactersPerGlyph;
2867 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
2869 // Set the layout parameters.
2870 Layout::Parameters layoutParameters( size,
2872 lineBreakInfo.Begin(),
2873 wordBreakInfo.Begin(),
2874 ( 0u != characterDirection.Count() ) ? characterDirection.Begin() : NULL,
2876 glyphsToCharactersMap.Begin(),
2877 charactersPerGlyph.Begin(),
2878 charactersToGlyphBuffer,
2879 glyphsPerCharacterBuffer,
2880 totalNumberOfGlyphs,
2881 mImpl->mModel->mHorizontalAlignment );
2883 // Resize the vector of positions to have the same size than the vector of glyphs.
2884 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
2885 glyphPositions.Resize( totalNumberOfGlyphs );
2887 // Whether the last character is a new paragraph character.
2888 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
2889 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
2891 // The initial glyph and the number of glyphs to layout.
2892 layoutParameters.startGlyphIndex = startGlyphIndex;
2893 layoutParameters.numberOfGlyphs = numberOfGlyphs;
2894 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
2895 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
2897 // Update the visual model.
2899 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
2901 mImpl->mModel->mVisualModel->mLines,
2903 mImpl->mModel->mElideEnabled );
2905 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
2909 layoutSize = newLayoutSize;
2911 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
2913 mImpl->mAutoScrollDirectionRTL = false;
2916 // Reorder the lines
2917 if( NO_OPERATION != ( REORDER & operations ) )
2919 Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = mImpl->mModel->mLogicalModel->mBidirectionalParagraphInfo;
2920 Vector<BidirectionalLineInfoRun>& bidirectionalLineInfo = mImpl->mModel->mLogicalModel->mBidirectionalLineInfo;
2922 // Check first if there are paragraphs with bidirectional info.
2923 if( 0u != bidirectionalInfo.Count() )
2926 const Length numberOfLines = mImpl->mModel->mVisualModel->mLines.Count();
2928 // Reorder the lines.
2929 bidirectionalLineInfo.Reserve( numberOfLines ); // Reserve because is not known yet how many lines have right to left characters.
2930 ReorderLines( bidirectionalInfo,
2932 requestedNumberOfCharacters,
2933 mImpl->mModel->mVisualModel->mLines,
2934 bidirectionalLineInfo );
2936 // Set the bidirectional info per line into the layout parameters.
2937 layoutParameters.lineBidirectionalInfoRunsBuffer = bidirectionalLineInfo.Begin();
2938 layoutParameters.numberOfBidirectionalInfoRuns = bidirectionalLineInfo.Count();
2940 // Re-layout the text. Reorder those lines with right to left characters.
2941 mImpl->mLayoutEngine.ReLayoutRightToLeftLines( layoutParameters,
2943 requestedNumberOfCharacters,
2946 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && ( numberOfLines > 0 ) )
2948 const LineRun* const firstline = mImpl->mModel->mVisualModel->mLines.Begin();
2951 mImpl->mAutoScrollDirectionRTL = firstline->direction;
2957 // Sets the layout size.
2958 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
2960 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
2965 if( NO_OPERATION != ( ALIGN & operations ) )
2967 // The laid-out lines.
2968 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
2970 // Need to align with the control's size as the text may contain lines
2971 // starting either with left to right text or right to left.
2972 mImpl->mLayoutEngine.Align( size,
2974 requestedNumberOfCharacters,
2975 mImpl->mModel->mHorizontalAlignment,
2977 mImpl->mModel->mAlignmentOffset );
2981 #if defined(DEBUG_ENABLED)
2982 std::string currentText;
2983 GetText( currentText );
2984 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mAutoScrollDirectionRTL[%s] [%s]\n", this, (mImpl->mAutoScrollDirectionRTL)?"true":"false", currentText.c_str() );
2986 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
2990 void Controller::CalculateVerticalOffset( const Size& controlSize )
2992 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
2994 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
2996 // Get the line height of the default font.
2997 layoutSize.height = mImpl->GetDefaultFontLineHeight();
3000 switch( mImpl->mModel->mVerticalAlignment )
3002 case Layout::VERTICAL_ALIGN_TOP:
3004 mImpl->mModel->mScrollPosition.y = 0.f;
3007 case Layout::VERTICAL_ALIGN_CENTER:
3009 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
3012 case Layout::VERTICAL_ALIGN_BOTTOM:
3014 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
3020 // private : Events.
3022 void Controller::ProcessModifyEvents()
3024 Vector<ModifyEvent>& events = mImpl->mModifyEvents;
3026 if( 0u == events.Count() )
3032 for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
3033 endIt = events.End();
3037 const ModifyEvent& event = *it;
3039 if( ModifyEvent::TEXT_REPLACED == event.type )
3041 // A (single) replace event should come first, otherwise we wasted time processing NOOP events
3042 DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
3044 TextReplacedEvent();
3046 else if( ModifyEvent::TEXT_INSERTED == event.type )
3048 TextInsertedEvent();
3050 else if( ModifyEvent::TEXT_DELETED == event.type )
3052 // Placeholder-text cannot be deleted
3053 if( !mImpl->IsShowingPlaceholderText() )
3060 if( NULL != mImpl->mEventData )
3062 // When the text is being modified, delay cursor blinking
3063 mImpl->mEventData->mDecorator->DelayCursorBlink();
3066 // Discard temporary text
3070 void Controller::TextReplacedEvent()
3072 // The natural size needs to be re-calculated.
3073 mImpl->mRecalculateNaturalSize = true;
3075 // Apply modifications to the model
3076 mImpl->mOperationsPending = ALL_OPERATIONS;
3079 void Controller::TextInsertedEvent()
3081 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
3083 if( NULL == mImpl->mEventData )
3088 mImpl->mEventData->mCheckScrollAmount = true;
3090 // The natural size needs to be re-calculated.
3091 mImpl->mRecalculateNaturalSize = true;
3093 // Apply modifications to the model; TODO - Optimize this
3094 mImpl->mOperationsPending = ALL_OPERATIONS;
3097 void Controller::TextDeletedEvent()
3099 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
3101 if( NULL == mImpl->mEventData )
3106 mImpl->mEventData->mCheckScrollAmount = true;
3108 // The natural size needs to be re-calculated.
3109 mImpl->mRecalculateNaturalSize = true;
3111 // Apply modifications to the model; TODO - Optimize this
3112 mImpl->mOperationsPending = ALL_OPERATIONS;
3115 void Controller::SelectEvent( float x, float y, bool selectAll )
3117 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
3119 if( NULL != mImpl->mEventData )
3123 Event event( Event::SELECT_ALL );
3124 mImpl->mEventData->mEventQueue.push_back( event );
3128 Event event( Event::SELECT );
3129 event.p2.mFloat = x;
3130 event.p3.mFloat = y;
3131 mImpl->mEventData->mEventQueue.push_back( event );
3134 mImpl->mEventData->mCheckScrollAmount = true;
3135 mImpl->mEventData->mIsLeftHandleSelected = true;
3136 mImpl->mEventData->mIsRightHandleSelected = true;
3137 mImpl->RequestRelayout();
3141 bool Controller::BackspaceKeyEvent()
3143 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p DALI_KEY_BACKSPACE\n", this );
3145 bool removed = false;
3147 if( NULL == mImpl->mEventData )
3152 // IMF manager is no longer handling key-events
3153 mImpl->ClearPreEditFlag();
3155 if( EventData::SELECTING == mImpl->mEventData->mState )
3157 removed = RemoveSelectedText();
3159 else if( mImpl->mEventData->mPrimaryCursorPosition > 0 )
3161 // Remove the character before the current cursor position
3162 removed = RemoveText( -1,
3164 UPDATE_INPUT_STYLE );
3169 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3170 !mImpl->IsPlaceholderAvailable() )
3172 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3176 ShowPlaceholderText();
3178 mImpl->mEventData->mUpdateCursorPosition = true;
3179 mImpl->mEventData->mScrollAfterDelete = true;
3185 // private : Helpers.
3187 void Controller::ResetText()
3190 mImpl->mModel->mLogicalModel->mText.Clear();
3192 // We have cleared everything including the placeholder-text
3193 mImpl->PlaceholderCleared();
3195 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3196 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3197 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
3199 // Clear any previous text.
3200 mImpl->mTextUpdateInfo.mClearAll = true;
3202 // The natural size needs to be re-calculated.
3203 mImpl->mRecalculateNaturalSize = true;
3205 // Apply modifications to the model
3206 mImpl->mOperationsPending = ALL_OPERATIONS;
3209 void Controller::ShowPlaceholderText()
3211 if( mImpl->IsPlaceholderAvailable() )
3213 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
3215 if( NULL == mImpl->mEventData )
3220 mImpl->mEventData->mIsShowingPlaceholderText = true;
3222 // Disable handles when showing place-holder text
3223 mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
3224 mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
3225 mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
3227 const char* text( NULL );
3230 if( !mImpl->mEventData->mPlaceholderTextActive.empty() || !mImpl->mEventData->mPlaceholderTextInactive.empty() )
3232 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
3233 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
3235 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
3236 size = mImpl->mEventData->mPlaceholderTextActive.size();
3240 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
3241 size = mImpl->mEventData->mPlaceholderTextInactive.size();
3246 if( 0u != mImpl->mEventData->mPlaceholderText.c_str() )
3248 text = mImpl->mEventData->mPlaceholderText.c_str();
3249 size = mImpl->mEventData->mPlaceholderText.size();
3253 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3254 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3256 // Reset model for showing placeholder.
3257 mImpl->mModel->mLogicalModel->mText.Clear();
3258 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
3260 // Convert text into UTF-32
3261 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
3262 utf32Characters.Resize( size );
3264 // This is a bit horrible but std::string returns a (signed) char*
3265 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
3267 // Transform a text array encoded in utf8 into an array encoded in utf32.
3268 // It returns the actual number of characters.
3269 const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
3270 utf32Characters.Resize( characterCount );
3272 // The characters to be added.
3273 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
3275 // Reset the cursor position
3276 mImpl->mEventData->mPrimaryCursorPosition = 0;
3278 // The natural size needs to be re-calculated.
3279 mImpl->mRecalculateNaturalSize = true;
3281 // Apply modifications to the model
3282 mImpl->mOperationsPending = ALL_OPERATIONS;
3284 // Update the rest of the model during size negotiation
3285 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
3289 void Controller::ClearFontData()
3291 if( mImpl->mFontDefaults )
3293 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
3296 // Set flags to update the model.
3297 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3298 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3299 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
3301 mImpl->mTextUpdateInfo.mClearAll = true;
3302 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
3303 mImpl->mRecalculateNaturalSize = true;
3305 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
3310 UPDATE_LAYOUT_SIZE |
3315 void Controller::ClearStyleData()
3317 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
3318 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
3321 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
3323 // Reset the cursor position
3324 if( NULL != mImpl->mEventData )
3326 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
3328 // Update the cursor if it's in editing mode.
3329 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
3331 mImpl->mEventData->mUpdateCursorPosition = true;
3336 void Controller::ResetScrollPosition()
3338 if( NULL != mImpl->mEventData )
3340 // Reset the scroll position.
3341 mImpl->mModel->mScrollPosition = Vector2::ZERO;
3342 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3346 // private : Private contructors & copy operator.
3348 Controller::Controller()
3351 mImpl = new Controller::Impl( NULL, NULL );
3354 Controller::Controller( ControlInterface* controlInterface )
3356 mImpl = new Controller::Impl( controlInterface, NULL );
3359 Controller::Controller( ControlInterface* controlInterface,
3360 EditableControlInterface* editableControlInterface )
3362 mImpl = new Controller::Impl( controlInterface,
3363 editableControlInterface );
3366 // The copy constructor and operator are left unimplemented.
3368 // protected : Destructor.
3370 Controller::~Controller()
3377 } // namespace Toolkit