2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/text/text-controller.h>
24 #include <dali/public-api/adaptor-framework/key.h>
25 #include <dali/integration-api/debug.h>
26 #include <dali/devel-api/adaptor-framework/clipboard-event-notifier.h>
27 #include <dali/devel-api/text-abstraction/font-client.h>
30 #include <dali-toolkit/internal/text/bidirectional-support.h>
31 #include <dali-toolkit/internal/text/character-set-conversion.h>
32 #include <dali-toolkit/internal/text/layouts/layout-parameters.h>
33 #include <dali-toolkit/internal/text/markup-processor.h>
34 #include <dali-toolkit/internal/text/text-controller-impl.h>
35 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
40 #if defined(DEBUG_ENABLED)
41 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
44 const float MAX_FLOAT = std::numeric_limits<float>::max();
46 const std::string EMPTY_STRING("");
48 float ConvertToEven( float value )
50 int intValue(static_cast<int>( value ));
51 return static_cast<float>(intValue % 2 == 0) ? intValue : (intValue + 1);
66 * @brief Adds a new font description run for the selected text.
68 * The new font parameters are added after the call to this method.
70 * @param[in] eventData The event data pointer.
71 * @param[in] logicalModel The logical model where to add the new font description run.
72 * @param[out] startOfSelectedText Index to the first selected character.
73 * @param[out] lengthOfSelectedText Number of selected characters.
75 FontDescriptionRun& UpdateSelectionFontStyleRun( EventData* eventData,
76 LogicalModelPtr logicalModel,
77 CharacterIndex& startOfSelectedText,
78 Length& lengthOfSelectedText )
80 const bool handlesCrossed = eventData->mLeftSelectionPosition > eventData->mRightSelectionPosition;
82 // Get start and end position of selection
83 startOfSelectedText = handlesCrossed ? eventData->mRightSelectionPosition : eventData->mLeftSelectionPosition;
84 lengthOfSelectedText = ( handlesCrossed ? eventData->mLeftSelectionPosition : eventData->mRightSelectionPosition ) - startOfSelectedText;
87 const VectorBase::SizeType numberOfRuns = logicalModel->mFontDescriptionRuns.Count();
88 logicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
90 FontDescriptionRun& fontDescriptionRun = *( logicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
92 fontDescriptionRun.characterRun.characterIndex = startOfSelectedText;
93 fontDescriptionRun.characterRun.numberOfCharacters = lengthOfSelectedText;
95 // Recalculate the selection highlight as the metrics may have changed.
96 eventData->mUpdateLeftSelectionPosition = true;
97 eventData->mUpdateRightSelectionPosition = true;
98 eventData->mUpdateHighlightBox = true;
100 return fontDescriptionRun;
103 // public : Constructor.
105 ControllerPtr Controller::New()
107 return ControllerPtr( new Controller() );
110 ControllerPtr Controller::New( ControlInterface* controlInterface )
112 return ControllerPtr( new Controller( controlInterface ) );
115 ControllerPtr Controller::New( ControlInterface* controlInterface,
116 EditableControlInterface* editableControlInterface )
118 return ControllerPtr( new Controller( controlInterface,
119 editableControlInterface ) );
122 // public : Configure the text controller.
124 void Controller::EnableTextInput( DecoratorPtr decorator )
128 delete mImpl->mEventData;
129 mImpl->mEventData = NULL;
131 // Nothing else to do.
135 if( NULL == mImpl->mEventData )
137 mImpl->mEventData = new EventData( decorator );
141 void Controller::SetGlyphType( TextAbstraction::GlyphType glyphType )
143 // Metrics for bitmap & vector based glyphs are different
144 mImpl->mMetrics->SetGlyphType( glyphType );
146 // Clear the font-specific data
149 mImpl->RequestRelayout();
152 void Controller::SetMarkupProcessorEnabled( bool enable )
154 mImpl->mMarkupProcessorEnabled = enable;
157 bool Controller::IsMarkupProcessorEnabled() const
159 return mImpl->mMarkupProcessorEnabled;
162 void Controller::SetAutoScrollEnabled( bool enable )
164 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled[%s] SingleBox[%s]-> [%p]\n", (enable)?"true":"false", ( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX)?"true":"false", this );
166 if( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX )
170 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled for SINGLE_LINE_BOX\n" );
171 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
181 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled Disabling autoscroll\n");
182 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
189 mImpl->mIsAutoScrollEnabled = enable;
190 mImpl->RequestRelayout();
194 DALI_LOG_WARNING( "Attempted AutoScrolling on a non SINGLE_LINE_BOX, request ignored\n" );
195 mImpl->mIsAutoScrollEnabled = false;
199 bool Controller::IsAutoScrollEnabled() const
201 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::IsAutoScrollEnabled[%s]\n", mImpl->mIsAutoScrollEnabled?"true":"false" );
203 return mImpl->mIsAutoScrollEnabled;
206 CharacterDirection Controller::GetAutoScrollDirection() const
208 return mImpl->mAutoScrollDirectionRTL;
211 float Controller::GetAutoScrollLineAlignment() const
215 if( mImpl->mModel->mVisualModel &&
216 ( 0u != mImpl->mModel->mVisualModel->mLines.Count() ) )
218 offset = ( *mImpl->mModel->mVisualModel->mLines.Begin() ).alignmentOffset;
224 void Controller::SetHorizontalScrollEnabled( bool enable )
226 if( ( NULL != mImpl->mEventData ) &&
227 mImpl->mEventData->mDecorator )
229 mImpl->mEventData->mDecorator->SetHorizontalScrollEnabled( enable );
232 bool Controller::IsHorizontalScrollEnabled() const
234 if( ( NULL != mImpl->mEventData ) &&
235 mImpl->mEventData->mDecorator )
237 return mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
243 void Controller::SetVerticalScrollEnabled( bool enable )
245 if( ( NULL != mImpl->mEventData ) &&
246 mImpl->mEventData->mDecorator )
248 if( mImpl->mEventData->mDecorator )
250 mImpl->mEventData->mDecorator->SetVerticalScrollEnabled( enable );
255 bool Controller::IsVerticalScrollEnabled() const
257 if( ( NULL != mImpl->mEventData ) &&
258 mImpl->mEventData->mDecorator )
260 return mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
266 void Controller::SetSmoothHandlePanEnabled( bool enable )
268 if( ( NULL != mImpl->mEventData ) &&
269 mImpl->mEventData->mDecorator )
271 mImpl->mEventData->mDecorator->SetSmoothHandlePanEnabled( enable );
275 bool Controller::IsSmoothHandlePanEnabled() const
277 if( ( NULL != mImpl->mEventData ) &&
278 mImpl->mEventData->mDecorator )
280 return mImpl->mEventData->mDecorator->IsSmoothHandlePanEnabled();
286 void Controller::SetMaximumNumberOfCharacters( Length maxCharacters )
288 mImpl->mMaximumNumberOfCharacters = maxCharacters;
291 int Controller::GetMaximumNumberOfCharacters()
293 return mImpl->mMaximumNumberOfCharacters;
296 void Controller::SetEnableCursorBlink( bool enable )
298 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "TextInput disabled" );
300 if( NULL != mImpl->mEventData )
302 mImpl->mEventData->mCursorBlinkEnabled = enable;
305 mImpl->mEventData->mDecorator )
307 mImpl->mEventData->mDecorator->StopCursorBlink();
312 bool Controller::GetEnableCursorBlink() const
314 if( NULL != mImpl->mEventData )
316 return mImpl->mEventData->mCursorBlinkEnabled;
322 void Controller::SetMultiLineEnabled( bool enable )
324 const Layout::Engine::Type layout = enable ? Layout::Engine::MULTI_LINE_BOX : Layout::Engine::SINGLE_LINE_BOX;
326 if( layout != mImpl->mLayoutEngine.GetLayout() )
328 // Set the layout type.
329 mImpl->mLayoutEngine.SetLayout( layout );
331 // Set the flags to redo the layout operations
332 const OperationsMask layoutOperations = static_cast<OperationsMask>( LAYOUT |
337 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | layoutOperations );
339 mImpl->RequestRelayout();
343 bool Controller::IsMultiLineEnabled() const
345 return Layout::Engine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
348 void Controller::SetHorizontalAlignment( Layout::HorizontalAlignment alignment )
350 if( alignment != mImpl->mModel->mHorizontalAlignment )
352 // Set the alignment.
353 mImpl->mModel->mHorizontalAlignment = alignment;
355 // Set the flag to redo the alignment operation.
356 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
358 mImpl->RequestRelayout();
362 Layout::HorizontalAlignment Controller::GetHorizontalAlignment() const
364 return mImpl->mModel->mHorizontalAlignment;
367 void Controller::SetVerticalAlignment( Layout::VerticalAlignment alignment )
369 if( alignment != mImpl->mModel->mVerticalAlignment )
371 // Set the alignment.
372 mImpl->mModel->mVerticalAlignment = alignment;
374 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
376 mImpl->RequestRelayout();
380 Layout::VerticalAlignment Controller::GetVerticalAlignment() const
382 return mImpl->mModel->mVerticalAlignment;
385 void Controller::SetTextElideEnabled( bool enabled )
387 mImpl->mModel->mElideEnabled = enabled;
390 bool Controller::IsTextElideEnabled() const
392 return mImpl->mModel->mElideEnabled;
397 void Controller::SetText( const std::string& text )
399 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" );
401 // Reset keyboard as text changed
402 mImpl->ResetImfManager();
404 // Remove the previously set text and style.
410 CharacterIndex lastCursorIndex = 0u;
412 if( NULL != mImpl->mEventData )
414 // If popup shown then hide it by switching to Editing state
415 if( ( EventData::SELECTING == mImpl->mEventData->mState ) ||
416 ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
417 ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) ||
418 ( EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState ) )
420 mImpl->ChangeState( EventData::EDITING );
426 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mTextColor );
428 MarkupProcessData markupProcessData( mImpl->mModel->mLogicalModel->mColorRuns,
429 mImpl->mModel->mLogicalModel->mFontDescriptionRuns );
431 Length textSize = 0u;
432 const uint8_t* utf8 = NULL;
433 if( mImpl->mMarkupProcessorEnabled )
435 ProcessMarkupString( text, markupProcessData );
436 textSize = markupProcessData.markupProcessedText.size();
438 // This is a bit horrible but std::string returns a (signed) char*
439 utf8 = reinterpret_cast<const uint8_t*>( markupProcessData.markupProcessedText.c_str() );
443 textSize = text.size();
445 // This is a bit horrible but std::string returns a (signed) char*
446 utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
449 // Convert text into UTF-32
450 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
451 utf32Characters.Resize( textSize );
453 // Transform a text array encoded in utf8 into an array encoded in utf32.
454 // It returns the actual number of characters.
455 Length characterCount = Utf8ToUtf32( utf8, textSize, utf32Characters.Begin() );
456 utf32Characters.Resize( characterCount );
458 DALI_ASSERT_DEBUG( textSize >= characterCount && "Invalid UTF32 conversion length" );
459 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", this, textSize, mImpl->mModel->mLogicalModel->mText.Count() );
461 // The characters to be added.
462 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
464 // To reset the cursor position
465 lastCursorIndex = characterCount;
467 // Update the rest of the model during size negotiation
468 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
470 // The natural size needs to be re-calculated.
471 mImpl->mRecalculateNaturalSize = true;
473 // Apply modifications to the model
474 mImpl->mOperationsPending = ALL_OPERATIONS;
478 ShowPlaceholderText();
481 // Resets the cursor position.
482 ResetCursorPosition( lastCursorIndex );
484 // Scrolls the text to make the cursor visible.
485 ResetScrollPosition();
487 mImpl->RequestRelayout();
489 if( NULL != mImpl->mEventData )
491 // Cancel previously queued events
492 mImpl->mEventData->mEventQueue.clear();
495 // Do this last since it provides callbacks into application code.
496 if( NULL != mImpl->mEditableControlInterface )
498 mImpl->mEditableControlInterface->TextChanged();
502 void Controller::GetText( std::string& text ) const
504 if( !mImpl->IsShowingPlaceholderText() )
506 // Retrieves the text string.
507 mImpl->GetText( 0u, text );
511 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this );
515 void Controller::SetPlaceholderText( const std::string& text )
517 if( NULL != mImpl->mEventData )
519 mImpl->mEventData->mPlaceholderText = text;
521 // Update placeholder if there is no text
522 if( mImpl->IsShowingPlaceholderText() ||
523 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
525 ShowPlaceholderText();
530 // This is overloading function for PLACEHOLDER_TEXT_FOCUSED in text-field
531 void Controller::SetPlaceholderText( PlaceholderType type, const std::string& text )
533 if( NULL != mImpl->mEventData )
535 if( PLACEHOLDER_TYPE_INACTIVE == type )
537 mImpl->mEventData->mPlaceholderTextInactive = text;
541 mImpl->mEventData->mPlaceholderTextActive = text;
544 // Update placeholder if there is no text
545 if( mImpl->IsShowingPlaceholderText() ||
546 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
548 ShowPlaceholderText();
553 void Controller::GetPlaceholderText( std::string& text ) const
555 if( NULL != mImpl->mEventData )
557 text = mImpl->mEventData->mPlaceholderText;
561 // This is overloading function for PLACEHOLDER_TEXT_FOCUSED in text-field
562 void Controller::GetPlaceholderText( PlaceholderType type, std::string& text ) const
564 if( NULL != mImpl->mEventData )
566 if( PLACEHOLDER_TYPE_INACTIVE == type )
568 text = mImpl->mEventData->mPlaceholderTextInactive;
572 text = mImpl->mEventData->mPlaceholderTextActive;
577 void Controller::UpdateAfterFontChange( const std::string& newDefaultFont )
579 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
581 if( !mImpl->mFontDefaults->familyDefined ) // If user defined font then should not update when system font changes
583 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
584 mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
588 mImpl->RequestRelayout();
592 // public : Default style & Input style
594 void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
596 if( NULL == mImpl->mFontDefaults )
598 mImpl->mFontDefaults = new FontDefaults();
601 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
602 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
603 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
605 // Clear the font-specific data
608 mImpl->RequestRelayout();
611 const std::string& Controller::GetDefaultFontFamily() const
613 if( NULL != mImpl->mFontDefaults )
615 return mImpl->mFontDefaults->mFontDescription.family;
621 void Controller::SetDefaultFontWeight( FontWeight weight )
623 if( NULL == mImpl->mFontDefaults )
625 mImpl->mFontDefaults = new FontDefaults();
628 mImpl->mFontDefaults->mFontDescription.weight = weight;
629 mImpl->mFontDefaults->weightDefined = true;
631 // Clear the font-specific data
634 mImpl->RequestRelayout();
637 bool Controller::IsDefaultFontWeightDefined() const
639 return mImpl->mFontDefaults->weightDefined;
642 FontWeight Controller::GetDefaultFontWeight() const
644 if( NULL != mImpl->mFontDefaults )
646 return mImpl->mFontDefaults->mFontDescription.weight;
649 return TextAbstraction::FontWeight::NORMAL;
652 void Controller::SetDefaultFontWidth( FontWidth width )
654 if( NULL == mImpl->mFontDefaults )
656 mImpl->mFontDefaults = new FontDefaults();
659 mImpl->mFontDefaults->mFontDescription.width = width;
660 mImpl->mFontDefaults->widthDefined = true;
662 // Clear the font-specific data
665 mImpl->RequestRelayout();
668 bool Controller::IsDefaultFontWidthDefined() const
670 return mImpl->mFontDefaults->widthDefined;
673 FontWidth Controller::GetDefaultFontWidth() const
675 if( NULL != mImpl->mFontDefaults )
677 return mImpl->mFontDefaults->mFontDescription.width;
680 return TextAbstraction::FontWidth::NORMAL;
683 void Controller::SetDefaultFontSlant( FontSlant slant )
685 if( NULL == mImpl->mFontDefaults )
687 mImpl->mFontDefaults = new FontDefaults();
690 mImpl->mFontDefaults->mFontDescription.slant = slant;
691 mImpl->mFontDefaults->slantDefined = true;
693 // Clear the font-specific data
696 mImpl->RequestRelayout();
699 bool Controller::IsDefaultFontSlantDefined() const
701 return mImpl->mFontDefaults->slantDefined;
704 FontSlant Controller::GetDefaultFontSlant() const
706 if( NULL != mImpl->mFontDefaults )
708 return mImpl->mFontDefaults->mFontDescription.slant;
711 return TextAbstraction::FontSlant::NORMAL;
714 void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
716 if( NULL == mImpl->mFontDefaults )
718 mImpl->mFontDefaults = new FontDefaults();
725 mImpl->mFontDefaults->mDefaultPointSize = fontSize;
726 mImpl->mFontDefaults->sizeDefined = true;
731 // Point size = Pixel size * 72 / DPI
732 unsigned int horizontalDpi = 0u;
733 unsigned int verticalDpi = 0u;
734 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
735 fontClient.GetDpi( horizontalDpi, verticalDpi );
737 mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72 ) / horizontalDpi;
738 mImpl->mFontDefaults->sizeDefined = true;
743 DALI_ASSERT_ALWAYS( false );
747 // Clear the font-specific data
750 mImpl->RequestRelayout();
753 float Controller::GetDefaultFontSize( FontSizeType type ) const
756 if( NULL != mImpl->mFontDefaults )
762 value = mImpl->mFontDefaults->mDefaultPointSize;
767 // Pixel size = Point size * DPI / 72
768 unsigned int horizontalDpi = 0u;
769 unsigned int verticalDpi = 0u;
770 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
771 fontClient.GetDpi( horizontalDpi, verticalDpi );
773 value = mImpl->mFontDefaults->mDefaultPointSize * horizontalDpi / 72;
778 DALI_ASSERT_ALWAYS( false );
787 void Controller::SetDefaultColor( const Vector4& color )
789 mImpl->mTextColor = color;
791 if( !mImpl->IsShowingPlaceholderText() )
793 mImpl->mModel->mVisualModel->SetTextColor( color );
795 mImpl->RequestRelayout();
799 const Vector4& Controller::GetDefaultColor() const
801 return mImpl->mTextColor;
804 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
806 if( NULL != mImpl->mEventData )
808 mImpl->mEventData->mPlaceholderTextColor = textColor;
811 if( mImpl->IsShowingPlaceholderText() )
813 mImpl->mModel->mVisualModel->SetTextColor( textColor );
814 mImpl->RequestRelayout();
818 const Vector4& Controller::GetPlaceholderTextColor() const
820 if( NULL != mImpl->mEventData )
822 return mImpl->mEventData->mPlaceholderTextColor;
828 void Controller::SetShadowOffset( const Vector2& shadowOffset )
830 mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
832 mImpl->RequestRelayout();
835 const Vector2& Controller::GetShadowOffset() const
837 return mImpl->mModel->mVisualModel->GetShadowOffset();
840 void Controller::SetShadowColor( const Vector4& shadowColor )
842 mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
844 mImpl->RequestRelayout();
847 const Vector4& Controller::GetShadowColor() const
849 return mImpl->mModel->mVisualModel->GetShadowColor();
852 void Controller::SetUnderlineColor( const Vector4& color )
854 mImpl->mModel->mVisualModel->SetUnderlineColor( color );
856 mImpl->RequestRelayout();
859 const Vector4& Controller::GetUnderlineColor() const
861 return mImpl->mModel->mVisualModel->GetUnderlineColor();
864 void Controller::SetUnderlineEnabled( bool enabled )
866 mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
868 mImpl->RequestRelayout();
871 bool Controller::IsUnderlineEnabled() const
873 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
876 void Controller::SetUnderlineHeight( float height )
878 mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
880 mImpl->RequestRelayout();
883 float Controller::GetUnderlineHeight() const
885 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
888 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
890 if( NULL == mImpl->mEmbossDefaults )
892 mImpl->mEmbossDefaults = new EmbossDefaults();
895 mImpl->mEmbossDefaults->properties = embossProperties;
898 const std::string& Controller::GetDefaultEmbossProperties() const
900 if( NULL != mImpl->mEmbossDefaults )
902 return mImpl->mEmbossDefaults->properties;
908 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
910 if( NULL == mImpl->mOutlineDefaults )
912 mImpl->mOutlineDefaults = new OutlineDefaults();
915 mImpl->mOutlineDefaults->properties = outlineProperties;
918 const std::string& Controller::GetDefaultOutlineProperties() const
920 if( NULL != mImpl->mOutlineDefaults )
922 return mImpl->mOutlineDefaults->properties;
928 void Controller::SetDefaultLineSpacing( float lineSpacing )
930 //TODO finish implementation
931 mImpl->mLayoutEngine.SetDefaultLineSpacing( lineSpacing );
934 float Controller::GetDefaultLineSpacing() const
936 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
939 void Controller::SetInputColor( const Vector4& color )
941 if( NULL != mImpl->mEventData )
943 mImpl->mEventData->mInputStyle.textColor = color;
944 mImpl->mEventData->mInputStyle.isDefaultColor = false;
946 if( EventData::SELECTING == mImpl->mEventData->mState )
948 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
950 // Get start and end position of selection
951 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
952 const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
954 // Add the color run.
955 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
956 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
958 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
959 colorRun.color = color;
960 colorRun.characterRun.characterIndex = startOfSelectedText;
961 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
963 // Request to relayout.
964 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
965 mImpl->RequestRelayout();
967 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
968 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
969 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
974 const Vector4& Controller::GetInputColor() const
976 if( NULL != mImpl->mEventData )
978 return mImpl->mEventData->mInputStyle.textColor;
981 // Return the default text's color if there is no EventData.
982 return mImpl->mTextColor;
986 void Controller::SetInputFontFamily( const std::string& fontFamily )
988 if( NULL != mImpl->mEventData )
990 mImpl->mEventData->mInputStyle.familyName = fontFamily;
991 mImpl->mEventData->mInputStyle.isFamilyDefined = true;
993 if( EventData::SELECTING == mImpl->mEventData->mState )
995 CharacterIndex startOfSelectedText = 0u;
996 Length lengthOfSelectedText = 0u;
997 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
998 mImpl->mModel->mLogicalModel,
1000 lengthOfSelectedText );
1002 fontDescriptionRun.familyLength = fontFamily.size();
1003 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
1004 memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength );
1005 fontDescriptionRun.familyDefined = true;
1007 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
1009 // Request to relayout.
1010 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1015 UPDATE_LAYOUT_SIZE |
1018 mImpl->mRecalculateNaturalSize = true;
1019 mImpl->RequestRelayout();
1021 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1022 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1023 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1025 // As the font changes, recalculate the handle positions is needed.
1026 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1027 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1028 mImpl->mEventData->mUpdateHighlightBox = true;
1029 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1034 const std::string& Controller::GetInputFontFamily() const
1036 if( NULL != mImpl->mEventData )
1038 return mImpl->mEventData->mInputStyle.familyName;
1041 // Return the default font's family if there is no EventData.
1042 return GetDefaultFontFamily();
1045 void Controller::SetInputFontWeight( FontWeight weight )
1047 if( NULL != mImpl->mEventData )
1049 mImpl->mEventData->mInputStyle.weight = weight;
1050 mImpl->mEventData->mInputStyle.isWeightDefined = true;
1052 if( EventData::SELECTING == mImpl->mEventData->mState )
1054 CharacterIndex startOfSelectedText = 0u;
1055 Length lengthOfSelectedText = 0u;
1056 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1057 mImpl->mModel->mLogicalModel,
1058 startOfSelectedText,
1059 lengthOfSelectedText );
1061 fontDescriptionRun.weight = weight;
1062 fontDescriptionRun.weightDefined = true;
1064 // Request to relayout.
1065 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1070 UPDATE_LAYOUT_SIZE |
1073 mImpl->mRecalculateNaturalSize = true;
1074 mImpl->RequestRelayout();
1076 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1077 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1078 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1080 // As the font might change, recalculate the handle positions is needed.
1081 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1082 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1083 mImpl->mEventData->mUpdateHighlightBox = true;
1084 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1089 bool Controller::IsInputFontWeightDefined() const
1091 bool defined = false;
1093 if( NULL != mImpl->mEventData )
1095 defined = mImpl->mEventData->mInputStyle.isWeightDefined;
1101 FontWeight Controller::GetInputFontWeight() const
1103 if( NULL != mImpl->mEventData )
1105 return mImpl->mEventData->mInputStyle.weight;
1108 return GetDefaultFontWeight();
1111 void Controller::SetInputFontWidth( FontWidth width )
1113 if( NULL != mImpl->mEventData )
1115 mImpl->mEventData->mInputStyle.width = width;
1116 mImpl->mEventData->mInputStyle.isWidthDefined = true;
1118 if( EventData::SELECTING == mImpl->mEventData->mState )
1120 CharacterIndex startOfSelectedText = 0u;
1121 Length lengthOfSelectedText = 0u;
1122 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1123 mImpl->mModel->mLogicalModel,
1124 startOfSelectedText,
1125 lengthOfSelectedText );
1127 fontDescriptionRun.width = width;
1128 fontDescriptionRun.widthDefined = true;
1130 // Request to relayout.
1131 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1136 UPDATE_LAYOUT_SIZE |
1139 mImpl->mRecalculateNaturalSize = true;
1140 mImpl->RequestRelayout();
1142 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1143 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1144 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1146 // As the font might change, recalculate the handle positions is needed.
1147 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1148 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1149 mImpl->mEventData->mUpdateHighlightBox = true;
1150 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1155 bool Controller::IsInputFontWidthDefined() const
1157 bool defined = false;
1159 if( NULL != mImpl->mEventData )
1161 defined = mImpl->mEventData->mInputStyle.isWidthDefined;
1167 FontWidth Controller::GetInputFontWidth() const
1169 if( NULL != mImpl->mEventData )
1171 return mImpl->mEventData->mInputStyle.width;
1174 return GetDefaultFontWidth();
1177 void Controller::SetInputFontSlant( FontSlant slant )
1179 if( NULL != mImpl->mEventData )
1181 mImpl->mEventData->mInputStyle.slant = slant;
1182 mImpl->mEventData->mInputStyle.isSlantDefined = true;
1184 if( EventData::SELECTING == mImpl->mEventData->mState )
1186 CharacterIndex startOfSelectedText = 0u;
1187 Length lengthOfSelectedText = 0u;
1188 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1189 mImpl->mModel->mLogicalModel,
1190 startOfSelectedText,
1191 lengthOfSelectedText );
1193 fontDescriptionRun.slant = slant;
1194 fontDescriptionRun.slantDefined = true;
1196 // Request to relayout.
1197 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1202 UPDATE_LAYOUT_SIZE |
1205 mImpl->mRecalculateNaturalSize = true;
1206 mImpl->RequestRelayout();
1208 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1209 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1210 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1212 // As the font might change, recalculate the handle positions is needed.
1213 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1214 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1215 mImpl->mEventData->mUpdateHighlightBox = true;
1216 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1221 bool Controller::IsInputFontSlantDefined() const
1223 bool defined = false;
1225 if( NULL != mImpl->mEventData )
1227 defined = mImpl->mEventData->mInputStyle.isSlantDefined;
1233 FontSlant Controller::GetInputFontSlant() const
1235 if( NULL != mImpl->mEventData )
1237 return mImpl->mEventData->mInputStyle.slant;
1240 return GetDefaultFontSlant();
1243 void Controller::SetInputFontPointSize( float size )
1245 if( NULL != mImpl->mEventData )
1247 mImpl->mEventData->mInputStyle.size = size;
1248 mImpl->mEventData->mInputStyle.isSizeDefined = true;
1250 if( EventData::SELECTING == mImpl->mEventData->mState )
1252 CharacterIndex startOfSelectedText = 0u;
1253 Length lengthOfSelectedText = 0u;
1254 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1255 mImpl->mModel->mLogicalModel,
1256 startOfSelectedText,
1257 lengthOfSelectedText );
1259 fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
1260 fontDescriptionRun.sizeDefined = true;
1262 // Request to relayout.
1263 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1268 UPDATE_LAYOUT_SIZE |
1271 mImpl->mRecalculateNaturalSize = true;
1272 mImpl->RequestRelayout();
1274 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1275 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1276 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1278 // As the font might change, recalculate the handle positions is needed.
1279 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1280 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1281 mImpl->mEventData->mUpdateHighlightBox = true;
1282 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1287 float Controller::GetInputFontPointSize() const
1289 if( NULL != mImpl->mEventData )
1291 return mImpl->mEventData->mInputStyle.size;
1294 // Return the default font's point size if there is no EventData.
1295 return GetDefaultFontSize( Text::Controller::POINT_SIZE );
1298 void Controller::SetInputLineSpacing( float lineSpacing )
1300 if( NULL != mImpl->mEventData )
1302 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1303 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1307 float Controller::GetInputLineSpacing() const
1309 if( NULL != mImpl->mEventData )
1311 return mImpl->mEventData->mInputStyle.lineSpacing;
1317 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1319 if( NULL != mImpl->mEventData )
1321 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1325 const std::string& Controller::GetInputShadowProperties() const
1327 if( NULL != mImpl->mEventData )
1329 return mImpl->mEventData->mInputStyle.shadowProperties;
1332 return EMPTY_STRING;
1335 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1337 if( NULL != mImpl->mEventData )
1339 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1343 const std::string& Controller::GetInputUnderlineProperties() const
1345 if( NULL != mImpl->mEventData )
1347 return mImpl->mEventData->mInputStyle.underlineProperties;
1350 return EMPTY_STRING;
1353 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
1355 if( NULL != mImpl->mEventData )
1357 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1361 const std::string& Controller::GetInputEmbossProperties() const
1363 if( NULL != mImpl->mEventData )
1365 return mImpl->mEventData->mInputStyle.embossProperties;
1368 return GetDefaultEmbossProperties();
1371 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
1373 if( NULL != mImpl->mEventData )
1375 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1379 const std::string& Controller::GetInputOutlineProperties() const
1381 if( NULL != mImpl->mEventData )
1383 return mImpl->mEventData->mInputStyle.outlineProperties;
1386 return GetDefaultOutlineProperties();
1389 void Controller::SetInputModePassword( bool passwordInput )
1391 if( NULL != mImpl->mEventData )
1393 mImpl->mEventData->mPasswordInput = passwordInput;
1397 bool Controller::IsInputModePassword()
1399 if( NULL != mImpl->mEventData )
1401 return mImpl->mEventData->mPasswordInput;
1406 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
1408 if( NULL != mImpl->mEventData )
1410 mImpl->mEventData->mDoubleTapAction = action;
1414 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1416 NoTextTap::Action action = NoTextTap::NO_ACTION;
1418 if( NULL != mImpl->mEventData )
1420 action = mImpl->mEventData->mDoubleTapAction;
1426 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
1428 if( NULL != mImpl->mEventData )
1430 mImpl->mEventData->mLongPressAction = action;
1434 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1436 NoTextTap::Action action = NoTextTap::NO_ACTION;
1438 if( NULL != mImpl->mEventData )
1440 action = mImpl->mEventData->mLongPressAction;
1446 bool Controller::IsUnderlineSetByString()
1448 return mImpl->mUnderlineSetByString;
1451 void Controller::UnderlineSetByString( bool setByString )
1453 mImpl->mUnderlineSetByString = setByString;
1456 bool Controller::IsShadowSetByString()
1458 return mImpl->mShadowSetByString;
1461 void Controller::ShadowSetByString( bool setByString )
1463 mImpl->mShadowSetByString = setByString;
1466 bool Controller::IsFontStyleSetByString()
1468 return mImpl->mFontStyleSetByString;
1471 void Controller::FontStyleSetByString( bool setByString )
1473 mImpl->mFontStyleSetByString = setByString;
1476 // public : Queries & retrieves.
1478 Layout::Engine& Controller::GetLayoutEngine()
1480 return mImpl->mLayoutEngine;
1483 View& Controller::GetView()
1485 return mImpl->mView;
1488 Vector3 Controller::GetNaturalSize()
1490 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
1491 Vector3 naturalSize;
1493 // Make sure the model is up-to-date before layouting
1494 ProcessModifyEvents();
1496 if( mImpl->mRecalculateNaturalSize )
1498 // Operations that can be done only once until the text changes.
1499 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1506 GET_GLYPH_METRICS );
1508 // Set the update info to relayout the whole text.
1509 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1510 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1512 // Make sure the model is up-to-date before layouting
1513 mImpl->UpdateModel( onlyOnceOperations );
1515 // Layout the text for the new width.
1516 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
1518 // Store the actual control's size to restore later.
1519 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
1521 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
1522 static_cast<OperationsMask>( onlyOnceOperations |
1524 naturalSize.GetVectorXY() );
1526 // Do not do again the only once operations.
1527 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1529 // Do the size related operations again.
1530 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1533 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1535 // Stores the natural size to avoid recalculate it again
1536 // unless the text/style changes.
1537 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
1539 mImpl->mRecalculateNaturalSize = false;
1541 // Clear the update info. This info will be set the next time the text is updated.
1542 mImpl->mTextUpdateInfo.Clear();
1544 // Restore the actual control's size.
1545 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
1547 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1551 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
1553 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1556 naturalSize.x = ConvertToEven( naturalSize.x );
1557 naturalSize.y = ConvertToEven( naturalSize.y );
1562 float Controller::GetHeightForWidth( float width )
1564 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
1565 // Make sure the model is up-to-date before layouting
1566 ProcessModifyEvents();
1569 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ||
1570 mImpl->mTextUpdateInfo.mFullRelayoutNeeded )
1572 // Operations that can be done only once until the text changes.
1573 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1580 GET_GLYPH_METRICS );
1582 // Set the update info to relayout the whole text.
1583 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1584 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1586 // Make sure the model is up-to-date before layouting
1587 mImpl->UpdateModel( onlyOnceOperations );
1590 // Layout the text for the new width.
1591 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
1593 // Store the actual control's width.
1594 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
1596 DoRelayout( Size( width, MAX_FLOAT ),
1597 static_cast<OperationsMask>( onlyOnceOperations |
1601 // Do not do again the only once operations.
1602 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1604 // Do the size related operations again.
1605 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1609 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1611 // Clear the update info. This info will be set the next time the text is updated.
1612 mImpl->mTextUpdateInfo.Clear();
1614 // Restore the actual control's width.
1615 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
1617 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
1621 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
1622 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
1625 return layoutSize.height;
1628 int Controller::GetLineCount( float width )
1630 GetHeightForWidth( width );
1631 int numberofLines = mImpl->mModel->GetNumberOfLines();
1632 return numberofLines;
1635 const ModelInterface* const Controller::GetTextModel() const
1637 return mImpl->mModel.Get();
1640 float Controller::GetScrollAmountByUserInput()
1642 float scrollAmount = 0.0f;
1644 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
1646 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
1647 mImpl->mEventData->mCheckScrollAmount = false;
1649 return scrollAmount;
1652 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
1654 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
1657 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
1658 layoutHeight = layout.height;
1659 scrollPosition = mImpl->mModel->mScrollPosition.y;
1660 isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
1664 void Controller::SetHiddenInputOption(const Property::Map& options )
1666 if( NULL == mImpl->mHiddenInput )
1668 mImpl->mHiddenInput = new HiddenText( this );
1670 mImpl->mHiddenInput->SetProperties(options);
1673 void Controller::GetHiddenInputOption(Property::Map& options )
1675 if( NULL != mImpl->mHiddenInput )
1677 mImpl->mHiddenInput->GetProperties(options);
1681 // public : Relayout.
1683 Controller::UpdateTextType Controller::Relayout( const Size& size )
1685 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
1687 UpdateTextType updateTextType = NONE_UPDATED;
1689 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
1691 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
1693 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
1694 updateTextType = MODEL_UPDATED;
1697 // Clear the update info. This info will be set the next time the text is updated.
1698 mImpl->mTextUpdateInfo.Clear();
1700 // Not worth to relayout if width or height is equal to zero.
1701 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
1703 return updateTextType;
1706 // Whether a new size has been set.
1707 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
1711 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
1713 // Layout operations that need to be done if the size changes.
1714 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1717 UPDATE_LAYOUT_SIZE |
1719 // Set the update info to relayout the whole text.
1720 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
1721 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
1723 // Store the size used to layout the text.
1724 mImpl->mModel->mVisualModel->mControlSize = size;
1727 // Whether there are modify events.
1728 if( 0u != mImpl->mModifyEvents.Count() )
1730 // Style operations that need to be done if the text is modified.
1731 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1735 // Make sure the model is up-to-date before layouting.
1736 ProcessModifyEvents();
1737 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
1741 updated = DoRelayout( size,
1742 mImpl->mOperationsPending,
1743 layoutSize ) || updated;
1747 updateTextType = MODEL_UPDATED;
1750 // Do not re-do any operation until something changes.
1751 mImpl->mOperationsPending = NO_OPERATION;
1752 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
1754 // Whether the text control is editable
1755 const bool isEditable = NULL != mImpl->mEventData;
1757 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
1759 if( newSize && isEditable )
1761 offset = mImpl->mModel->mScrollPosition;
1764 if( !isEditable || !IsMultiLineEnabled() )
1766 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
1767 CalculateVerticalOffset( size );
1774 // If there is a new size, the scroll position needs to be clamped.
1775 mImpl->ClampHorizontalScroll( layoutSize );
1777 // Update the decorator's positions is needed if there is a new size.
1778 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
1781 // Move the cursor, grab handle etc.
1782 if( mImpl->ProcessInputEvents() )
1784 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
1788 // Clear the update info. This info will be set the next time the text is updated.
1789 mImpl->mTextUpdateInfo.Clear();
1790 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
1792 return updateTextType;
1795 void Controller::RequestRelayout()
1797 mImpl->RequestRelayout();
1800 // public : Input style change signals.
1802 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
1804 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
1807 void Controller::ProcessInputStyleChangedSignals()
1809 if( NULL == mImpl->mEventData )
1815 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
1816 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
1820 const InputStyle::Mask mask = *it;
1822 if( NULL != mImpl->mEditableControlInterface )
1824 // Emit the input style changed signal.
1825 mImpl->mEditableControlInterface->InputStyleChanged( mask );
1829 mImpl->mEventData->mInputStyleChangedQueue.Clear();
1832 // public : Text-input Event Queuing.
1834 void Controller::KeyboardFocusGainEvent()
1836 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
1838 if( NULL != mImpl->mEventData )
1840 if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
1841 ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
1843 mImpl->ChangeState( EventData::EDITING );
1844 mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
1845 mImpl->mEventData->mUpdateInputStyle = true;
1847 mImpl->NotifyImfMultiLineStatus();
1848 if( mImpl->IsShowingPlaceholderText() )
1850 // Show alternative placeholder-text when editing
1851 ShowPlaceholderText();
1854 mImpl->RequestRelayout();
1858 void Controller::KeyboardFocusLostEvent()
1860 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
1862 if( NULL != mImpl->mEventData )
1864 if( EventData::INTERRUPTED != mImpl->mEventData->mState )
1866 mImpl->ChangeState( EventData::INACTIVE );
1868 if( !mImpl->IsShowingRealText() )
1870 // Revert to regular placeholder-text when not editing
1871 ShowPlaceholderText();
1875 mImpl->RequestRelayout();
1878 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
1880 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
1882 bool textChanged = false;
1883 bool relayoutNeeded = false;
1885 if( ( NULL != mImpl->mEventData ) &&
1886 ( keyEvent.state == KeyEvent::Down ) )
1888 int keyCode = keyEvent.keyCode;
1889 const std::string& keyString = keyEvent.keyPressed;
1891 const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
1893 // Pre-process to separate modifying events from non-modifying input events.
1896 // In some platforms arrive key events with no key code.
1899 else if( Dali::DALI_KEY_ESCAPE == keyCode )
1901 // Escape key is a special case which causes focus loss
1902 KeyboardFocusLostEvent();
1904 // Will request for relayout.
1905 relayoutNeeded = true;
1907 else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) ||
1908 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
1909 ( Dali::DALI_KEY_CURSOR_UP == keyCode ) ||
1910 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) )
1912 // If don't have any text, do nothing.
1913 if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
1918 uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition;
1919 uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
1920 uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition );
1921 uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines();
1923 // Logic to determine whether this text control will lose focus or not.
1924 if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition ) ||
1925 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition) ||
1926 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) ||
1927 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) ||
1928 ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) ||
1929 ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) )
1934 mImpl->mEventData->mCheckScrollAmount = true;
1935 Event event( Event::CURSOR_KEY_EVENT );
1936 event.p1.mInt = keyCode;
1937 mImpl->mEventData->mEventQueue.push_back( event );
1939 // Will request for relayout.
1940 relayoutNeeded = true;
1942 else if( Dali::DALI_KEY_BACKSPACE == keyCode )
1944 textChanged = BackspaceKeyEvent();
1946 // Will request for relayout.
1947 relayoutNeeded = true;
1949 else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
1950 IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
1951 IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
1953 // Power key/Menu/Home key behaviour does not allow edit mode to resume.
1954 mImpl->ChangeState( EventData::INACTIVE );
1956 // Will request for relayout.
1957 relayoutNeeded = true;
1959 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
1961 else if( Dali::DALI_KEY_SHIFT_LEFT == keyCode )
1963 // DALI_KEY_SHIFT_LEFT is the key code for the Left Shift. It's sent (by the imf?) when the predictive text is enabled
1964 // and a character is typed after the type of a upper case latin character.
1968 else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
1970 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
1975 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
1977 // IMF manager is no longer handling key-events
1978 mImpl->ClearPreEditFlag();
1980 InsertText( keyString, COMMIT );
1983 // Will request for relayout.
1984 relayoutNeeded = true;
1987 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
1988 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
1990 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
1991 ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
1992 ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
1994 // Should not change the state if the key is the shift send by the imf manager.
1995 // Otherwise, when the state is SELECTING the text controller can't send the right
1996 // surrounding info to the imf.
1997 mImpl->ChangeState( EventData::EDITING );
1999 // Will request for relayout.
2000 relayoutNeeded = true;
2003 if( relayoutNeeded )
2005 mImpl->RequestRelayout();
2010 ( NULL != mImpl->mEditableControlInterface ) )
2012 // Do this last since it provides callbacks into application code
2013 mImpl->mEditableControlInterface->TextChanged();
2019 void Controller::TapEvent( unsigned int tapCount, float x, float y )
2021 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
2023 if( NULL != mImpl->mEventData )
2025 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
2026 EventData::State state( mImpl->mEventData->mState );
2027 bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
2029 if( mImpl->IsClipboardVisible() )
2031 if( EventData::INACTIVE == state || EventData::EDITING == state)
2033 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2035 relayoutNeeded = true;
2037 else if( 1u == tapCount )
2039 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
2041 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
2044 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
2046 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2047 relayoutNeeded = true;
2051 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
2053 // Hide placeholder text
2057 if( EventData::INACTIVE == state )
2059 mImpl->ChangeState( EventData::EDITING );
2061 else if( !mImpl->IsClipboardEmpty() )
2063 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
2065 relayoutNeeded = true;
2068 else if( 2u == tapCount )
2070 if( mImpl->mEventData->mSelectionEnabled &&
2071 mImpl->IsShowingRealText() )
2073 relayoutNeeded = true;
2074 mImpl->mEventData->mIsLeftHandleSelected = true;
2075 mImpl->mEventData->mIsRightHandleSelected = true;
2079 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
2080 if( relayoutNeeded )
2082 Event event( Event::TAP_EVENT );
2083 event.p1.mUint = tapCount;
2084 event.p2.mFloat = x;
2085 event.p3.mFloat = y;
2086 mImpl->mEventData->mEventQueue.push_back( event );
2088 mImpl->RequestRelayout();
2092 // Reset keyboard as tap event has occurred.
2093 mImpl->ResetImfManager();
2096 void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
2098 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
2100 if( NULL != mImpl->mEventData )
2102 Event event( Event::PAN_EVENT );
2103 event.p1.mInt = state;
2104 event.p2.mFloat = displacement.x;
2105 event.p3.mFloat = displacement.y;
2106 mImpl->mEventData->mEventQueue.push_back( event );
2108 mImpl->RequestRelayout();
2112 void Controller::LongPressEvent( Gesture::State state, float x, float y )
2114 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
2116 if( ( state == Gesture::Started ) &&
2117 ( NULL != mImpl->mEventData ) )
2119 // The 1st long-press on inactive text-field is treated as tap
2120 if( EventData::INACTIVE == mImpl->mEventData->mState )
2122 mImpl->ChangeState( EventData::EDITING );
2124 Event event( Event::TAP_EVENT );
2126 event.p2.mFloat = x;
2127 event.p3.mFloat = y;
2128 mImpl->mEventData->mEventQueue.push_back( event );
2130 mImpl->RequestRelayout();
2132 else if( !mImpl->IsShowingRealText() )
2134 Event event( Event::LONG_PRESS_EVENT );
2135 event.p1.mInt = state;
2136 event.p2.mFloat = x;
2137 event.p3.mFloat = y;
2138 mImpl->mEventData->mEventQueue.push_back( event );
2139 mImpl->RequestRelayout();
2141 else if( !mImpl->IsClipboardVisible() )
2143 // Reset the imf manager to commit the pre-edit before selecting the text.
2144 mImpl->ResetImfManager();
2146 Event event( Event::LONG_PRESS_EVENT );
2147 event.p1.mInt = state;
2148 event.p2.mFloat = x;
2149 event.p3.mFloat = y;
2150 mImpl->mEventData->mEventQueue.push_back( event );
2151 mImpl->RequestRelayout();
2153 mImpl->mEventData->mIsLeftHandleSelected = true;
2154 mImpl->mEventData->mIsRightHandleSelected = true;
2159 ImfManager::ImfCallbackData Controller::OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
2161 // Whether the text needs to be relaid-out.
2162 bool requestRelayout = false;
2164 // Whether to retrieve the text and cursor position to be sent to the IMF manager.
2165 bool retrieveText = false;
2166 bool retrieveCursor = false;
2168 switch( imfEvent.eventName )
2170 case ImfManager::COMMIT:
2172 InsertText( imfEvent.predictiveString, Text::Controller::COMMIT );
2173 requestRelayout = true;
2174 retrieveCursor = true;
2177 case ImfManager::PREEDIT:
2179 InsertText( imfEvent.predictiveString, Text::Controller::PRE_EDIT );
2180 requestRelayout = true;
2181 retrieveCursor = true;
2184 case ImfManager::DELETESURROUNDING:
2186 const bool textDeleted = RemoveText( imfEvent.cursorOffset,
2187 imfEvent.numberOfChars,
2188 DONT_UPDATE_INPUT_STYLE );
2192 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2193 !mImpl->IsPlaceholderAvailable() )
2195 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2199 ShowPlaceholderText();
2201 mImpl->mEventData->mUpdateCursorPosition = true;
2202 mImpl->mEventData->mScrollAfterDelete = true;
2204 requestRelayout = true;
2208 case ImfManager::GETSURROUNDING:
2210 retrieveText = true;
2211 retrieveCursor = true;
2214 case ImfManager::PRIVATECOMMAND:
2216 // PRIVATECOMMAND event is just for getting the private command message
2217 retrieveText = true;
2218 retrieveCursor = true;
2221 case ImfManager::VOID:
2228 if( requestRelayout )
2230 mImpl->mOperationsPending = ALL_OPERATIONS;
2231 mImpl->RequestRelayout();
2235 CharacterIndex cursorPosition = 0u;
2236 Length numberOfWhiteSpaces = 0u;
2238 if( retrieveCursor )
2240 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
2242 cursorPosition = mImpl->GetLogicalCursorPosition();
2244 if( cursorPosition < numberOfWhiteSpaces )
2246 cursorPosition = 0u;
2250 cursorPosition -= numberOfWhiteSpaces;
2256 mImpl->GetText( numberOfWhiteSpaces, text );
2259 ImfManager::ImfCallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
2261 if( requestRelayout &&
2262 ( NULL != mImpl->mEditableControlInterface ) )
2264 // Do this last since it provides callbacks into application code
2265 mImpl->mEditableControlInterface->TextChanged();
2268 return callbackData;
2271 void Controller::PasteClipboardItemEvent()
2273 // Retrieve the clipboard contents first
2274 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
2275 std::string stringToPaste( notifier.GetContent() );
2277 // Commit the current pre-edit text; the contents of the clipboard should be appended
2278 mImpl->ResetImfManager();
2280 // Temporary disable hiding clipboard
2281 mImpl->SetClipboardHideEnable( false );
2284 PasteText( stringToPaste );
2286 mImpl->SetClipboardHideEnable( true );
2289 // protected : Inherit from Text::Decorator::ControllerInterface.
2291 void Controller::GetTargetSize( Vector2& targetSize )
2293 targetSize = mImpl->mModel->mVisualModel->mControlSize;
2296 void Controller::AddDecoration( Actor& actor, bool needsClipping )
2298 if( NULL != mImpl->mEditableControlInterface )
2300 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
2304 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
2306 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
2308 if( NULL != mImpl->mEventData )
2310 switch( handleType )
2314 Event event( Event::GRAB_HANDLE_EVENT );
2315 event.p1.mUint = state;
2316 event.p2.mFloat = x;
2317 event.p3.mFloat = y;
2319 mImpl->mEventData->mEventQueue.push_back( event );
2322 case LEFT_SELECTION_HANDLE:
2324 Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
2325 event.p1.mUint = state;
2326 event.p2.mFloat = x;
2327 event.p3.mFloat = y;
2329 mImpl->mEventData->mEventQueue.push_back( event );
2332 case RIGHT_SELECTION_HANDLE:
2334 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
2335 event.p1.mUint = state;
2336 event.p2.mFloat = x;
2337 event.p3.mFloat = y;
2339 mImpl->mEventData->mEventQueue.push_back( event );
2342 case LEFT_SELECTION_HANDLE_MARKER:
2343 case RIGHT_SELECTION_HANDLE_MARKER:
2345 // Markers do not move the handles.
2348 case HANDLE_TYPE_COUNT:
2350 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
2354 mImpl->RequestRelayout();
2358 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
2360 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
2362 if( NULL == mImpl->mEventData )
2369 case Toolkit::TextSelectionPopup::CUT:
2371 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
2372 mImpl->mOperationsPending = ALL_OPERATIONS;
2374 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2375 !mImpl->IsPlaceholderAvailable() )
2377 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2381 ShowPlaceholderText();
2384 mImpl->mEventData->mUpdateCursorPosition = true;
2385 mImpl->mEventData->mScrollAfterDelete = true;
2387 mImpl->RequestRelayout();
2389 if( NULL != mImpl->mEditableControlInterface )
2391 mImpl->mEditableControlInterface->TextChanged();
2395 case Toolkit::TextSelectionPopup::COPY:
2397 mImpl->SendSelectionToClipboard( false ); // Text not modified
2399 mImpl->mEventData->mUpdateCursorPosition = true;
2401 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
2404 case Toolkit::TextSelectionPopup::PASTE:
2406 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
2409 case Toolkit::TextSelectionPopup::SELECT:
2411 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
2413 if( mImpl->mEventData->mSelectionEnabled )
2415 // Creates a SELECT event.
2416 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
2420 case Toolkit::TextSelectionPopup::SELECT_ALL:
2422 // Creates a SELECT_ALL event
2423 SelectEvent( 0.f, 0.f, true );
2426 case Toolkit::TextSelectionPopup::CLIPBOARD:
2428 mImpl->ShowClipboard();
2431 case Toolkit::TextSelectionPopup::NONE:
2439 void Controller::DisplayTimeExpired()
2441 mImpl->mEventData->mUpdateCursorPosition = true;
2442 // Apply modifications to the model
2443 mImpl->mOperationsPending = ALL_OPERATIONS;
2445 mImpl->RequestRelayout();
2448 // private : Update.
2450 void Controller::InsertText( const std::string& text, Controller::InsertType type )
2452 bool removedPrevious = false;
2453 bool removedSelected = false;
2454 bool maxLengthReached = false;
2456 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
2458 if( NULL == mImpl->mEventData )
2463 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
2464 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
2465 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
2467 // TODO: At the moment the underline runs are only for pre-edit.
2468 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
2470 // Remove the previous IMF pre-edit.
2471 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
2473 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
2474 mImpl->mEventData->mPreEditLength,
2475 DONT_UPDATE_INPUT_STYLE );
2477 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
2478 mImpl->mEventData->mPreEditLength = 0u;
2482 // Remove the previous Selection.
2483 removedSelected = RemoveSelectedText();
2487 Vector<Character> utf32Characters;
2488 Length characterCount = 0u;
2492 // Convert text into UTF-32
2493 utf32Characters.Resize( text.size() );
2495 // This is a bit horrible but std::string returns a (signed) char*
2496 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
2498 // Transform a text array encoded in utf8 into an array encoded in utf32.
2499 // It returns the actual number of characters.
2500 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
2501 utf32Characters.Resize( characterCount );
2503 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
2504 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
2507 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
2509 // The placeholder text is no longer needed
2510 if( mImpl->IsShowingPlaceholderText() )
2515 mImpl->ChangeState( EventData::EDITING );
2517 // Handle the IMF (predicitive text) state changes
2518 if( COMMIT == type )
2520 // IMF manager is no longer handling key-events
2521 mImpl->ClearPreEditFlag();
2525 if( !mImpl->mEventData->mPreEditFlag )
2527 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
2529 // Record the start of the pre-edit text
2530 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
2533 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
2534 mImpl->mEventData->mPreEditFlag = true;
2536 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
2539 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
2541 // Restrict new text to fit within Maximum characters setting.
2542 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
2543 maxLengthReached = ( characterCount > maxSizeOfNewText );
2545 // The cursor position.
2546 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
2548 // Update the text's style.
2550 // Updates the text style runs by adding characters.
2551 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
2553 // Get the character index from the cursor index.
2554 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
2556 // Retrieve the text's style for the given index.
2558 mImpl->RetrieveDefaultInputStyle( style );
2559 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
2561 // Whether to add a new text color run.
2562 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor );
2564 // Whether to add a new font run.
2565 const bool addFontNameRun = style.familyName != mImpl->mEventData->mInputStyle.familyName;
2566 const bool addFontWeightRun = style.weight != mImpl->mEventData->mInputStyle.weight;
2567 const bool addFontWidthRun = style.width != mImpl->mEventData->mInputStyle.width;
2568 const bool addFontSlantRun = style.slant != mImpl->mEventData->mInputStyle.slant;
2569 const bool addFontSizeRun = style.size != mImpl->mEventData->mInputStyle.size;
2574 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
2575 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
2577 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
2578 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
2579 colorRun.characterRun.characterIndex = cursorIndex;
2580 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
2583 if( addFontNameRun ||
2589 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
2590 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
2592 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
2594 if( addFontNameRun )
2596 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
2597 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
2598 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
2599 fontDescriptionRun.familyDefined = true;
2601 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
2604 if( addFontWeightRun )
2606 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
2607 fontDescriptionRun.weightDefined = true;
2610 if( addFontWidthRun )
2612 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
2613 fontDescriptionRun.widthDefined = true;
2616 if( addFontSlantRun )
2618 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
2619 fontDescriptionRun.slantDefined = true;
2622 if( addFontSizeRun )
2624 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
2625 fontDescriptionRun.sizeDefined = true;
2628 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
2629 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
2632 // Insert at current cursor position.
2633 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
2635 if( cursorIndex < numberOfCharactersInModel )
2637 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
2641 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
2644 // Mark the first paragraph to be updated.
2645 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
2646 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
2648 // Update the cursor index.
2649 cursorIndex += maxSizeOfNewText;
2651 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 );
2654 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
2655 mImpl->IsPlaceholderAvailable() )
2657 // Show place-holder if empty after removing the pre-edit text
2658 ShowPlaceholderText();
2659 mImpl->mEventData->mUpdateCursorPosition = true;
2660 mImpl->ClearPreEditFlag();
2662 else if( removedPrevious ||
2664 ( 0 != utf32Characters.Count() ) )
2666 // Queue an inserted event
2667 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
2669 mImpl->mEventData->mUpdateCursorPosition = true;
2670 if( removedSelected )
2672 mImpl->mEventData->mScrollAfterDelete = true;
2676 mImpl->mEventData->mScrollAfterUpdatePosition = true;
2680 if( maxLengthReached )
2682 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
2684 mImpl->ResetImfManager();
2686 if( NULL != mImpl->mEditableControlInterface )
2688 // Do this last since it provides callbacks into application code
2689 mImpl->mEditableControlInterface->MaxLengthReached();
2694 void Controller::PasteText( const std::string& stringToPaste )
2696 InsertText( stringToPaste, Text::Controller::COMMIT );
2697 mImpl->ChangeState( EventData::EDITING );
2698 mImpl->RequestRelayout();
2700 if( NULL != mImpl->mEditableControlInterface )
2702 // Do this last since it provides callbacks into application code
2703 mImpl->mEditableControlInterface->TextChanged();
2707 bool Controller::RemoveText( int cursorOffset,
2708 int numberOfCharacters,
2709 UpdateInputStyleType type )
2711 bool removed = false;
2713 if( NULL == mImpl->mEventData )
2718 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
2719 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
2721 if( !mImpl->IsShowingPlaceholderText() )
2723 // Delete at current cursor position
2724 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
2725 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
2727 CharacterIndex cursorIndex = 0;
2729 // Validate the cursor position & number of characters
2730 if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
2732 cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
2735 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
2737 numberOfCharacters = currentText.Count() - cursorIndex;
2740 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.
2741 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
2743 // Mark the paragraphs to be updated.
2744 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
2745 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
2747 // Update the input style and remove the text's style before removing the text.
2749 if( UPDATE_INPUT_STYLE == type )
2751 // Keep a copy of the current input style.
2752 InputStyle currentInputStyle;
2753 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
2755 // Set first the default input style.
2756 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
2758 // Update the input style.
2759 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
2761 // Compare if the input style has changed.
2762 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
2764 if( hasInputStyleChanged )
2766 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
2767 // Queue the input style changed signal.
2768 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
2772 // Updates the text style runs by removing characters. Runs with no characters are removed.
2773 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
2775 // Remove the characters.
2776 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
2777 Vector<Character>::Iterator last = first + numberOfCharacters;
2779 currentText.Erase( first, last );
2781 // Cursor position retreat
2782 oldCursorIndex = cursorIndex;
2784 mImpl->mEventData->mScrollAfterDelete = true;
2786 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
2794 bool Controller::RemoveSelectedText()
2796 bool textRemoved( false );
2798 if( EventData::SELECTING == mImpl->mEventData->mState )
2800 std::string removedString;
2801 mImpl->RetrieveSelection( removedString, true );
2803 if( !removedString.empty() )
2806 mImpl->ChangeState( EventData::EDITING );
2813 // private : Relayout.
2815 bool Controller::DoRelayout( const Size& size,
2816 OperationsMask operationsRequired,
2819 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
2820 bool viewUpdated( false );
2822 // Calculate the operations to be done.
2823 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
2825 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
2826 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
2828 // Get the current layout size.
2829 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
2831 if( NO_OPERATION != ( LAYOUT & operations ) )
2833 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
2835 // Some vectors with data needed to layout and reorder may be void
2836 // after the first time the text has been laid out.
2837 // Fill the vectors again.
2839 // Calculate the number of glyphs to layout.
2840 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
2841 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
2842 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
2843 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
2845 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
2846 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
2847 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
2848 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
2850 if( 0u == totalNumberOfGlyphs )
2852 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
2854 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
2857 // Nothing else to do if there is no glyphs.
2858 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
2862 const Vector<LineBreakInfo>& lineBreakInfo = mImpl->mModel->mLogicalModel->mLineBreakInfo;
2863 const Vector<WordBreakInfo>& wordBreakInfo = mImpl->mModel->mLogicalModel->mWordBreakInfo;
2864 const Vector<CharacterDirection>& characterDirection = mImpl->mModel->mLogicalModel->mCharacterDirections;
2865 const Vector<GlyphInfo>& glyphs = mImpl->mModel->mVisualModel->mGlyphs;
2866 const Vector<CharacterIndex>& glyphsToCharactersMap = mImpl->mModel->mVisualModel->mGlyphsToCharacters;
2867 const Vector<Length>& charactersPerGlyph = mImpl->mModel->mVisualModel->mCharactersPerGlyph;
2868 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
2870 // Set the layout parameters.
2871 Layout::Parameters layoutParameters( size,
2873 lineBreakInfo.Begin(),
2874 wordBreakInfo.Begin(),
2875 ( 0u != characterDirection.Count() ) ? characterDirection.Begin() : NULL,
2877 glyphsToCharactersMap.Begin(),
2878 charactersPerGlyph.Begin(),
2879 charactersToGlyphBuffer,
2880 glyphsPerCharacterBuffer,
2881 totalNumberOfGlyphs,
2882 mImpl->mModel->mHorizontalAlignment );
2884 // Resize the vector of positions to have the same size than the vector of glyphs.
2885 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
2886 glyphPositions.Resize( totalNumberOfGlyphs );
2888 // Whether the last character is a new paragraph character.
2889 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
2890 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
2892 // The initial glyph and the number of glyphs to layout.
2893 layoutParameters.startGlyphIndex = startGlyphIndex;
2894 layoutParameters.numberOfGlyphs = numberOfGlyphs;
2895 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
2896 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
2898 // Update the visual model.
2900 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
2902 mImpl->mModel->mVisualModel->mLines,
2904 mImpl->mModel->mElideEnabled );
2906 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
2910 layoutSize = newLayoutSize;
2912 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
2914 mImpl->mAutoScrollDirectionRTL = false;
2917 // Reorder the lines
2918 if( NO_OPERATION != ( REORDER & operations ) )
2920 Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = mImpl->mModel->mLogicalModel->mBidirectionalParagraphInfo;
2921 Vector<BidirectionalLineInfoRun>& bidirectionalLineInfo = mImpl->mModel->mLogicalModel->mBidirectionalLineInfo;
2923 // Check first if there are paragraphs with bidirectional info.
2924 if( 0u != bidirectionalInfo.Count() )
2927 const Length numberOfLines = mImpl->mModel->mVisualModel->mLines.Count();
2929 // Reorder the lines.
2930 bidirectionalLineInfo.Reserve( numberOfLines ); // Reserve because is not known yet how many lines have right to left characters.
2931 ReorderLines( bidirectionalInfo,
2933 requestedNumberOfCharacters,
2934 mImpl->mModel->mVisualModel->mLines,
2935 bidirectionalLineInfo );
2937 // Set the bidirectional info per line into the layout parameters.
2938 layoutParameters.lineBidirectionalInfoRunsBuffer = bidirectionalLineInfo.Begin();
2939 layoutParameters.numberOfBidirectionalInfoRuns = bidirectionalLineInfo.Count();
2941 // Re-layout the text. Reorder those lines with right to left characters.
2942 mImpl->mLayoutEngine.ReLayoutRightToLeftLines( layoutParameters,
2944 requestedNumberOfCharacters,
2947 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && ( numberOfLines > 0 ) )
2949 const LineRun* const firstline = mImpl->mModel->mVisualModel->mLines.Begin();
2952 mImpl->mAutoScrollDirectionRTL = firstline->direction;
2958 // Sets the layout size.
2959 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
2961 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
2966 if( NO_OPERATION != ( ALIGN & operations ) )
2968 // The laid-out lines.
2969 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
2971 // Need to align with the control's size as the text may contain lines
2972 // starting either with left to right text or right to left.
2973 mImpl->mLayoutEngine.Align( size,
2975 requestedNumberOfCharacters,
2976 mImpl->mModel->mHorizontalAlignment,
2978 mImpl->mModel->mAlignmentOffset );
2982 #if defined(DEBUG_ENABLED)
2983 std::string currentText;
2984 GetText( currentText );
2985 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mAutoScrollDirectionRTL[%s] [%s]\n", this, (mImpl->mAutoScrollDirectionRTL)?"true":"false", currentText.c_str() );
2987 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
2991 void Controller::CalculateVerticalOffset( const Size& controlSize )
2993 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
2995 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
2997 // Get the line height of the default font.
2998 layoutSize.height = mImpl->GetDefaultFontLineHeight();
3001 switch( mImpl->mModel->mVerticalAlignment )
3003 case Layout::VERTICAL_ALIGN_TOP:
3005 mImpl->mModel->mScrollPosition.y = 0.f;
3008 case Layout::VERTICAL_ALIGN_CENTER:
3010 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
3013 case Layout::VERTICAL_ALIGN_BOTTOM:
3015 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
3021 // private : Events.
3023 void Controller::ProcessModifyEvents()
3025 Vector<ModifyEvent>& events = mImpl->mModifyEvents;
3027 if( 0u == events.Count() )
3033 for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
3034 endIt = events.End();
3038 const ModifyEvent& event = *it;
3040 if( ModifyEvent::TEXT_REPLACED == event.type )
3042 // A (single) replace event should come first, otherwise we wasted time processing NOOP events
3043 DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
3045 TextReplacedEvent();
3047 else if( ModifyEvent::TEXT_INSERTED == event.type )
3049 TextInsertedEvent();
3051 else if( ModifyEvent::TEXT_DELETED == event.type )
3053 // Placeholder-text cannot be deleted
3054 if( !mImpl->IsShowingPlaceholderText() )
3061 if( NULL != mImpl->mEventData )
3063 // When the text is being modified, delay cursor blinking
3064 mImpl->mEventData->mDecorator->DelayCursorBlink();
3067 // Discard temporary text
3071 void Controller::TextReplacedEvent()
3073 // The natural size needs to be re-calculated.
3074 mImpl->mRecalculateNaturalSize = true;
3076 // Apply modifications to the model
3077 mImpl->mOperationsPending = ALL_OPERATIONS;
3080 void Controller::TextInsertedEvent()
3082 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
3084 if( NULL == mImpl->mEventData )
3089 mImpl->mEventData->mCheckScrollAmount = true;
3091 // The natural size needs to be re-calculated.
3092 mImpl->mRecalculateNaturalSize = true;
3094 // Apply modifications to the model; TODO - Optimize this
3095 mImpl->mOperationsPending = ALL_OPERATIONS;
3098 void Controller::TextDeletedEvent()
3100 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
3102 if( NULL == mImpl->mEventData )
3107 mImpl->mEventData->mCheckScrollAmount = true;
3109 // The natural size needs to be re-calculated.
3110 mImpl->mRecalculateNaturalSize = true;
3112 // Apply modifications to the model; TODO - Optimize this
3113 mImpl->mOperationsPending = ALL_OPERATIONS;
3116 void Controller::SelectEvent( float x, float y, bool selectAll )
3118 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
3120 if( NULL != mImpl->mEventData )
3124 Event event( Event::SELECT_ALL );
3125 mImpl->mEventData->mEventQueue.push_back( event );
3129 Event event( Event::SELECT );
3130 event.p2.mFloat = x;
3131 event.p3.mFloat = y;
3132 mImpl->mEventData->mEventQueue.push_back( event );
3135 mImpl->mEventData->mCheckScrollAmount = true;
3136 mImpl->mEventData->mIsLeftHandleSelected = true;
3137 mImpl->mEventData->mIsRightHandleSelected = true;
3138 mImpl->RequestRelayout();
3142 bool Controller::BackspaceKeyEvent()
3144 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p DALI_KEY_BACKSPACE\n", this );
3146 bool removed = false;
3148 if( NULL == mImpl->mEventData )
3153 // IMF manager is no longer handling key-events
3154 mImpl->ClearPreEditFlag();
3156 if( EventData::SELECTING == mImpl->mEventData->mState )
3158 removed = RemoveSelectedText();
3160 else if( mImpl->mEventData->mPrimaryCursorPosition > 0 )
3162 // Remove the character before the current cursor position
3163 removed = RemoveText( -1,
3165 UPDATE_INPUT_STYLE );
3170 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3171 !mImpl->IsPlaceholderAvailable() )
3173 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3177 ShowPlaceholderText();
3179 mImpl->mEventData->mUpdateCursorPosition = true;
3180 mImpl->mEventData->mScrollAfterDelete = true;
3186 // private : Helpers.
3188 void Controller::ResetText()
3191 mImpl->mModel->mLogicalModel->mText.Clear();
3193 // We have cleared everything including the placeholder-text
3194 mImpl->PlaceholderCleared();
3196 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3197 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3198 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
3200 // Clear any previous text.
3201 mImpl->mTextUpdateInfo.mClearAll = true;
3203 // The natural size needs to be re-calculated.
3204 mImpl->mRecalculateNaturalSize = true;
3206 // Apply modifications to the model
3207 mImpl->mOperationsPending = ALL_OPERATIONS;
3210 void Controller::ShowPlaceholderText()
3212 if( mImpl->IsPlaceholderAvailable() )
3214 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
3216 if( NULL == mImpl->mEventData )
3221 mImpl->mEventData->mIsShowingPlaceholderText = true;
3223 // Disable handles when showing place-holder text
3224 mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
3225 mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
3226 mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
3228 const char* text( NULL );
3231 if( !mImpl->mEventData->mPlaceholderTextActive.empty() || !mImpl->mEventData->mPlaceholderTextInactive.empty() )
3233 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
3234 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
3236 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
3237 size = mImpl->mEventData->mPlaceholderTextActive.size();
3241 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
3242 size = mImpl->mEventData->mPlaceholderTextInactive.size();
3247 if( 0u != mImpl->mEventData->mPlaceholderText.c_str() )
3249 text = mImpl->mEventData->mPlaceholderText.c_str();
3250 size = mImpl->mEventData->mPlaceholderText.size();
3254 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3255 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3257 // Reset model for showing placeholder.
3258 mImpl->mModel->mLogicalModel->mText.Clear();
3259 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
3261 // Convert text into UTF-32
3262 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
3263 utf32Characters.Resize( size );
3265 // This is a bit horrible but std::string returns a (signed) char*
3266 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
3268 // Transform a text array encoded in utf8 into an array encoded in utf32.
3269 // It returns the actual number of characters.
3270 const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
3271 utf32Characters.Resize( characterCount );
3273 // The characters to be added.
3274 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
3276 // Reset the cursor position
3277 mImpl->mEventData->mPrimaryCursorPosition = 0;
3279 // The natural size needs to be re-calculated.
3280 mImpl->mRecalculateNaturalSize = true;
3282 // Apply modifications to the model
3283 mImpl->mOperationsPending = ALL_OPERATIONS;
3285 // Update the rest of the model during size negotiation
3286 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
3290 void Controller::ClearFontData()
3292 if( mImpl->mFontDefaults )
3294 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
3297 // Set flags to update the model.
3298 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3299 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3300 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
3302 mImpl->mTextUpdateInfo.mClearAll = true;
3303 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
3304 mImpl->mRecalculateNaturalSize = true;
3306 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
3311 UPDATE_LAYOUT_SIZE |
3316 void Controller::ClearStyleData()
3318 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
3319 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
3322 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
3324 // Reset the cursor position
3325 if( NULL != mImpl->mEventData )
3327 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
3329 // Update the cursor if it's in editing mode.
3330 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
3332 mImpl->mEventData->mUpdateCursorPosition = true;
3337 void Controller::ResetScrollPosition()
3339 if( NULL != mImpl->mEventData )
3341 // Reset the scroll position.
3342 mImpl->mModel->mScrollPosition = Vector2::ZERO;
3343 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3347 // private : Private contructors & copy operator.
3349 Controller::Controller()
3352 mImpl = new Controller::Impl( NULL, NULL );
3355 Controller::Controller( ControlInterface* controlInterface )
3357 mImpl = new Controller::Impl( controlInterface, NULL );
3360 Controller::Controller( ControlInterface* controlInterface,
3361 EditableControlInterface* editableControlInterface )
3363 mImpl = new Controller::Impl( controlInterface,
3364 editableControlInterface );
3367 // The copy constructor and operator are left unimplemented.
3369 // protected : Destructor.
3371 Controller::~Controller()
3378 } // namespace Toolkit