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;
395 void Controller::SetSelectionEnabled( bool enabled )
397 mImpl->mEventData->mSelectionEnabled = enabled;
400 bool Controller::IsSelectionEnabled() const
402 return mImpl->mEventData->mSelectionEnabled;
407 void Controller::SetText( const std::string& text )
409 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" );
411 // Reset keyboard as text changed
412 mImpl->ResetImfManager();
414 // Remove the previously set text and style.
420 CharacterIndex lastCursorIndex = 0u;
422 if( NULL != mImpl->mEventData )
424 // If popup shown then hide it by switching to Editing state
425 if( ( EventData::SELECTING == mImpl->mEventData->mState ) ||
426 ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
427 ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) ||
428 ( EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState ) )
430 mImpl->ChangeState( EventData::EDITING );
436 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mTextColor );
438 MarkupProcessData markupProcessData( mImpl->mModel->mLogicalModel->mColorRuns,
439 mImpl->mModel->mLogicalModel->mFontDescriptionRuns );
441 Length textSize = 0u;
442 const uint8_t* utf8 = NULL;
443 if( mImpl->mMarkupProcessorEnabled )
445 ProcessMarkupString( text, markupProcessData );
446 textSize = markupProcessData.markupProcessedText.size();
448 // This is a bit horrible but std::string returns a (signed) char*
449 utf8 = reinterpret_cast<const uint8_t*>( markupProcessData.markupProcessedText.c_str() );
453 textSize = text.size();
455 // This is a bit horrible but std::string returns a (signed) char*
456 utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
459 // Convert text into UTF-32
460 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
461 utf32Characters.Resize( textSize );
463 // Transform a text array encoded in utf8 into an array encoded in utf32.
464 // It returns the actual number of characters.
465 Length characterCount = Utf8ToUtf32( utf8, textSize, utf32Characters.Begin() );
466 utf32Characters.Resize( characterCount );
468 DALI_ASSERT_DEBUG( textSize >= characterCount && "Invalid UTF32 conversion length" );
469 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", this, textSize, mImpl->mModel->mLogicalModel->mText.Count() );
471 // The characters to be added.
472 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
474 // To reset the cursor position
475 lastCursorIndex = characterCount;
477 // Update the rest of the model during size negotiation
478 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
480 // The natural size needs to be re-calculated.
481 mImpl->mRecalculateNaturalSize = true;
483 // Apply modifications to the model
484 mImpl->mOperationsPending = ALL_OPERATIONS;
488 ShowPlaceholderText();
491 // Resets the cursor position.
492 ResetCursorPosition( lastCursorIndex );
494 // Scrolls the text to make the cursor visible.
495 ResetScrollPosition();
497 mImpl->RequestRelayout();
499 if( NULL != mImpl->mEventData )
501 // Cancel previously queued events
502 mImpl->mEventData->mEventQueue.clear();
505 // Do this last since it provides callbacks into application code.
506 if( NULL != mImpl->mEditableControlInterface )
508 mImpl->mEditableControlInterface->TextChanged();
512 void Controller::GetText( std::string& text ) const
514 if( !mImpl->IsShowingPlaceholderText() )
516 // Retrieves the text string.
517 mImpl->GetText( 0u, text );
521 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this );
525 void Controller::SetPlaceholderText( const std::string& text )
527 if( NULL != mImpl->mEventData )
529 mImpl->mEventData->mPlaceholderText = text;
531 // Update placeholder if there is no text
532 if( mImpl->IsShowingPlaceholderText() ||
533 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
535 ShowPlaceholderText();
540 // This is overloading function for PLACEHOLDER_TEXT_FOCUSED in text-field
541 void Controller::SetPlaceholderText( PlaceholderType type, const std::string& text )
543 if( NULL != mImpl->mEventData )
545 if( PLACEHOLDER_TYPE_INACTIVE == type )
547 mImpl->mEventData->mPlaceholderTextInactive = text;
551 mImpl->mEventData->mPlaceholderTextActive = text;
554 // Update placeholder if there is no text
555 if( mImpl->IsShowingPlaceholderText() ||
556 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
558 ShowPlaceholderText();
563 void Controller::GetPlaceholderText( std::string& text ) const
565 if( NULL != mImpl->mEventData )
567 text = mImpl->mEventData->mPlaceholderText;
571 // This is overloading function for PLACEHOLDER_TEXT_FOCUSED in text-field
572 void Controller::GetPlaceholderText( PlaceholderType type, std::string& text ) const
574 if( NULL != mImpl->mEventData )
576 if( PLACEHOLDER_TYPE_INACTIVE == type )
578 text = mImpl->mEventData->mPlaceholderTextInactive;
582 text = mImpl->mEventData->mPlaceholderTextActive;
587 void Controller::UpdateAfterFontChange( const std::string& newDefaultFont )
589 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
591 if( !mImpl->mFontDefaults->familyDefined ) // If user defined font then should not update when system font changes
593 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
594 mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
598 mImpl->RequestRelayout();
602 // public : Default style & Input style
604 void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
606 if( NULL == mImpl->mFontDefaults )
608 mImpl->mFontDefaults = new FontDefaults();
611 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
612 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
613 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
615 // Clear the font-specific data
618 mImpl->RequestRelayout();
621 const std::string& Controller::GetDefaultFontFamily() const
623 if( NULL != mImpl->mFontDefaults )
625 return mImpl->mFontDefaults->mFontDescription.family;
631 void Controller::SetDefaultFontWeight( FontWeight weight )
633 if( NULL == mImpl->mFontDefaults )
635 mImpl->mFontDefaults = new FontDefaults();
638 mImpl->mFontDefaults->mFontDescription.weight = weight;
639 mImpl->mFontDefaults->weightDefined = true;
641 // Clear the font-specific data
644 mImpl->RequestRelayout();
647 bool Controller::IsDefaultFontWeightDefined() const
649 return mImpl->mFontDefaults->weightDefined;
652 FontWeight Controller::GetDefaultFontWeight() const
654 if( NULL != mImpl->mFontDefaults )
656 return mImpl->mFontDefaults->mFontDescription.weight;
659 return TextAbstraction::FontWeight::NORMAL;
662 void Controller::SetDefaultFontWidth( FontWidth width )
664 if( NULL == mImpl->mFontDefaults )
666 mImpl->mFontDefaults = new FontDefaults();
669 mImpl->mFontDefaults->mFontDescription.width = width;
670 mImpl->mFontDefaults->widthDefined = true;
672 // Clear the font-specific data
675 mImpl->RequestRelayout();
678 bool Controller::IsDefaultFontWidthDefined() const
680 return mImpl->mFontDefaults->widthDefined;
683 FontWidth Controller::GetDefaultFontWidth() const
685 if( NULL != mImpl->mFontDefaults )
687 return mImpl->mFontDefaults->mFontDescription.width;
690 return TextAbstraction::FontWidth::NORMAL;
693 void Controller::SetDefaultFontSlant( FontSlant slant )
695 if( NULL == mImpl->mFontDefaults )
697 mImpl->mFontDefaults = new FontDefaults();
700 mImpl->mFontDefaults->mFontDescription.slant = slant;
701 mImpl->mFontDefaults->slantDefined = true;
703 // Clear the font-specific data
706 mImpl->RequestRelayout();
709 bool Controller::IsDefaultFontSlantDefined() const
711 return mImpl->mFontDefaults->slantDefined;
714 FontSlant Controller::GetDefaultFontSlant() const
716 if( NULL != mImpl->mFontDefaults )
718 return mImpl->mFontDefaults->mFontDescription.slant;
721 return TextAbstraction::FontSlant::NORMAL;
724 void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
726 if( NULL == mImpl->mFontDefaults )
728 mImpl->mFontDefaults = new FontDefaults();
735 mImpl->mFontDefaults->mDefaultPointSize = fontSize;
736 mImpl->mFontDefaults->sizeDefined = true;
741 // Point size = Pixel size * 72 / DPI
742 unsigned int horizontalDpi = 0u;
743 unsigned int verticalDpi = 0u;
744 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
745 fontClient.GetDpi( horizontalDpi, verticalDpi );
747 mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72 ) / horizontalDpi;
748 mImpl->mFontDefaults->sizeDefined = true;
753 DALI_ASSERT_ALWAYS( false );
757 // Clear the font-specific data
760 mImpl->RequestRelayout();
763 float Controller::GetDefaultFontSize( FontSizeType type ) const
766 if( NULL != mImpl->mFontDefaults )
772 value = mImpl->mFontDefaults->mDefaultPointSize;
777 // Pixel size = Point size * DPI / 72
778 unsigned int horizontalDpi = 0u;
779 unsigned int verticalDpi = 0u;
780 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
781 fontClient.GetDpi( horizontalDpi, verticalDpi );
783 value = mImpl->mFontDefaults->mDefaultPointSize * horizontalDpi / 72;
788 DALI_ASSERT_ALWAYS( false );
797 void Controller::SetDefaultColor( const Vector4& color )
799 mImpl->mTextColor = color;
801 if( !mImpl->IsShowingPlaceholderText() )
803 mImpl->mModel->mVisualModel->SetTextColor( color );
805 mImpl->RequestRelayout();
809 const Vector4& Controller::GetDefaultColor() const
811 return mImpl->mTextColor;
814 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
816 if( NULL != mImpl->mEventData )
818 mImpl->mEventData->mPlaceholderTextColor = textColor;
821 if( mImpl->IsShowingPlaceholderText() )
823 mImpl->mModel->mVisualModel->SetTextColor( textColor );
824 mImpl->RequestRelayout();
828 const Vector4& Controller::GetPlaceholderTextColor() const
830 if( NULL != mImpl->mEventData )
832 return mImpl->mEventData->mPlaceholderTextColor;
838 void Controller::SetShadowOffset( const Vector2& shadowOffset )
840 mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
842 mImpl->RequestRelayout();
845 const Vector2& Controller::GetShadowOffset() const
847 return mImpl->mModel->mVisualModel->GetShadowOffset();
850 void Controller::SetShadowColor( const Vector4& shadowColor )
852 mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
854 mImpl->RequestRelayout();
857 const Vector4& Controller::GetShadowColor() const
859 return mImpl->mModel->mVisualModel->GetShadowColor();
862 void Controller::SetUnderlineColor( const Vector4& color )
864 mImpl->mModel->mVisualModel->SetUnderlineColor( color );
866 mImpl->RequestRelayout();
869 const Vector4& Controller::GetUnderlineColor() const
871 return mImpl->mModel->mVisualModel->GetUnderlineColor();
874 void Controller::SetUnderlineEnabled( bool enabled )
876 mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
878 mImpl->RequestRelayout();
881 bool Controller::IsUnderlineEnabled() const
883 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
886 void Controller::SetUnderlineHeight( float height )
888 mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
890 mImpl->RequestRelayout();
893 float Controller::GetUnderlineHeight() const
895 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
898 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
900 if( NULL == mImpl->mEmbossDefaults )
902 mImpl->mEmbossDefaults = new EmbossDefaults();
905 mImpl->mEmbossDefaults->properties = embossProperties;
908 const std::string& Controller::GetDefaultEmbossProperties() const
910 if( NULL != mImpl->mEmbossDefaults )
912 return mImpl->mEmbossDefaults->properties;
918 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
920 if( NULL == mImpl->mOutlineDefaults )
922 mImpl->mOutlineDefaults = new OutlineDefaults();
925 mImpl->mOutlineDefaults->properties = outlineProperties;
928 const std::string& Controller::GetDefaultOutlineProperties() const
930 if( NULL != mImpl->mOutlineDefaults )
932 return mImpl->mOutlineDefaults->properties;
938 void Controller::SetDefaultLineSpacing( float lineSpacing )
940 //TODO finish implementation
941 mImpl->mLayoutEngine.SetDefaultLineSpacing( lineSpacing );
944 float Controller::GetDefaultLineSpacing() const
946 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
949 void Controller::SetInputColor( const Vector4& color )
951 if( NULL != mImpl->mEventData )
953 mImpl->mEventData->mInputStyle.textColor = color;
954 mImpl->mEventData->mInputStyle.isDefaultColor = false;
956 if( EventData::SELECTING == mImpl->mEventData->mState )
958 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
960 // Get start and end position of selection
961 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
962 const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
964 // Add the color run.
965 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
966 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
968 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
969 colorRun.color = color;
970 colorRun.characterRun.characterIndex = startOfSelectedText;
971 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
973 // Request to relayout.
974 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
975 mImpl->RequestRelayout();
977 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
978 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
979 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
984 const Vector4& Controller::GetInputColor() const
986 if( NULL != mImpl->mEventData )
988 return mImpl->mEventData->mInputStyle.textColor;
991 // Return the default text's color if there is no EventData.
992 return mImpl->mTextColor;
996 void Controller::SetInputFontFamily( const std::string& fontFamily )
998 if( NULL != mImpl->mEventData )
1000 mImpl->mEventData->mInputStyle.familyName = fontFamily;
1001 mImpl->mEventData->mInputStyle.isFamilyDefined = true;
1003 if( EventData::SELECTING == mImpl->mEventData->mState )
1005 CharacterIndex startOfSelectedText = 0u;
1006 Length lengthOfSelectedText = 0u;
1007 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1008 mImpl->mModel->mLogicalModel,
1009 startOfSelectedText,
1010 lengthOfSelectedText );
1012 fontDescriptionRun.familyLength = fontFamily.size();
1013 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
1014 memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength );
1015 fontDescriptionRun.familyDefined = true;
1017 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
1019 // Request to relayout.
1020 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1025 UPDATE_LAYOUT_SIZE |
1028 mImpl->mRecalculateNaturalSize = true;
1029 mImpl->RequestRelayout();
1031 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1032 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1033 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1035 // As the font changes, recalculate the handle positions is needed.
1036 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1037 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1038 mImpl->mEventData->mUpdateHighlightBox = true;
1039 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1044 const std::string& Controller::GetInputFontFamily() const
1046 if( NULL != mImpl->mEventData )
1048 return mImpl->mEventData->mInputStyle.familyName;
1051 // Return the default font's family if there is no EventData.
1052 return GetDefaultFontFamily();
1055 void Controller::SetInputFontWeight( FontWeight weight )
1057 if( NULL != mImpl->mEventData )
1059 mImpl->mEventData->mInputStyle.weight = weight;
1060 mImpl->mEventData->mInputStyle.isWeightDefined = true;
1062 if( EventData::SELECTING == mImpl->mEventData->mState )
1064 CharacterIndex startOfSelectedText = 0u;
1065 Length lengthOfSelectedText = 0u;
1066 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1067 mImpl->mModel->mLogicalModel,
1068 startOfSelectedText,
1069 lengthOfSelectedText );
1071 fontDescriptionRun.weight = weight;
1072 fontDescriptionRun.weightDefined = true;
1074 // Request to relayout.
1075 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1080 UPDATE_LAYOUT_SIZE |
1083 mImpl->mRecalculateNaturalSize = true;
1084 mImpl->RequestRelayout();
1086 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1087 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1088 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1090 // As the font might change, recalculate the handle positions is needed.
1091 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1092 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1093 mImpl->mEventData->mUpdateHighlightBox = true;
1094 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1099 bool Controller::IsInputFontWeightDefined() const
1101 bool defined = false;
1103 if( NULL != mImpl->mEventData )
1105 defined = mImpl->mEventData->mInputStyle.isWeightDefined;
1111 FontWeight Controller::GetInputFontWeight() const
1113 if( NULL != mImpl->mEventData )
1115 return mImpl->mEventData->mInputStyle.weight;
1118 return GetDefaultFontWeight();
1121 void Controller::SetInputFontWidth( FontWidth width )
1123 if( NULL != mImpl->mEventData )
1125 mImpl->mEventData->mInputStyle.width = width;
1126 mImpl->mEventData->mInputStyle.isWidthDefined = true;
1128 if( EventData::SELECTING == mImpl->mEventData->mState )
1130 CharacterIndex startOfSelectedText = 0u;
1131 Length lengthOfSelectedText = 0u;
1132 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1133 mImpl->mModel->mLogicalModel,
1134 startOfSelectedText,
1135 lengthOfSelectedText );
1137 fontDescriptionRun.width = width;
1138 fontDescriptionRun.widthDefined = true;
1140 // Request to relayout.
1141 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1146 UPDATE_LAYOUT_SIZE |
1149 mImpl->mRecalculateNaturalSize = true;
1150 mImpl->RequestRelayout();
1152 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1153 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1154 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1156 // As the font might change, recalculate the handle positions is needed.
1157 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1158 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1159 mImpl->mEventData->mUpdateHighlightBox = true;
1160 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1165 bool Controller::IsInputFontWidthDefined() const
1167 bool defined = false;
1169 if( NULL != mImpl->mEventData )
1171 defined = mImpl->mEventData->mInputStyle.isWidthDefined;
1177 FontWidth Controller::GetInputFontWidth() const
1179 if( NULL != mImpl->mEventData )
1181 return mImpl->mEventData->mInputStyle.width;
1184 return GetDefaultFontWidth();
1187 void Controller::SetInputFontSlant( FontSlant slant )
1189 if( NULL != mImpl->mEventData )
1191 mImpl->mEventData->mInputStyle.slant = slant;
1192 mImpl->mEventData->mInputStyle.isSlantDefined = true;
1194 if( EventData::SELECTING == mImpl->mEventData->mState )
1196 CharacterIndex startOfSelectedText = 0u;
1197 Length lengthOfSelectedText = 0u;
1198 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1199 mImpl->mModel->mLogicalModel,
1200 startOfSelectedText,
1201 lengthOfSelectedText );
1203 fontDescriptionRun.slant = slant;
1204 fontDescriptionRun.slantDefined = true;
1206 // Request to relayout.
1207 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1212 UPDATE_LAYOUT_SIZE |
1215 mImpl->mRecalculateNaturalSize = true;
1216 mImpl->RequestRelayout();
1218 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1219 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1220 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1222 // As the font might change, recalculate the handle positions is needed.
1223 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1224 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1225 mImpl->mEventData->mUpdateHighlightBox = true;
1226 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1231 bool Controller::IsInputFontSlantDefined() const
1233 bool defined = false;
1235 if( NULL != mImpl->mEventData )
1237 defined = mImpl->mEventData->mInputStyle.isSlantDefined;
1243 FontSlant Controller::GetInputFontSlant() const
1245 if( NULL != mImpl->mEventData )
1247 return mImpl->mEventData->mInputStyle.slant;
1250 return GetDefaultFontSlant();
1253 void Controller::SetInputFontPointSize( float size )
1255 if( NULL != mImpl->mEventData )
1257 mImpl->mEventData->mInputStyle.size = size;
1258 mImpl->mEventData->mInputStyle.isSizeDefined = true;
1260 if( EventData::SELECTING == mImpl->mEventData->mState )
1262 CharacterIndex startOfSelectedText = 0u;
1263 Length lengthOfSelectedText = 0u;
1264 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1265 mImpl->mModel->mLogicalModel,
1266 startOfSelectedText,
1267 lengthOfSelectedText );
1269 fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
1270 fontDescriptionRun.sizeDefined = true;
1272 // Request to relayout.
1273 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1278 UPDATE_LAYOUT_SIZE |
1281 mImpl->mRecalculateNaturalSize = true;
1282 mImpl->RequestRelayout();
1284 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1285 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1286 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1288 // As the font might change, recalculate the handle positions is needed.
1289 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1290 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1291 mImpl->mEventData->mUpdateHighlightBox = true;
1292 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1297 float Controller::GetInputFontPointSize() const
1299 if( NULL != mImpl->mEventData )
1301 return mImpl->mEventData->mInputStyle.size;
1304 // Return the default font's point size if there is no EventData.
1305 return GetDefaultFontSize( Text::Controller::POINT_SIZE );
1308 void Controller::SetInputLineSpacing( float lineSpacing )
1310 if( NULL != mImpl->mEventData )
1312 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1313 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1317 float Controller::GetInputLineSpacing() const
1319 if( NULL != mImpl->mEventData )
1321 return mImpl->mEventData->mInputStyle.lineSpacing;
1327 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1329 if( NULL != mImpl->mEventData )
1331 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1335 const std::string& Controller::GetInputShadowProperties() const
1337 if( NULL != mImpl->mEventData )
1339 return mImpl->mEventData->mInputStyle.shadowProperties;
1342 return EMPTY_STRING;
1345 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1347 if( NULL != mImpl->mEventData )
1349 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1353 const std::string& Controller::GetInputUnderlineProperties() const
1355 if( NULL != mImpl->mEventData )
1357 return mImpl->mEventData->mInputStyle.underlineProperties;
1360 return EMPTY_STRING;
1363 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
1365 if( NULL != mImpl->mEventData )
1367 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1371 const std::string& Controller::GetInputEmbossProperties() const
1373 if( NULL != mImpl->mEventData )
1375 return mImpl->mEventData->mInputStyle.embossProperties;
1378 return GetDefaultEmbossProperties();
1381 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
1383 if( NULL != mImpl->mEventData )
1385 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1389 const std::string& Controller::GetInputOutlineProperties() const
1391 if( NULL != mImpl->mEventData )
1393 return mImpl->mEventData->mInputStyle.outlineProperties;
1396 return GetDefaultOutlineProperties();
1399 void Controller::SetInputModePassword( bool passwordInput )
1401 if( NULL != mImpl->mEventData )
1403 mImpl->mEventData->mPasswordInput = passwordInput;
1407 bool Controller::IsInputModePassword()
1409 if( NULL != mImpl->mEventData )
1411 return mImpl->mEventData->mPasswordInput;
1416 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
1418 if( NULL != mImpl->mEventData )
1420 mImpl->mEventData->mDoubleTapAction = action;
1424 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1426 NoTextTap::Action action = NoTextTap::NO_ACTION;
1428 if( NULL != mImpl->mEventData )
1430 action = mImpl->mEventData->mDoubleTapAction;
1436 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
1438 if( NULL != mImpl->mEventData )
1440 mImpl->mEventData->mLongPressAction = action;
1444 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1446 NoTextTap::Action action = NoTextTap::NO_ACTION;
1448 if( NULL != mImpl->mEventData )
1450 action = mImpl->mEventData->mLongPressAction;
1456 bool Controller::IsUnderlineSetByString()
1458 return mImpl->mUnderlineSetByString;
1461 void Controller::UnderlineSetByString( bool setByString )
1463 mImpl->mUnderlineSetByString = setByString;
1466 bool Controller::IsShadowSetByString()
1468 return mImpl->mShadowSetByString;
1471 void Controller::ShadowSetByString( bool setByString )
1473 mImpl->mShadowSetByString = setByString;
1476 bool Controller::IsFontStyleSetByString()
1478 return mImpl->mFontStyleSetByString;
1481 void Controller::FontStyleSetByString( bool setByString )
1483 mImpl->mFontStyleSetByString = setByString;
1486 // public : Queries & retrieves.
1488 Layout::Engine& Controller::GetLayoutEngine()
1490 return mImpl->mLayoutEngine;
1493 View& Controller::GetView()
1495 return mImpl->mView;
1498 Vector3 Controller::GetNaturalSize()
1500 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
1501 Vector3 naturalSize;
1503 // Make sure the model is up-to-date before layouting
1504 ProcessModifyEvents();
1506 if( mImpl->mRecalculateNaturalSize )
1508 // Operations that can be done only once until the text changes.
1509 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1516 GET_GLYPH_METRICS );
1518 // Set the update info to relayout the whole text.
1519 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1520 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1522 // Make sure the model is up-to-date before layouting
1523 mImpl->UpdateModel( onlyOnceOperations );
1525 // Layout the text for the new width.
1526 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
1528 // Store the actual control's size to restore later.
1529 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
1531 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
1532 static_cast<OperationsMask>( onlyOnceOperations |
1534 naturalSize.GetVectorXY() );
1536 // Do not do again the only once operations.
1537 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1539 // Do the size related operations again.
1540 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1543 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1545 // Stores the natural size to avoid recalculate it again
1546 // unless the text/style changes.
1547 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
1549 mImpl->mRecalculateNaturalSize = false;
1551 // Clear the update info. This info will be set the next time the text is updated.
1552 mImpl->mTextUpdateInfo.Clear();
1554 // Restore the actual control's size.
1555 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
1557 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1561 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
1563 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1566 naturalSize.x = ConvertToEven( naturalSize.x );
1567 naturalSize.y = ConvertToEven( naturalSize.y );
1572 float Controller::GetHeightForWidth( float width )
1574 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
1575 // Make sure the model is up-to-date before layouting
1576 ProcessModifyEvents();
1579 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 )
1581 // Operations that can be done only once until the text changes.
1582 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1589 GET_GLYPH_METRICS );
1591 // Set the update info to relayout the whole text.
1592 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1593 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1595 // Make sure the model is up-to-date before layouting
1596 mImpl->UpdateModel( onlyOnceOperations );
1599 // Layout the text for the new width.
1600 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
1602 // Store the actual control's width.
1603 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
1605 DoRelayout( Size( width, MAX_FLOAT ),
1606 static_cast<OperationsMask>( onlyOnceOperations |
1610 // Do not do again the only once operations.
1611 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1613 // Do the size related operations again.
1614 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1618 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1620 // Clear the update info. This info will be set the next time the text is updated.
1621 mImpl->mTextUpdateInfo.Clear();
1623 // Restore the actual control's width.
1624 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
1626 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
1630 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
1631 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
1634 return layoutSize.height;
1637 int Controller::GetLineCount( float width )
1639 GetHeightForWidth( width );
1640 int numberofLines = mImpl->mModel->GetNumberOfLines();
1641 return numberofLines;
1644 const ModelInterface* const Controller::GetTextModel() const
1646 return mImpl->mModel.Get();
1649 float Controller::GetScrollAmountByUserInput()
1651 float scrollAmount = 0.0f;
1653 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
1655 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
1656 mImpl->mEventData->mCheckScrollAmount = false;
1658 return scrollAmount;
1661 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
1663 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
1666 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
1667 layoutHeight = layout.height;
1668 scrollPosition = mImpl->mModel->mScrollPosition.y;
1669 isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
1673 void Controller::SetHiddenInputOption(const Property::Map& options )
1675 if( NULL == mImpl->mHiddenInput )
1677 mImpl->mHiddenInput = new HiddenText( this );
1679 mImpl->mHiddenInput->SetProperties(options);
1682 void Controller::GetHiddenInputOption(Property::Map& options )
1684 if( NULL != mImpl->mHiddenInput )
1686 mImpl->mHiddenInput->GetProperties(options);
1690 // public : Relayout.
1692 Controller::UpdateTextType Controller::Relayout( const Size& size )
1694 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
1696 UpdateTextType updateTextType = NONE_UPDATED;
1698 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
1700 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
1702 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
1703 updateTextType = MODEL_UPDATED;
1706 // Clear the update info. This info will be set the next time the text is updated.
1707 mImpl->mTextUpdateInfo.Clear();
1709 // Not worth to relayout if width or height is equal to zero.
1710 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
1712 return updateTextType;
1715 // Whether a new size has been set.
1716 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
1720 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
1722 // Layout operations that need to be done if the size changes.
1723 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1726 UPDATE_LAYOUT_SIZE |
1728 // Set the update info to relayout the whole text.
1729 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
1730 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
1732 // Store the size used to layout the text.
1733 mImpl->mModel->mVisualModel->mControlSize = size;
1736 // Whether there are modify events.
1737 if( 0u != mImpl->mModifyEvents.Count() )
1739 // Style operations that need to be done if the text is modified.
1740 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1744 // Make sure the model is up-to-date before layouting.
1745 ProcessModifyEvents();
1746 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
1750 updated = DoRelayout( size,
1751 mImpl->mOperationsPending,
1752 layoutSize ) || updated;
1756 updateTextType = MODEL_UPDATED;
1759 // Do not re-do any operation until something changes.
1760 mImpl->mOperationsPending = NO_OPERATION;
1761 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
1763 // Whether the text control is editable
1764 const bool isEditable = NULL != mImpl->mEventData;
1766 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
1768 if( newSize && isEditable )
1770 offset = mImpl->mModel->mScrollPosition;
1773 if( !isEditable || !IsMultiLineEnabled() )
1775 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
1776 CalculateVerticalOffset( size );
1783 // If there is a new size, the scroll position needs to be clamped.
1784 mImpl->ClampHorizontalScroll( layoutSize );
1786 // Update the decorator's positions is needed if there is a new size.
1787 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
1790 // Move the cursor, grab handle etc.
1791 if( mImpl->ProcessInputEvents() )
1793 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
1797 // Clear the update info. This info will be set the next time the text is updated.
1798 mImpl->mTextUpdateInfo.Clear();
1799 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
1801 return updateTextType;
1804 void Controller::RequestRelayout()
1806 mImpl->RequestRelayout();
1809 // public : Input style change signals.
1811 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
1813 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
1816 void Controller::ProcessInputStyleChangedSignals()
1818 if( NULL == mImpl->mEventData )
1824 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
1825 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
1829 const InputStyle::Mask mask = *it;
1831 if( NULL != mImpl->mEditableControlInterface )
1833 // Emit the input style changed signal.
1834 mImpl->mEditableControlInterface->InputStyleChanged( mask );
1838 mImpl->mEventData->mInputStyleChangedQueue.Clear();
1841 // public : Text-input Event Queuing.
1843 void Controller::KeyboardFocusGainEvent()
1845 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
1847 if( NULL != mImpl->mEventData )
1849 if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
1850 ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
1852 mImpl->ChangeState( EventData::EDITING );
1853 mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
1854 mImpl->mEventData->mUpdateInputStyle = true;
1856 mImpl->NotifyImfMultiLineStatus();
1857 if( mImpl->IsShowingPlaceholderText() )
1859 // Show alternative placeholder-text when editing
1860 ShowPlaceholderText();
1863 mImpl->RequestRelayout();
1867 void Controller::KeyboardFocusLostEvent()
1869 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
1871 if( NULL != mImpl->mEventData )
1873 if( EventData::INTERRUPTED != mImpl->mEventData->mState )
1875 mImpl->ChangeState( EventData::INACTIVE );
1877 if( !mImpl->IsShowingRealText() )
1879 // Revert to regular placeholder-text when not editing
1880 ShowPlaceholderText();
1884 mImpl->RequestRelayout();
1887 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
1889 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
1891 bool textChanged = false;
1892 bool relayoutNeeded = false;
1894 if( ( NULL != mImpl->mEventData ) &&
1895 ( keyEvent.state == KeyEvent::Down ) )
1897 int keyCode = keyEvent.keyCode;
1898 const std::string& keyString = keyEvent.keyPressed;
1900 const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
1902 // Pre-process to separate modifying events from non-modifying input events.
1905 // In some platforms arrive key events with no key code.
1908 else if( Dali::DALI_KEY_ESCAPE == keyCode )
1910 // Escape key is a special case which causes focus loss
1911 KeyboardFocusLostEvent();
1913 // Will request for relayout.
1914 relayoutNeeded = true;
1916 else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) ||
1917 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
1918 ( Dali::DALI_KEY_CURSOR_UP == keyCode ) ||
1919 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) )
1921 // If don't have any text, do nothing.
1922 if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
1927 uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition;
1928 uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
1929 uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition );
1930 uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines();
1932 // Logic to determine whether this text control will lose focus or not.
1933 if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition ) ||
1934 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition) ||
1935 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) ||
1936 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) ||
1937 ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) ||
1938 ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) )
1943 mImpl->mEventData->mCheckScrollAmount = true;
1944 Event event( Event::CURSOR_KEY_EVENT );
1945 event.p1.mInt = keyCode;
1946 mImpl->mEventData->mEventQueue.push_back( event );
1948 // Will request for relayout.
1949 relayoutNeeded = true;
1951 else if( Dali::DALI_KEY_BACKSPACE == keyCode )
1953 textChanged = BackspaceKeyEvent();
1955 // Will request for relayout.
1956 relayoutNeeded = true;
1958 else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
1959 IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
1960 IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
1962 // Power key/Menu/Home key behaviour does not allow edit mode to resume.
1963 mImpl->ChangeState( EventData::INACTIVE );
1965 // Will request for relayout.
1966 relayoutNeeded = true;
1968 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
1970 else if( Dali::DALI_KEY_SHIFT_LEFT == keyCode )
1972 // DALI_KEY_SHIFT_LEFT is the key code for the Left Shift. It's sent (by the imf?) when the predictive text is enabled
1973 // and a character is typed after the type of a upper case latin character.
1977 else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
1979 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
1984 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
1986 // IMF manager is no longer handling key-events
1987 mImpl->ClearPreEditFlag();
1989 InsertText( keyString, COMMIT );
1992 // Will request for relayout.
1993 relayoutNeeded = true;
1996 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
1997 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
1999 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
2000 ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
2001 ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
2003 // Should not change the state if the key is the shift send by the imf manager.
2004 // Otherwise, when the state is SELECTING the text controller can't send the right
2005 // surrounding info to the imf.
2006 mImpl->ChangeState( EventData::EDITING );
2008 // Will request for relayout.
2009 relayoutNeeded = true;
2012 if( relayoutNeeded )
2014 mImpl->RequestRelayout();
2019 ( NULL != mImpl->mEditableControlInterface ) )
2021 // Do this last since it provides callbacks into application code
2022 mImpl->mEditableControlInterface->TextChanged();
2028 void Controller::TapEvent( unsigned int tapCount, float x, float y )
2030 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
2032 if( NULL != mImpl->mEventData )
2034 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
2035 EventData::State state( mImpl->mEventData->mState );
2036 bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
2038 if( mImpl->IsClipboardVisible() )
2040 if( EventData::INACTIVE == state || EventData::EDITING == state)
2042 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2044 relayoutNeeded = true;
2046 else if( 1u == tapCount )
2048 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
2050 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
2053 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
2055 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2056 relayoutNeeded = true;
2060 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
2062 // Hide placeholder text
2066 if( EventData::INACTIVE == state )
2068 mImpl->ChangeState( EventData::EDITING );
2070 else if( !mImpl->IsClipboardEmpty() )
2072 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
2074 relayoutNeeded = true;
2077 else if( 2u == tapCount )
2079 if( mImpl->mEventData->mSelectionEnabled &&
2080 mImpl->IsShowingRealText() )
2082 relayoutNeeded = true;
2083 mImpl->mEventData->mIsLeftHandleSelected = true;
2084 mImpl->mEventData->mIsRightHandleSelected = true;
2088 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
2089 if( relayoutNeeded )
2091 Event event( Event::TAP_EVENT );
2092 event.p1.mUint = tapCount;
2093 event.p2.mFloat = x;
2094 event.p3.mFloat = y;
2095 mImpl->mEventData->mEventQueue.push_back( event );
2097 mImpl->RequestRelayout();
2101 // Reset keyboard as tap event has occurred.
2102 mImpl->ResetImfManager();
2105 void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
2107 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
2109 if( NULL != mImpl->mEventData )
2111 Event event( Event::PAN_EVENT );
2112 event.p1.mInt = state;
2113 event.p2.mFloat = displacement.x;
2114 event.p3.mFloat = displacement.y;
2115 mImpl->mEventData->mEventQueue.push_back( event );
2117 mImpl->RequestRelayout();
2121 void Controller::LongPressEvent( Gesture::State state, float x, float y )
2123 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
2125 if( ( state == Gesture::Started ) &&
2126 ( NULL != mImpl->mEventData ) )
2128 // The 1st long-press on inactive text-field is treated as tap
2129 if( EventData::INACTIVE == mImpl->mEventData->mState )
2131 mImpl->ChangeState( EventData::EDITING );
2133 Event event( Event::TAP_EVENT );
2135 event.p2.mFloat = x;
2136 event.p3.mFloat = y;
2137 mImpl->mEventData->mEventQueue.push_back( event );
2139 mImpl->RequestRelayout();
2141 else if( !mImpl->IsShowingRealText() )
2143 Event event( Event::LONG_PRESS_EVENT );
2144 event.p1.mInt = state;
2145 event.p2.mFloat = x;
2146 event.p3.mFloat = y;
2147 mImpl->mEventData->mEventQueue.push_back( event );
2148 mImpl->RequestRelayout();
2150 else if( !mImpl->IsClipboardVisible() )
2152 // Reset the imf manager to commit the pre-edit before selecting the text.
2153 mImpl->ResetImfManager();
2155 Event event( Event::LONG_PRESS_EVENT );
2156 event.p1.mInt = state;
2157 event.p2.mFloat = x;
2158 event.p3.mFloat = y;
2159 mImpl->mEventData->mEventQueue.push_back( event );
2160 mImpl->RequestRelayout();
2162 mImpl->mEventData->mIsLeftHandleSelected = true;
2163 mImpl->mEventData->mIsRightHandleSelected = true;
2168 ImfManager::ImfCallbackData Controller::OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
2170 // Whether the text needs to be relaid-out.
2171 bool requestRelayout = false;
2173 // Whether to retrieve the text and cursor position to be sent to the IMF manager.
2174 bool retrieveText = false;
2175 bool retrieveCursor = false;
2177 switch( imfEvent.eventName )
2179 case ImfManager::COMMIT:
2181 InsertText( imfEvent.predictiveString, Text::Controller::COMMIT );
2182 requestRelayout = true;
2183 retrieveCursor = true;
2186 case ImfManager::PREEDIT:
2188 InsertText( imfEvent.predictiveString, Text::Controller::PRE_EDIT );
2189 requestRelayout = true;
2190 retrieveCursor = true;
2193 case ImfManager::DELETESURROUNDING:
2195 const bool textDeleted = RemoveText( imfEvent.cursorOffset,
2196 imfEvent.numberOfChars,
2197 DONT_UPDATE_INPUT_STYLE );
2201 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2202 !mImpl->IsPlaceholderAvailable() )
2204 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2208 ShowPlaceholderText();
2210 mImpl->mEventData->mUpdateCursorPosition = true;
2211 mImpl->mEventData->mScrollAfterDelete = true;
2213 requestRelayout = true;
2217 case ImfManager::GETSURROUNDING:
2219 retrieveText = true;
2220 retrieveCursor = true;
2223 case ImfManager::PRIVATECOMMAND:
2225 // PRIVATECOMMAND event is just for getting the private command message
2226 retrieveText = true;
2227 retrieveCursor = true;
2230 case ImfManager::VOID:
2237 if( requestRelayout )
2239 mImpl->mOperationsPending = ALL_OPERATIONS;
2240 mImpl->RequestRelayout();
2244 CharacterIndex cursorPosition = 0u;
2245 Length numberOfWhiteSpaces = 0u;
2247 if( retrieveCursor )
2249 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
2251 cursorPosition = mImpl->GetLogicalCursorPosition();
2253 if( cursorPosition < numberOfWhiteSpaces )
2255 cursorPosition = 0u;
2259 cursorPosition -= numberOfWhiteSpaces;
2265 mImpl->GetText( numberOfWhiteSpaces, text );
2268 ImfManager::ImfCallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
2270 if( requestRelayout &&
2271 ( NULL != mImpl->mEditableControlInterface ) )
2273 // Do this last since it provides callbacks into application code
2274 mImpl->mEditableControlInterface->TextChanged();
2277 return callbackData;
2280 void Controller::PasteClipboardItemEvent()
2282 // Retrieve the clipboard contents first
2283 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
2284 std::string stringToPaste( notifier.GetContent() );
2286 // Commit the current pre-edit text; the contents of the clipboard should be appended
2287 mImpl->ResetImfManager();
2289 // Temporary disable hiding clipboard
2290 mImpl->SetClipboardHideEnable( false );
2293 PasteText( stringToPaste );
2295 mImpl->SetClipboardHideEnable( true );
2298 // protected : Inherit from Text::Decorator::ControllerInterface.
2300 void Controller::GetTargetSize( Vector2& targetSize )
2302 targetSize = mImpl->mModel->mVisualModel->mControlSize;
2305 void Controller::AddDecoration( Actor& actor, bool needsClipping )
2307 if( NULL != mImpl->mEditableControlInterface )
2309 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
2313 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
2315 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
2317 if( NULL != mImpl->mEventData )
2319 switch( handleType )
2323 Event event( Event::GRAB_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 LEFT_SELECTION_HANDLE:
2333 Event event( Event::LEFT_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 RIGHT_SELECTION_HANDLE:
2343 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
2344 event.p1.mUint = state;
2345 event.p2.mFloat = x;
2346 event.p3.mFloat = y;
2348 mImpl->mEventData->mEventQueue.push_back( event );
2351 case LEFT_SELECTION_HANDLE_MARKER:
2352 case RIGHT_SELECTION_HANDLE_MARKER:
2354 // Markers do not move the handles.
2357 case HANDLE_TYPE_COUNT:
2359 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
2363 mImpl->RequestRelayout();
2367 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
2369 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
2371 if( NULL == mImpl->mEventData )
2378 case Toolkit::TextSelectionPopup::CUT:
2380 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
2381 mImpl->mOperationsPending = ALL_OPERATIONS;
2383 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2384 !mImpl->IsPlaceholderAvailable() )
2386 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2390 ShowPlaceholderText();
2393 mImpl->mEventData->mUpdateCursorPosition = true;
2394 mImpl->mEventData->mScrollAfterDelete = true;
2396 mImpl->RequestRelayout();
2398 if( NULL != mImpl->mEditableControlInterface )
2400 mImpl->mEditableControlInterface->TextChanged();
2404 case Toolkit::TextSelectionPopup::COPY:
2406 mImpl->SendSelectionToClipboard( false ); // Text not modified
2408 mImpl->mEventData->mUpdateCursorPosition = true;
2410 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
2413 case Toolkit::TextSelectionPopup::PASTE:
2415 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
2418 case Toolkit::TextSelectionPopup::SELECT:
2420 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
2422 if( mImpl->mEventData->mSelectionEnabled )
2424 // Creates a SELECT event.
2425 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
2429 case Toolkit::TextSelectionPopup::SELECT_ALL:
2431 // Creates a SELECT_ALL event
2432 SelectEvent( 0.f, 0.f, true );
2435 case Toolkit::TextSelectionPopup::CLIPBOARD:
2437 mImpl->ShowClipboard();
2440 case Toolkit::TextSelectionPopup::NONE:
2448 void Controller::DisplayTimeExpired()
2450 mImpl->mEventData->mUpdateCursorPosition = true;
2451 // Apply modifications to the model
2452 mImpl->mOperationsPending = ALL_OPERATIONS;
2454 mImpl->RequestRelayout();
2457 // private : Update.
2459 void Controller::InsertText( const std::string& text, Controller::InsertType type )
2461 bool removedPrevious = false;
2462 bool removedSelected = false;
2463 bool maxLengthReached = false;
2465 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
2467 if( NULL == mImpl->mEventData )
2472 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
2473 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
2474 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
2476 // TODO: At the moment the underline runs are only for pre-edit.
2477 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
2479 // Remove the previous IMF pre-edit.
2480 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
2482 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
2483 mImpl->mEventData->mPreEditLength,
2484 DONT_UPDATE_INPUT_STYLE );
2486 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
2487 mImpl->mEventData->mPreEditLength = 0u;
2491 // Remove the previous Selection.
2492 removedSelected = RemoveSelectedText();
2496 Vector<Character> utf32Characters;
2497 Length characterCount = 0u;
2501 // Convert text into UTF-32
2502 utf32Characters.Resize( text.size() );
2504 // This is a bit horrible but std::string returns a (signed) char*
2505 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
2507 // Transform a text array encoded in utf8 into an array encoded in utf32.
2508 // It returns the actual number of characters.
2509 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
2510 utf32Characters.Resize( characterCount );
2512 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
2513 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
2516 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
2518 // The placeholder text is no longer needed
2519 if( mImpl->IsShowingPlaceholderText() )
2524 mImpl->ChangeState( EventData::EDITING );
2526 // Handle the IMF (predicitive text) state changes
2527 if( COMMIT == type )
2529 // IMF manager is no longer handling key-events
2530 mImpl->ClearPreEditFlag();
2534 if( !mImpl->mEventData->mPreEditFlag )
2536 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
2538 // Record the start of the pre-edit text
2539 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
2542 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
2543 mImpl->mEventData->mPreEditFlag = true;
2545 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
2548 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
2550 // Restrict new text to fit within Maximum characters setting.
2551 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
2552 maxLengthReached = ( characterCount > maxSizeOfNewText );
2554 // The cursor position.
2555 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
2557 // Update the text's style.
2559 // Updates the text style runs by adding characters.
2560 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
2562 // Get the character index from the cursor index.
2563 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
2565 // Retrieve the text's style for the given index.
2567 mImpl->RetrieveDefaultInputStyle( style );
2568 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
2570 // Whether to add a new text color run.
2571 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor );
2573 // Whether to add a new font run.
2574 const bool addFontNameRun = style.familyName != mImpl->mEventData->mInputStyle.familyName;
2575 const bool addFontWeightRun = style.weight != mImpl->mEventData->mInputStyle.weight;
2576 const bool addFontWidthRun = style.width != mImpl->mEventData->mInputStyle.width;
2577 const bool addFontSlantRun = style.slant != mImpl->mEventData->mInputStyle.slant;
2578 const bool addFontSizeRun = style.size != mImpl->mEventData->mInputStyle.size;
2583 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
2584 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
2586 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
2587 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
2588 colorRun.characterRun.characterIndex = cursorIndex;
2589 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
2592 if( addFontNameRun ||
2598 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
2599 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
2601 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
2603 if( addFontNameRun )
2605 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
2606 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
2607 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
2608 fontDescriptionRun.familyDefined = true;
2610 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
2613 if( addFontWeightRun )
2615 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
2616 fontDescriptionRun.weightDefined = true;
2619 if( addFontWidthRun )
2621 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
2622 fontDescriptionRun.widthDefined = true;
2625 if( addFontSlantRun )
2627 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
2628 fontDescriptionRun.slantDefined = true;
2631 if( addFontSizeRun )
2633 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
2634 fontDescriptionRun.sizeDefined = true;
2637 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
2638 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
2641 // Insert at current cursor position.
2642 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
2644 if( cursorIndex < numberOfCharactersInModel )
2646 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
2650 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
2653 // Mark the first paragraph to be updated.
2654 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
2655 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
2657 // Update the cursor index.
2658 cursorIndex += maxSizeOfNewText;
2660 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 );
2663 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
2664 mImpl->IsPlaceholderAvailable() )
2666 // Show place-holder if empty after removing the pre-edit text
2667 ShowPlaceholderText();
2668 mImpl->mEventData->mUpdateCursorPosition = true;
2669 mImpl->ClearPreEditFlag();
2671 else if( removedPrevious ||
2673 ( 0 != utf32Characters.Count() ) )
2675 // Queue an inserted event
2676 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
2678 mImpl->mEventData->mUpdateCursorPosition = true;
2679 if( removedSelected )
2681 mImpl->mEventData->mScrollAfterDelete = true;
2685 mImpl->mEventData->mScrollAfterUpdatePosition = true;
2689 if( maxLengthReached )
2691 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
2693 mImpl->ResetImfManager();
2695 if( NULL != mImpl->mEditableControlInterface )
2697 // Do this last since it provides callbacks into application code
2698 mImpl->mEditableControlInterface->MaxLengthReached();
2703 void Controller::PasteText( const std::string& stringToPaste )
2705 InsertText( stringToPaste, Text::Controller::COMMIT );
2706 mImpl->ChangeState( EventData::EDITING );
2707 mImpl->RequestRelayout();
2709 if( NULL != mImpl->mEditableControlInterface )
2711 // Do this last since it provides callbacks into application code
2712 mImpl->mEditableControlInterface->TextChanged();
2716 bool Controller::RemoveText( int cursorOffset,
2717 int numberOfCharacters,
2718 UpdateInputStyleType type )
2720 bool removed = false;
2722 if( NULL == mImpl->mEventData )
2727 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
2728 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
2730 if( !mImpl->IsShowingPlaceholderText() )
2732 // Delete at current cursor position
2733 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
2734 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
2736 CharacterIndex cursorIndex = 0;
2738 // Validate the cursor position & number of characters
2739 if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
2741 cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
2744 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
2746 numberOfCharacters = currentText.Count() - cursorIndex;
2749 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.
2750 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
2752 // Mark the paragraphs to be updated.
2753 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
2754 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
2756 // Update the input style and remove the text's style before removing the text.
2758 if( UPDATE_INPUT_STYLE == type )
2760 // Keep a copy of the current input style.
2761 InputStyle currentInputStyle;
2762 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
2764 // Set first the default input style.
2765 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
2767 // Update the input style.
2768 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
2770 // Compare if the input style has changed.
2771 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
2773 if( hasInputStyleChanged )
2775 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
2776 // Queue the input style changed signal.
2777 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
2781 // Updates the text style runs by removing characters. Runs with no characters are removed.
2782 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
2784 // Remove the characters.
2785 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
2786 Vector<Character>::Iterator last = first + numberOfCharacters;
2788 currentText.Erase( first, last );
2790 // Cursor position retreat
2791 oldCursorIndex = cursorIndex;
2793 mImpl->mEventData->mScrollAfterDelete = true;
2795 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
2803 bool Controller::RemoveSelectedText()
2805 bool textRemoved( false );
2807 if( EventData::SELECTING == mImpl->mEventData->mState )
2809 std::string removedString;
2810 mImpl->RetrieveSelection( removedString, true );
2812 if( !removedString.empty() )
2815 mImpl->ChangeState( EventData::EDITING );
2822 // private : Relayout.
2824 bool Controller::DoRelayout( const Size& size,
2825 OperationsMask operationsRequired,
2828 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
2829 bool viewUpdated( false );
2831 // Calculate the operations to be done.
2832 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
2834 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
2835 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
2837 // Get the current layout size.
2838 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
2840 if( NO_OPERATION != ( LAYOUT & operations ) )
2842 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
2844 // Some vectors with data needed to layout and reorder may be void
2845 // after the first time the text has been laid out.
2846 // Fill the vectors again.
2848 // Calculate the number of glyphs to layout.
2849 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
2850 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
2851 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
2852 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
2854 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
2855 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
2856 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
2857 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
2859 if( 0u == totalNumberOfGlyphs )
2861 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
2863 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
2866 // Nothing else to do if there is no glyphs.
2867 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
2871 const Vector<LineBreakInfo>& lineBreakInfo = mImpl->mModel->mLogicalModel->mLineBreakInfo;
2872 const Vector<WordBreakInfo>& wordBreakInfo = mImpl->mModel->mLogicalModel->mWordBreakInfo;
2873 const Vector<CharacterDirection>& characterDirection = mImpl->mModel->mLogicalModel->mCharacterDirections;
2874 const Vector<GlyphInfo>& glyphs = mImpl->mModel->mVisualModel->mGlyphs;
2875 const Vector<CharacterIndex>& glyphsToCharactersMap = mImpl->mModel->mVisualModel->mGlyphsToCharacters;
2876 const Vector<Length>& charactersPerGlyph = mImpl->mModel->mVisualModel->mCharactersPerGlyph;
2877 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
2879 // Set the layout parameters.
2880 Layout::Parameters layoutParameters( size,
2882 lineBreakInfo.Begin(),
2883 wordBreakInfo.Begin(),
2884 ( 0u != characterDirection.Count() ) ? characterDirection.Begin() : NULL,
2886 glyphsToCharactersMap.Begin(),
2887 charactersPerGlyph.Begin(),
2888 charactersToGlyphBuffer,
2889 glyphsPerCharacterBuffer,
2890 totalNumberOfGlyphs,
2891 mImpl->mModel->mHorizontalAlignment );
2893 // Resize the vector of positions to have the same size than the vector of glyphs.
2894 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
2895 glyphPositions.Resize( totalNumberOfGlyphs );
2897 // Whether the last character is a new paragraph character.
2898 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
2899 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
2901 // The initial glyph and the number of glyphs to layout.
2902 layoutParameters.startGlyphIndex = startGlyphIndex;
2903 layoutParameters.numberOfGlyphs = numberOfGlyphs;
2904 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
2905 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
2907 // Update the visual model.
2909 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
2911 mImpl->mModel->mVisualModel->mLines,
2913 mImpl->mModel->mElideEnabled );
2915 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
2919 layoutSize = newLayoutSize;
2921 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
2923 mImpl->mAutoScrollDirectionRTL = false;
2926 // Reorder the lines
2927 if( NO_OPERATION != ( REORDER & operations ) )
2929 Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = mImpl->mModel->mLogicalModel->mBidirectionalParagraphInfo;
2930 Vector<BidirectionalLineInfoRun>& bidirectionalLineInfo = mImpl->mModel->mLogicalModel->mBidirectionalLineInfo;
2932 // Check first if there are paragraphs with bidirectional info.
2933 if( 0u != bidirectionalInfo.Count() )
2936 const Length numberOfLines = mImpl->mModel->mVisualModel->mLines.Count();
2938 // Reorder the lines.
2939 bidirectionalLineInfo.Reserve( numberOfLines ); // Reserve because is not known yet how many lines have right to left characters.
2940 ReorderLines( bidirectionalInfo,
2942 requestedNumberOfCharacters,
2943 mImpl->mModel->mVisualModel->mLines,
2944 bidirectionalLineInfo );
2946 // Set the bidirectional info per line into the layout parameters.
2947 layoutParameters.lineBidirectionalInfoRunsBuffer = bidirectionalLineInfo.Begin();
2948 layoutParameters.numberOfBidirectionalInfoRuns = bidirectionalLineInfo.Count();
2950 // Re-layout the text. Reorder those lines with right to left characters.
2951 mImpl->mLayoutEngine.ReLayoutRightToLeftLines( layoutParameters,
2953 requestedNumberOfCharacters,
2956 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && ( numberOfLines > 0 ) )
2958 const LineRun* const firstline = mImpl->mModel->mVisualModel->mLines.Begin();
2961 mImpl->mAutoScrollDirectionRTL = firstline->direction;
2967 // Sets the layout size.
2968 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
2970 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
2975 if( NO_OPERATION != ( ALIGN & operations ) )
2977 // The laid-out lines.
2978 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
2980 // Need to align with the control's size as the text may contain lines
2981 // starting either with left to right text or right to left.
2982 mImpl->mLayoutEngine.Align( size,
2984 requestedNumberOfCharacters,
2985 mImpl->mModel->mHorizontalAlignment,
2987 mImpl->mModel->mAlignmentOffset );
2991 #if defined(DEBUG_ENABLED)
2992 std::string currentText;
2993 GetText( currentText );
2994 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mAutoScrollDirectionRTL[%s] [%s]\n", this, (mImpl->mAutoScrollDirectionRTL)?"true":"false", currentText.c_str() );
2996 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
3000 void Controller::CalculateVerticalOffset( const Size& controlSize )
3002 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3004 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
3006 // Get the line height of the default font.
3007 layoutSize.height = mImpl->GetDefaultFontLineHeight();
3010 switch( mImpl->mModel->mVerticalAlignment )
3012 case Layout::VERTICAL_ALIGN_TOP:
3014 mImpl->mModel->mScrollPosition.y = 0.f;
3017 case Layout::VERTICAL_ALIGN_CENTER:
3019 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
3022 case Layout::VERTICAL_ALIGN_BOTTOM:
3024 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
3030 // private : Events.
3032 void Controller::ProcessModifyEvents()
3034 Vector<ModifyEvent>& events = mImpl->mModifyEvents;
3036 if( 0u == events.Count() )
3042 for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
3043 endIt = events.End();
3047 const ModifyEvent& event = *it;
3049 if( ModifyEvent::TEXT_REPLACED == event.type )
3051 // A (single) replace event should come first, otherwise we wasted time processing NOOP events
3052 DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
3054 TextReplacedEvent();
3056 else if( ModifyEvent::TEXT_INSERTED == event.type )
3058 TextInsertedEvent();
3060 else if( ModifyEvent::TEXT_DELETED == event.type )
3062 // Placeholder-text cannot be deleted
3063 if( !mImpl->IsShowingPlaceholderText() )
3070 if( NULL != mImpl->mEventData )
3072 // When the text is being modified, delay cursor blinking
3073 mImpl->mEventData->mDecorator->DelayCursorBlink();
3076 // Discard temporary text
3080 void Controller::TextReplacedEvent()
3082 // The natural size needs to be re-calculated.
3083 mImpl->mRecalculateNaturalSize = true;
3085 // Apply modifications to the model
3086 mImpl->mOperationsPending = ALL_OPERATIONS;
3089 void Controller::TextInsertedEvent()
3091 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
3093 if( NULL == mImpl->mEventData )
3098 mImpl->mEventData->mCheckScrollAmount = true;
3100 // The natural size needs to be re-calculated.
3101 mImpl->mRecalculateNaturalSize = true;
3103 // Apply modifications to the model; TODO - Optimize this
3104 mImpl->mOperationsPending = ALL_OPERATIONS;
3107 void Controller::TextDeletedEvent()
3109 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
3111 if( NULL == mImpl->mEventData )
3116 mImpl->mEventData->mCheckScrollAmount = true;
3118 // The natural size needs to be re-calculated.
3119 mImpl->mRecalculateNaturalSize = true;
3121 // Apply modifications to the model; TODO - Optimize this
3122 mImpl->mOperationsPending = ALL_OPERATIONS;
3125 void Controller::SelectEvent( float x, float y, bool selectAll )
3127 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
3129 if( NULL != mImpl->mEventData )
3133 Event event( Event::SELECT_ALL );
3134 mImpl->mEventData->mEventQueue.push_back( event );
3138 Event event( Event::SELECT );
3139 event.p2.mFloat = x;
3140 event.p3.mFloat = y;
3141 mImpl->mEventData->mEventQueue.push_back( event );
3144 mImpl->mEventData->mCheckScrollAmount = true;
3145 mImpl->mEventData->mIsLeftHandleSelected = true;
3146 mImpl->mEventData->mIsRightHandleSelected = true;
3147 mImpl->RequestRelayout();
3151 bool Controller::BackspaceKeyEvent()
3153 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p DALI_KEY_BACKSPACE\n", this );
3155 bool removed = false;
3157 if( NULL == mImpl->mEventData )
3162 // IMF manager is no longer handling key-events
3163 mImpl->ClearPreEditFlag();
3165 if( EventData::SELECTING == mImpl->mEventData->mState )
3167 removed = RemoveSelectedText();
3169 else if( mImpl->mEventData->mPrimaryCursorPosition > 0 )
3171 // Remove the character before the current cursor position
3172 removed = RemoveText( -1,
3174 UPDATE_INPUT_STYLE );
3179 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3180 !mImpl->IsPlaceholderAvailable() )
3182 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3186 ShowPlaceholderText();
3188 mImpl->mEventData->mUpdateCursorPosition = true;
3189 mImpl->mEventData->mScrollAfterDelete = true;
3195 // private : Helpers.
3197 void Controller::ResetText()
3200 mImpl->mModel->mLogicalModel->mText.Clear();
3202 // We have cleared everything including the placeholder-text
3203 mImpl->PlaceholderCleared();
3205 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3206 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3207 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
3209 // Clear any previous text.
3210 mImpl->mTextUpdateInfo.mClearAll = true;
3212 // The natural size needs to be re-calculated.
3213 mImpl->mRecalculateNaturalSize = true;
3215 // Apply modifications to the model
3216 mImpl->mOperationsPending = ALL_OPERATIONS;
3219 void Controller::ShowPlaceholderText()
3221 if( mImpl->IsPlaceholderAvailable() )
3223 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
3225 if( NULL == mImpl->mEventData )
3230 mImpl->mEventData->mIsShowingPlaceholderText = true;
3232 // Disable handles when showing place-holder text
3233 mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
3234 mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
3235 mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
3237 const char* text( NULL );
3240 if( !mImpl->mEventData->mPlaceholderTextActive.empty() || !mImpl->mEventData->mPlaceholderTextInactive.empty() )
3242 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
3243 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
3245 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
3246 size = mImpl->mEventData->mPlaceholderTextActive.size();
3250 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
3251 size = mImpl->mEventData->mPlaceholderTextInactive.size();
3256 if( 0u != mImpl->mEventData->mPlaceholderText.c_str() )
3258 text = mImpl->mEventData->mPlaceholderText.c_str();
3259 size = mImpl->mEventData->mPlaceholderText.size();
3263 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3264 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3266 // Reset model for showing placeholder.
3267 mImpl->mModel->mLogicalModel->mText.Clear();
3268 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
3270 // Convert text into UTF-32
3271 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
3272 utf32Characters.Resize( size );
3274 // This is a bit horrible but std::string returns a (signed) char*
3275 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
3277 // Transform a text array encoded in utf8 into an array encoded in utf32.
3278 // It returns the actual number of characters.
3279 const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
3280 utf32Characters.Resize( characterCount );
3282 // The characters to be added.
3283 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
3285 // Reset the cursor position
3286 mImpl->mEventData->mPrimaryCursorPosition = 0;
3288 // The natural size needs to be re-calculated.
3289 mImpl->mRecalculateNaturalSize = true;
3291 // Apply modifications to the model
3292 mImpl->mOperationsPending = ALL_OPERATIONS;
3294 // Update the rest of the model during size negotiation
3295 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
3299 void Controller::ClearFontData()
3301 if( mImpl->mFontDefaults )
3303 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
3306 // Set flags to update the model.
3307 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3308 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3309 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
3311 mImpl->mTextUpdateInfo.mClearAll = true;
3312 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
3313 mImpl->mRecalculateNaturalSize = true;
3315 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
3320 UPDATE_LAYOUT_SIZE |
3325 void Controller::ClearStyleData()
3327 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
3328 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
3331 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
3333 // Reset the cursor position
3334 if( NULL != mImpl->mEventData )
3336 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
3338 // Update the cursor if it's in editing mode.
3339 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
3341 mImpl->mEventData->mUpdateCursorPosition = true;
3346 void Controller::ResetScrollPosition()
3348 if( NULL != mImpl->mEventData )
3350 // Reset the scroll position.
3351 mImpl->mModel->mScrollPosition = Vector2::ZERO;
3352 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3356 // private : Private contructors & copy operator.
3358 Controller::Controller()
3361 mImpl = new Controller::Impl( NULL, NULL );
3364 Controller::Controller( ControlInterface* controlInterface )
3366 mImpl = new Controller::Impl( controlInterface, NULL );
3369 Controller::Controller( ControlInterface* controlInterface,
3370 EditableControlInterface* editableControlInterface )
3372 mImpl = new Controller::Impl( controlInterface,
3373 editableControlInterface );
3376 // The copy constructor and operator are left unimplemented.
3378 // protected : Destructor.
3380 Controller::~Controller()
3387 } // namespace Toolkit