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/multi-language-support.h>
35 #include <dali-toolkit/internal/text/text-controller-impl.h>
36 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
37 #include <dali-toolkit/internal/text/text-font-style.h>
42 #if defined(DEBUG_ENABLED)
43 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
46 const float MAX_FLOAT = std::numeric_limits<float>::max();
48 const std::string EMPTY_STRING("");
50 const char * const PLACEHOLDER_TEXT = "placeholderText";
51 const char * const PLACEHOLDER_TEXT_FOCUSED = "placeholderTextFocused";
52 const char * const PLACEHOLDER_COLOR = "placeholderColor";
53 const char * const PLACEHOLDER_FONT_FAMILY = "placeholderFontFamily";
54 const char * const PLACEHOLDER_FONT_STYLE = "placeholderFontStyle";
55 const char * const PLACEHOLDER_POINT_SIZE = "placeholderPointSize";
56 const char * const PLACEHOLDER_PIXEL_SIZE = "placeholderPixelSize";
58 float ConvertToEven( float value )
60 int intValue(static_cast<int>( value ));
61 return static_cast<float>(intValue % 2 == 0) ? intValue : (intValue + 1);
76 * @brief Adds a new font description run for the selected text.
78 * The new font parameters are added after the call to this method.
80 * @param[in] eventData The event data pointer.
81 * @param[in] logicalModel The logical model where to add the new font description run.
82 * @param[out] startOfSelectedText Index to the first selected character.
83 * @param[out] lengthOfSelectedText Number of selected characters.
85 FontDescriptionRun& UpdateSelectionFontStyleRun( EventData* eventData,
86 LogicalModelPtr logicalModel,
87 CharacterIndex& startOfSelectedText,
88 Length& lengthOfSelectedText )
90 const bool handlesCrossed = eventData->mLeftSelectionPosition > eventData->mRightSelectionPosition;
92 // Get start and end position of selection
93 startOfSelectedText = handlesCrossed ? eventData->mRightSelectionPosition : eventData->mLeftSelectionPosition;
94 lengthOfSelectedText = ( handlesCrossed ? eventData->mLeftSelectionPosition : eventData->mRightSelectionPosition ) - startOfSelectedText;
97 const VectorBase::SizeType numberOfRuns = logicalModel->mFontDescriptionRuns.Count();
98 logicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
100 FontDescriptionRun& fontDescriptionRun = *( logicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
102 fontDescriptionRun.characterRun.characterIndex = startOfSelectedText;
103 fontDescriptionRun.characterRun.numberOfCharacters = lengthOfSelectedText;
105 // Recalculate the selection highlight as the metrics may have changed.
106 eventData->mUpdateLeftSelectionPosition = true;
107 eventData->mUpdateRightSelectionPosition = true;
108 eventData->mUpdateHighlightBox = true;
110 return fontDescriptionRun;
113 // public : Constructor.
115 ControllerPtr Controller::New()
117 return ControllerPtr( new Controller() );
120 ControllerPtr Controller::New( ControlInterface* controlInterface )
122 return ControllerPtr( new Controller( controlInterface ) );
125 ControllerPtr Controller::New( ControlInterface* controlInterface,
126 EditableControlInterface* editableControlInterface )
128 return ControllerPtr( new Controller( controlInterface,
129 editableControlInterface ) );
132 // public : Configure the text controller.
134 void Controller::EnableTextInput( DecoratorPtr decorator )
138 delete mImpl->mEventData;
139 mImpl->mEventData = NULL;
141 // Nothing else to do.
145 if( NULL == mImpl->mEventData )
147 mImpl->mEventData = new EventData( decorator );
151 void Controller::SetGlyphType( TextAbstraction::GlyphType glyphType )
153 // Metrics for bitmap & vector based glyphs are different
154 mImpl->mMetrics->SetGlyphType( glyphType );
156 // Clear the font-specific data
159 mImpl->RequestRelayout();
162 void Controller::SetMarkupProcessorEnabled( bool enable )
164 mImpl->mMarkupProcessorEnabled = enable;
167 bool Controller::IsMarkupProcessorEnabled() const
169 return mImpl->mMarkupProcessorEnabled;
172 void Controller::SetAutoScrollEnabled( bool enable )
174 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 );
176 if( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX )
180 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled for SINGLE_LINE_BOX\n" );
181 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
191 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled Disabling autoscroll\n");
192 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
199 mImpl->mIsAutoScrollEnabled = enable;
200 mImpl->RequestRelayout();
204 DALI_LOG_WARNING( "Attempted AutoScrolling on a non SINGLE_LINE_BOX, request ignored\n" );
205 mImpl->mIsAutoScrollEnabled = false;
209 bool Controller::IsAutoScrollEnabled() const
211 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::IsAutoScrollEnabled[%s]\n", mImpl->mIsAutoScrollEnabled?"true":"false" );
213 return mImpl->mIsAutoScrollEnabled;
216 CharacterDirection Controller::GetAutoScrollDirection() const
218 return mImpl->mAutoScrollDirectionRTL;
221 float Controller::GetAutoScrollLineAlignment() const
225 if( mImpl->mModel->mVisualModel &&
226 ( 0u != mImpl->mModel->mVisualModel->mLines.Count() ) )
228 offset = ( *mImpl->mModel->mVisualModel->mLines.Begin() ).alignmentOffset;
234 void Controller::SetHorizontalScrollEnabled( bool enable )
236 if( ( NULL != mImpl->mEventData ) &&
237 mImpl->mEventData->mDecorator )
239 mImpl->mEventData->mDecorator->SetHorizontalScrollEnabled( enable );
242 bool Controller::IsHorizontalScrollEnabled() const
244 if( ( NULL != mImpl->mEventData ) &&
245 mImpl->mEventData->mDecorator )
247 return mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
253 void Controller::SetVerticalScrollEnabled( bool enable )
255 if( ( NULL != mImpl->mEventData ) &&
256 mImpl->mEventData->mDecorator )
258 if( mImpl->mEventData->mDecorator )
260 mImpl->mEventData->mDecorator->SetVerticalScrollEnabled( enable );
265 bool Controller::IsVerticalScrollEnabled() const
267 if( ( NULL != mImpl->mEventData ) &&
268 mImpl->mEventData->mDecorator )
270 return mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
276 void Controller::SetSmoothHandlePanEnabled( bool enable )
278 if( ( NULL != mImpl->mEventData ) &&
279 mImpl->mEventData->mDecorator )
281 mImpl->mEventData->mDecorator->SetSmoothHandlePanEnabled( enable );
285 bool Controller::IsSmoothHandlePanEnabled() const
287 if( ( NULL != mImpl->mEventData ) &&
288 mImpl->mEventData->mDecorator )
290 return mImpl->mEventData->mDecorator->IsSmoothHandlePanEnabled();
296 void Controller::SetMaximumNumberOfCharacters( Length maxCharacters )
298 mImpl->mMaximumNumberOfCharacters = maxCharacters;
301 int Controller::GetMaximumNumberOfCharacters()
303 return mImpl->mMaximumNumberOfCharacters;
306 void Controller::SetEnableCursorBlink( bool enable )
308 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "TextInput disabled" );
310 if( NULL != mImpl->mEventData )
312 mImpl->mEventData->mCursorBlinkEnabled = enable;
315 mImpl->mEventData->mDecorator )
317 mImpl->mEventData->mDecorator->StopCursorBlink();
322 bool Controller::GetEnableCursorBlink() const
324 if( NULL != mImpl->mEventData )
326 return mImpl->mEventData->mCursorBlinkEnabled;
332 void Controller::SetMultiLineEnabled( bool enable )
334 const Layout::Engine::Type layout = enable ? Layout::Engine::MULTI_LINE_BOX : Layout::Engine::SINGLE_LINE_BOX;
336 if( layout != mImpl->mLayoutEngine.GetLayout() )
338 // Set the layout type.
339 mImpl->mLayoutEngine.SetLayout( layout );
341 // Set the flags to redo the layout operations
342 const OperationsMask layoutOperations = static_cast<OperationsMask>( LAYOUT |
347 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | layoutOperations );
349 mImpl->RequestRelayout();
353 bool Controller::IsMultiLineEnabled() const
355 return Layout::Engine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
358 void Controller::SetHorizontalAlignment( Layout::HorizontalAlignment alignment )
360 if( alignment != mImpl->mModel->mHorizontalAlignment )
362 // Set the alignment.
363 mImpl->mModel->mHorizontalAlignment = alignment;
365 // Set the flag to redo the alignment operation.
366 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
368 mImpl->RequestRelayout();
372 Layout::HorizontalAlignment Controller::GetHorizontalAlignment() const
374 return mImpl->mModel->mHorizontalAlignment;
377 void Controller::SetVerticalAlignment( Layout::VerticalAlignment alignment )
379 if( alignment != mImpl->mModel->mVerticalAlignment )
381 // Set the alignment.
382 mImpl->mModel->mVerticalAlignment = alignment;
384 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
386 mImpl->RequestRelayout();
390 Layout::VerticalAlignment Controller::GetVerticalAlignment() const
392 return mImpl->mModel->mVerticalAlignment;
395 void Controller::SetLineWrapMode( Layout::LineWrap::Mode lineWrapMode )
397 if( lineWrapMode != mImpl->mModel->mLineWrapMode )
399 // Set the text wrap mode.
400 mImpl->mModel->mLineWrapMode = lineWrapMode;
403 // Update Text layout for applying wrap mode
404 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
409 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
410 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
411 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
414 mImpl->RequestRelayout();
418 Layout::LineWrap::Mode Controller::GetLineWrapMode() const
420 return mImpl->mModel->mLineWrapMode;
423 void Controller::SetTextElideEnabled( bool enabled )
425 mImpl->mModel->mElideEnabled = enabled;
428 bool Controller::IsTextElideEnabled() const
430 return mImpl->mModel->mElideEnabled;
433 void Controller::SetSelectionEnabled( bool enabled )
435 mImpl->mEventData->mSelectionEnabled = enabled;
438 bool Controller::IsSelectionEnabled() const
440 return mImpl->mEventData->mSelectionEnabled;
445 void Controller::SetText( const std::string& text )
447 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" );
449 // Reset keyboard as text changed
450 mImpl->ResetImfManager();
452 // Remove the previously set text and style.
458 CharacterIndex lastCursorIndex = 0u;
460 if( NULL != mImpl->mEventData )
462 // If popup shown then hide it by switching to Editing state
463 if( ( EventData::SELECTING == mImpl->mEventData->mState ) ||
464 ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
465 ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) ||
466 ( EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState ) )
468 mImpl->ChangeState( EventData::EDITING );
474 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mTextColor );
476 MarkupProcessData markupProcessData( mImpl->mModel->mLogicalModel->mColorRuns,
477 mImpl->mModel->mLogicalModel->mFontDescriptionRuns );
479 Length textSize = 0u;
480 const uint8_t* utf8 = NULL;
481 if( mImpl->mMarkupProcessorEnabled )
483 ProcessMarkupString( text, markupProcessData );
484 textSize = markupProcessData.markupProcessedText.size();
486 // This is a bit horrible but std::string returns a (signed) char*
487 utf8 = reinterpret_cast<const uint8_t*>( markupProcessData.markupProcessedText.c_str() );
491 textSize = text.size();
493 // This is a bit horrible but std::string returns a (signed) char*
494 utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
497 // Convert text into UTF-32
498 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
499 utf32Characters.Resize( textSize );
501 // Transform a text array encoded in utf8 into an array encoded in utf32.
502 // It returns the actual number of characters.
503 Length characterCount = Utf8ToUtf32( utf8, textSize, utf32Characters.Begin() );
504 utf32Characters.Resize( characterCount );
506 DALI_ASSERT_DEBUG( textSize >= characterCount && "Invalid UTF32 conversion length" );
507 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", this, textSize, mImpl->mModel->mLogicalModel->mText.Count() );
509 // The characters to be added.
510 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
512 // To reset the cursor position
513 lastCursorIndex = characterCount;
515 // Update the rest of the model during size negotiation
516 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
518 // The natural size needs to be re-calculated.
519 mImpl->mRecalculateNaturalSize = true;
521 // Apply modifications to the model
522 mImpl->mOperationsPending = ALL_OPERATIONS;
526 ShowPlaceholderText();
529 // Resets the cursor position.
530 ResetCursorPosition( lastCursorIndex );
532 // Scrolls the text to make the cursor visible.
533 ResetScrollPosition();
535 mImpl->RequestRelayout();
537 if( NULL != mImpl->mEventData )
539 // Cancel previously queued events
540 mImpl->mEventData->mEventQueue.clear();
543 // Do this last since it provides callbacks into application code.
544 if( NULL != mImpl->mEditableControlInterface )
546 mImpl->mEditableControlInterface->TextChanged();
550 void Controller::GetText( std::string& text ) const
552 if( !mImpl->IsShowingPlaceholderText() )
554 // Retrieves the text string.
555 mImpl->GetText( 0u, text );
559 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this );
563 void Controller::SetPlaceholderText( PlaceholderType type, const std::string& text )
565 if( NULL != mImpl->mEventData )
567 if( PLACEHOLDER_TYPE_INACTIVE == type )
569 mImpl->mEventData->mPlaceholderTextInactive = text;
573 mImpl->mEventData->mPlaceholderTextActive = text;
576 // Update placeholder if there is no text
577 if( mImpl->IsShowingPlaceholderText() ||
578 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
580 ShowPlaceholderText();
585 void Controller::GetPlaceholderText( PlaceholderType type, std::string& text ) const
587 if( NULL != mImpl->mEventData )
589 if( PLACEHOLDER_TYPE_INACTIVE == type )
591 text = mImpl->mEventData->mPlaceholderTextInactive;
595 text = mImpl->mEventData->mPlaceholderTextActive;
600 void Controller::UpdateAfterFontChange( const std::string& newDefaultFont )
602 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
604 if( !mImpl->mFontDefaults->familyDefined ) // If user defined font then should not update when system font changes
606 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
607 mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
611 mImpl->RequestRelayout();
615 // public : Default style & Input style
617 void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
619 if( NULL == mImpl->mFontDefaults )
621 mImpl->mFontDefaults = new FontDefaults();
624 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
625 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
626 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
628 // Clear the font-specific data
631 mImpl->RequestRelayout();
634 const std::string& Controller::GetDefaultFontFamily() const
636 if( NULL != mImpl->mFontDefaults )
638 return mImpl->mFontDefaults->mFontDescription.family;
644 void Controller::SetPlaceholderFontFamily( const std::string& placeholderTextFontFamily )
646 if( NULL != mImpl->mEventData )
648 if( NULL == mImpl->mEventData->mPlaceholderFont )
650 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
653 mImpl->mEventData->mPlaceholderFont->mFontDescription.family = placeholderTextFontFamily;
654 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetPlaceholderFontFamily %s\n", placeholderTextFontFamily.c_str());
655 mImpl->mEventData->mPlaceholderFont->familyDefined = !placeholderTextFontFamily.empty();
657 mImpl->RequestRelayout();
661 const std::string& Controller::GetPlaceholderFontFamily() const
663 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
665 return mImpl->mEventData->mPlaceholderFont->mFontDescription.family;
671 void Controller::SetDefaultFontWeight( FontWeight weight )
673 if( NULL == mImpl->mFontDefaults )
675 mImpl->mFontDefaults = new FontDefaults();
678 mImpl->mFontDefaults->mFontDescription.weight = weight;
679 mImpl->mFontDefaults->weightDefined = true;
681 // Clear the font-specific data
684 mImpl->RequestRelayout();
687 bool Controller::IsDefaultFontWeightDefined() const
689 if( NULL != mImpl->mFontDefaults )
691 return mImpl->mFontDefaults->weightDefined;
697 FontWeight Controller::GetDefaultFontWeight() const
699 if( NULL != mImpl->mFontDefaults )
701 return mImpl->mFontDefaults->mFontDescription.weight;
704 return TextAbstraction::FontWeight::NORMAL;
707 void Controller::SetPlaceholderTextFontWeight( FontWeight weight )
709 if( NULL != mImpl->mEventData )
711 if( NULL == mImpl->mEventData->mPlaceholderFont )
713 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
716 mImpl->mEventData->mPlaceholderFont->mFontDescription.weight = weight;
717 mImpl->mEventData->mPlaceholderFont->weightDefined = true;
719 mImpl->RequestRelayout();
723 bool Controller::IsPlaceholderTextFontWeightDefined() const
725 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
727 return mImpl->mEventData->mPlaceholderFont->weightDefined;
732 FontWeight Controller::GetPlaceholderTextFontWeight() const
734 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
736 return mImpl->mEventData->mPlaceholderFont->mFontDescription.weight;
739 return TextAbstraction::FontWeight::NORMAL;
742 void Controller::SetDefaultFontWidth( FontWidth width )
744 if( NULL == mImpl->mFontDefaults )
746 mImpl->mFontDefaults = new FontDefaults();
749 mImpl->mFontDefaults->mFontDescription.width = width;
750 mImpl->mFontDefaults->widthDefined = true;
752 // Clear the font-specific data
755 mImpl->RequestRelayout();
758 bool Controller::IsDefaultFontWidthDefined() const
760 if( NULL != mImpl->mFontDefaults )
762 return mImpl->mFontDefaults->widthDefined;
768 FontWidth Controller::GetDefaultFontWidth() const
770 if( NULL != mImpl->mFontDefaults )
772 return mImpl->mFontDefaults->mFontDescription.width;
775 return TextAbstraction::FontWidth::NORMAL;
778 void Controller::SetPlaceholderTextFontWidth( FontWidth width )
780 if( NULL != mImpl->mEventData )
782 if( NULL == mImpl->mEventData->mPlaceholderFont )
784 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
787 mImpl->mEventData->mPlaceholderFont->mFontDescription.width = width;
788 mImpl->mEventData->mPlaceholderFont->widthDefined = true;
790 mImpl->RequestRelayout();
794 bool Controller::IsPlaceholderTextFontWidthDefined() const
796 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
798 return mImpl->mEventData->mPlaceholderFont->widthDefined;
803 FontWidth Controller::GetPlaceholderTextFontWidth() const
805 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
807 return mImpl->mEventData->mPlaceholderFont->mFontDescription.width;
810 return TextAbstraction::FontWidth::NORMAL;
813 void Controller::SetDefaultFontSlant( FontSlant slant )
815 if( NULL == mImpl->mFontDefaults )
817 mImpl->mFontDefaults = new FontDefaults();
820 mImpl->mFontDefaults->mFontDescription.slant = slant;
821 mImpl->mFontDefaults->slantDefined = true;
823 // Clear the font-specific data
826 mImpl->RequestRelayout();
829 bool Controller::IsDefaultFontSlantDefined() const
831 if( NULL != mImpl->mFontDefaults )
833 return mImpl->mFontDefaults->slantDefined;
838 FontSlant Controller::GetDefaultFontSlant() const
840 if( NULL != mImpl->mFontDefaults )
842 return mImpl->mFontDefaults->mFontDescription.slant;
845 return TextAbstraction::FontSlant::NORMAL;
848 void Controller::SetPlaceholderTextFontSlant( FontSlant slant )
850 if( NULL != mImpl->mEventData )
852 if( NULL == mImpl->mEventData->mPlaceholderFont )
854 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
857 mImpl->mEventData->mPlaceholderFont->mFontDescription.slant = slant;
858 mImpl->mEventData->mPlaceholderFont->slantDefined = true;
860 mImpl->RequestRelayout();
864 bool Controller::IsPlaceholderTextFontSlantDefined() const
866 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
868 return mImpl->mEventData->mPlaceholderFont->slantDefined;
873 FontSlant Controller::GetPlaceholderTextFontSlant() const
875 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
877 return mImpl->mEventData->mPlaceholderFont->mFontDescription.slant;
880 return TextAbstraction::FontSlant::NORMAL;
883 void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
885 if( NULL == mImpl->mFontDefaults )
887 mImpl->mFontDefaults = new FontDefaults();
894 mImpl->mFontDefaults->mDefaultPointSize = fontSize;
895 mImpl->mFontDefaults->sizeDefined = true;
900 // Point size = Pixel size * 72.f / DPI
901 unsigned int horizontalDpi = 0u;
902 unsigned int verticalDpi = 0u;
903 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
904 fontClient.GetDpi( horizontalDpi, verticalDpi );
906 mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
907 mImpl->mFontDefaults->sizeDefined = true;
912 // Clear the font-specific data
915 mImpl->RequestRelayout();
918 float Controller::GetDefaultFontSize( FontSizeType type ) const
921 if( NULL != mImpl->mFontDefaults )
927 value = mImpl->mFontDefaults->mDefaultPointSize;
932 // Pixel size = Point size * DPI / 72.f
933 unsigned int horizontalDpi = 0u;
934 unsigned int verticalDpi = 0u;
935 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
936 fontClient.GetDpi( horizontalDpi, verticalDpi );
938 value = mImpl->mFontDefaults->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
948 void Controller::SetPlaceholderTextFontSize( float fontSize, FontSizeType type )
950 if( NULL != mImpl->mEventData )
952 if( NULL == mImpl->mEventData->mPlaceholderFont )
954 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
961 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = fontSize;
962 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
963 mImpl->mEventData->mIsPlaceholderPixelSize = false; // Font size flag
968 // Point size = Pixel size * 72.f / DPI
969 unsigned int horizontalDpi = 0u;
970 unsigned int verticalDpi = 0u;
971 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
972 fontClient.GetDpi( horizontalDpi, verticalDpi );
974 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
975 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
976 mImpl->mEventData->mIsPlaceholderPixelSize = true; // Font size flag
981 mImpl->RequestRelayout();
985 float Controller::GetPlaceholderTextFontSize( FontSizeType type ) const
988 if( NULL != mImpl->mEventData )
994 if( NULL != mImpl->mEventData->mPlaceholderFont )
996 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize;
1000 // If the placeholder text font size is not set, then return the default font size.
1001 value = GetDefaultFontSize( POINT_SIZE );
1007 if( NULL != mImpl->mEventData->mPlaceholderFont )
1009 // Pixel size = Point size * DPI / 72.f
1010 unsigned int horizontalDpi = 0u;
1011 unsigned int verticalDpi = 0u;
1012 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1013 fontClient.GetDpi( horizontalDpi, verticalDpi );
1015 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1019 // If the placeholder text font size is not set, then return the default font size.
1020 value = GetDefaultFontSize( PIXEL_SIZE );
1031 void Controller::SetDefaultColor( const Vector4& color )
1033 mImpl->mTextColor = color;
1035 if( !mImpl->IsShowingPlaceholderText() )
1037 mImpl->mModel->mVisualModel->SetTextColor( color );
1039 mImpl->RequestRelayout();
1043 const Vector4& Controller::GetDefaultColor() const
1045 return mImpl->mTextColor;
1048 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
1050 if( NULL != mImpl->mEventData )
1052 mImpl->mEventData->mPlaceholderTextColor = textColor;
1055 if( mImpl->IsShowingPlaceholderText() )
1057 mImpl->mModel->mVisualModel->SetTextColor( textColor );
1058 mImpl->RequestRelayout();
1062 const Vector4& Controller::GetPlaceholderTextColor() const
1064 if( NULL != mImpl->mEventData )
1066 return mImpl->mEventData->mPlaceholderTextColor;
1069 return Color::BLACK;
1072 void Controller::SetShadowOffset( const Vector2& shadowOffset )
1074 mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
1076 mImpl->RequestRelayout();
1079 const Vector2& Controller::GetShadowOffset() const
1081 return mImpl->mModel->mVisualModel->GetShadowOffset();
1084 void Controller::SetShadowColor( const Vector4& shadowColor )
1086 mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
1088 mImpl->RequestRelayout();
1091 const Vector4& Controller::GetShadowColor() const
1093 return mImpl->mModel->mVisualModel->GetShadowColor();
1096 void Controller::SetUnderlineColor( const Vector4& color )
1098 mImpl->mModel->mVisualModel->SetUnderlineColor( color );
1100 mImpl->RequestRelayout();
1103 const Vector4& Controller::GetUnderlineColor() const
1105 return mImpl->mModel->mVisualModel->GetUnderlineColor();
1108 void Controller::SetUnderlineEnabled( bool enabled )
1110 mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
1112 mImpl->RequestRelayout();
1115 bool Controller::IsUnderlineEnabled() const
1117 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
1120 void Controller::SetUnderlineHeight( float height )
1122 mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
1124 mImpl->RequestRelayout();
1127 float Controller::GetUnderlineHeight() const
1129 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
1132 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
1134 if( NULL == mImpl->mEmbossDefaults )
1136 mImpl->mEmbossDefaults = new EmbossDefaults();
1139 mImpl->mEmbossDefaults->properties = embossProperties;
1142 const std::string& Controller::GetDefaultEmbossProperties() const
1144 if( NULL != mImpl->mEmbossDefaults )
1146 return mImpl->mEmbossDefaults->properties;
1149 return EMPTY_STRING;
1152 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
1154 if( NULL == mImpl->mOutlineDefaults )
1156 mImpl->mOutlineDefaults = new OutlineDefaults();
1159 mImpl->mOutlineDefaults->properties = outlineProperties;
1162 const std::string& Controller::GetDefaultOutlineProperties() const
1164 if( NULL != mImpl->mOutlineDefaults )
1166 return mImpl->mOutlineDefaults->properties;
1169 return EMPTY_STRING;
1172 void Controller::SetDefaultLineSpacing( float lineSpacing )
1174 //TODO finish implementation
1175 mImpl->mLayoutEngine.SetDefaultLineSpacing( lineSpacing );
1178 float Controller::GetDefaultLineSpacing() const
1180 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
1183 void Controller::SetInputColor( const Vector4& color )
1185 if( NULL != mImpl->mEventData )
1187 mImpl->mEventData->mInputStyle.textColor = color;
1188 mImpl->mEventData->mInputStyle.isDefaultColor = false;
1190 if( EventData::SELECTING == mImpl->mEventData->mState )
1192 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
1194 // Get start and end position of selection
1195 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
1196 const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
1198 // Add the color run.
1199 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1200 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
1202 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
1203 colorRun.color = color;
1204 colorRun.characterRun.characterIndex = startOfSelectedText;
1205 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1207 // Request to relayout.
1208 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1209 mImpl->RequestRelayout();
1211 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1212 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1213 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1218 const Vector4& Controller::GetInputColor() const
1220 if( NULL != mImpl->mEventData )
1222 return mImpl->mEventData->mInputStyle.textColor;
1225 // Return the default text's color if there is no EventData.
1226 return mImpl->mTextColor;
1230 void Controller::SetInputFontFamily( const std::string& fontFamily )
1232 if( NULL != mImpl->mEventData )
1234 mImpl->mEventData->mInputStyle.familyName = fontFamily;
1235 mImpl->mEventData->mInputStyle.isFamilyDefined = true;
1237 if( EventData::SELECTING == mImpl->mEventData->mState )
1239 CharacterIndex startOfSelectedText = 0u;
1240 Length lengthOfSelectedText = 0u;
1241 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1242 mImpl->mModel->mLogicalModel,
1243 startOfSelectedText,
1244 lengthOfSelectedText );
1246 fontDescriptionRun.familyLength = fontFamily.size();
1247 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
1248 memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength );
1249 fontDescriptionRun.familyDefined = true;
1251 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
1253 // Request to relayout.
1254 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1259 UPDATE_LAYOUT_SIZE |
1262 mImpl->mRecalculateNaturalSize = true;
1263 mImpl->RequestRelayout();
1265 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1266 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1267 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1269 // As the font changes, recalculate the handle positions is needed.
1270 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1271 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1272 mImpl->mEventData->mUpdateHighlightBox = true;
1273 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1278 const std::string& Controller::GetInputFontFamily() const
1280 if( NULL != mImpl->mEventData )
1282 return mImpl->mEventData->mInputStyle.familyName;
1285 // Return the default font's family if there is no EventData.
1286 return GetDefaultFontFamily();
1289 void Controller::SetInputFontWeight( FontWeight weight )
1291 if( NULL != mImpl->mEventData )
1293 mImpl->mEventData->mInputStyle.weight = weight;
1294 mImpl->mEventData->mInputStyle.isWeightDefined = true;
1296 if( EventData::SELECTING == mImpl->mEventData->mState )
1298 CharacterIndex startOfSelectedText = 0u;
1299 Length lengthOfSelectedText = 0u;
1300 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1301 mImpl->mModel->mLogicalModel,
1302 startOfSelectedText,
1303 lengthOfSelectedText );
1305 fontDescriptionRun.weight = weight;
1306 fontDescriptionRun.weightDefined = true;
1308 // Request to relayout.
1309 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1314 UPDATE_LAYOUT_SIZE |
1317 mImpl->mRecalculateNaturalSize = true;
1318 mImpl->RequestRelayout();
1320 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1321 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1322 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1324 // As the font might change, recalculate the handle positions is needed.
1325 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1326 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1327 mImpl->mEventData->mUpdateHighlightBox = true;
1328 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1333 bool Controller::IsInputFontWeightDefined() const
1335 bool defined = false;
1337 if( NULL != mImpl->mEventData )
1339 defined = mImpl->mEventData->mInputStyle.isWeightDefined;
1345 FontWeight Controller::GetInputFontWeight() const
1347 if( NULL != mImpl->mEventData )
1349 return mImpl->mEventData->mInputStyle.weight;
1352 return GetDefaultFontWeight();
1355 void Controller::SetInputFontWidth( FontWidth width )
1357 if( NULL != mImpl->mEventData )
1359 mImpl->mEventData->mInputStyle.width = width;
1360 mImpl->mEventData->mInputStyle.isWidthDefined = true;
1362 if( EventData::SELECTING == mImpl->mEventData->mState )
1364 CharacterIndex startOfSelectedText = 0u;
1365 Length lengthOfSelectedText = 0u;
1366 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1367 mImpl->mModel->mLogicalModel,
1368 startOfSelectedText,
1369 lengthOfSelectedText );
1371 fontDescriptionRun.width = width;
1372 fontDescriptionRun.widthDefined = true;
1374 // Request to relayout.
1375 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1380 UPDATE_LAYOUT_SIZE |
1383 mImpl->mRecalculateNaturalSize = true;
1384 mImpl->RequestRelayout();
1386 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1387 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1388 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1390 // As the font might change, recalculate the handle positions is needed.
1391 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1392 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1393 mImpl->mEventData->mUpdateHighlightBox = true;
1394 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1399 bool Controller::IsInputFontWidthDefined() const
1401 bool defined = false;
1403 if( NULL != mImpl->mEventData )
1405 defined = mImpl->mEventData->mInputStyle.isWidthDefined;
1411 FontWidth Controller::GetInputFontWidth() const
1413 if( NULL != mImpl->mEventData )
1415 return mImpl->mEventData->mInputStyle.width;
1418 return GetDefaultFontWidth();
1421 void Controller::SetInputFontSlant( FontSlant slant )
1423 if( NULL != mImpl->mEventData )
1425 mImpl->mEventData->mInputStyle.slant = slant;
1426 mImpl->mEventData->mInputStyle.isSlantDefined = true;
1428 if( EventData::SELECTING == mImpl->mEventData->mState )
1430 CharacterIndex startOfSelectedText = 0u;
1431 Length lengthOfSelectedText = 0u;
1432 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1433 mImpl->mModel->mLogicalModel,
1434 startOfSelectedText,
1435 lengthOfSelectedText );
1437 fontDescriptionRun.slant = slant;
1438 fontDescriptionRun.slantDefined = true;
1440 // Request to relayout.
1441 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1446 UPDATE_LAYOUT_SIZE |
1449 mImpl->mRecalculateNaturalSize = true;
1450 mImpl->RequestRelayout();
1452 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1453 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1454 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1456 // As the font might change, recalculate the handle positions is needed.
1457 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1458 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1459 mImpl->mEventData->mUpdateHighlightBox = true;
1460 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1465 bool Controller::IsInputFontSlantDefined() const
1467 bool defined = false;
1469 if( NULL != mImpl->mEventData )
1471 defined = mImpl->mEventData->mInputStyle.isSlantDefined;
1477 FontSlant Controller::GetInputFontSlant() const
1479 if( NULL != mImpl->mEventData )
1481 return mImpl->mEventData->mInputStyle.slant;
1484 return GetDefaultFontSlant();
1487 void Controller::SetInputFontPointSize( float size )
1489 if( NULL != mImpl->mEventData )
1491 mImpl->mEventData->mInputStyle.size = size;
1492 mImpl->mEventData->mInputStyle.isSizeDefined = true;
1494 if( EventData::SELECTING == mImpl->mEventData->mState )
1496 CharacterIndex startOfSelectedText = 0u;
1497 Length lengthOfSelectedText = 0u;
1498 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1499 mImpl->mModel->mLogicalModel,
1500 startOfSelectedText,
1501 lengthOfSelectedText );
1503 fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
1504 fontDescriptionRun.sizeDefined = true;
1506 // Request to relayout.
1507 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1512 UPDATE_LAYOUT_SIZE |
1515 mImpl->mRecalculateNaturalSize = true;
1516 mImpl->RequestRelayout();
1518 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1519 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1520 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1522 // As the font might change, recalculate the handle positions is needed.
1523 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1524 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1525 mImpl->mEventData->mUpdateHighlightBox = true;
1526 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1531 float Controller::GetInputFontPointSize() const
1533 if( NULL != mImpl->mEventData )
1535 return mImpl->mEventData->mInputStyle.size;
1538 // Return the default font's point size if there is no EventData.
1539 return GetDefaultFontSize( Text::Controller::POINT_SIZE );
1542 void Controller::SetInputLineSpacing( float lineSpacing )
1544 if( NULL != mImpl->mEventData )
1546 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1547 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1551 float Controller::GetInputLineSpacing() const
1553 if( NULL != mImpl->mEventData )
1555 return mImpl->mEventData->mInputStyle.lineSpacing;
1561 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1563 if( NULL != mImpl->mEventData )
1565 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1569 const std::string& Controller::GetInputShadowProperties() const
1571 if( NULL != mImpl->mEventData )
1573 return mImpl->mEventData->mInputStyle.shadowProperties;
1576 return EMPTY_STRING;
1579 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1581 if( NULL != mImpl->mEventData )
1583 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1587 const std::string& Controller::GetInputUnderlineProperties() const
1589 if( NULL != mImpl->mEventData )
1591 return mImpl->mEventData->mInputStyle.underlineProperties;
1594 return EMPTY_STRING;
1597 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
1599 if( NULL != mImpl->mEventData )
1601 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1605 const std::string& Controller::GetInputEmbossProperties() const
1607 if( NULL != mImpl->mEventData )
1609 return mImpl->mEventData->mInputStyle.embossProperties;
1612 return GetDefaultEmbossProperties();
1615 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
1617 if( NULL != mImpl->mEventData )
1619 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1623 const std::string& Controller::GetInputOutlineProperties() const
1625 if( NULL != mImpl->mEventData )
1627 return mImpl->mEventData->mInputStyle.outlineProperties;
1630 return GetDefaultOutlineProperties();
1633 void Controller::SetInputModePassword( bool passwordInput )
1635 if( NULL != mImpl->mEventData )
1637 mImpl->mEventData->mPasswordInput = passwordInput;
1641 bool Controller::IsInputModePassword()
1643 if( NULL != mImpl->mEventData )
1645 return mImpl->mEventData->mPasswordInput;
1650 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
1652 if( NULL != mImpl->mEventData )
1654 mImpl->mEventData->mDoubleTapAction = action;
1658 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1660 NoTextTap::Action action = NoTextTap::NO_ACTION;
1662 if( NULL != mImpl->mEventData )
1664 action = mImpl->mEventData->mDoubleTapAction;
1670 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
1672 if( NULL != mImpl->mEventData )
1674 mImpl->mEventData->mLongPressAction = action;
1678 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1680 NoTextTap::Action action = NoTextTap::NO_ACTION;
1682 if( NULL != mImpl->mEventData )
1684 action = mImpl->mEventData->mLongPressAction;
1690 bool Controller::IsUnderlineSetByString()
1692 return mImpl->mUnderlineSetByString;
1695 void Controller::UnderlineSetByString( bool setByString )
1697 mImpl->mUnderlineSetByString = setByString;
1700 bool Controller::IsShadowSetByString()
1702 return mImpl->mShadowSetByString;
1705 void Controller::ShadowSetByString( bool setByString )
1707 mImpl->mShadowSetByString = setByString;
1710 bool Controller::IsFontStyleSetByString()
1712 return mImpl->mFontStyleSetByString;
1715 void Controller::FontStyleSetByString( bool setByString )
1717 mImpl->mFontStyleSetByString = setByString;
1720 // public : Queries & retrieves.
1722 Layout::Engine& Controller::GetLayoutEngine()
1724 return mImpl->mLayoutEngine;
1727 View& Controller::GetView()
1729 return mImpl->mView;
1732 Vector3 Controller::GetNaturalSize()
1734 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
1735 Vector3 naturalSize;
1737 // Make sure the model is up-to-date before layouting
1738 ProcessModifyEvents();
1740 if( mImpl->mRecalculateNaturalSize )
1742 // Operations that can be done only once until the text changes.
1743 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1750 GET_GLYPH_METRICS );
1752 // Set the update info to relayout the whole text.
1753 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1754 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1756 // Make sure the model is up-to-date before layouting
1757 mImpl->UpdateModel( onlyOnceOperations );
1759 // Layout the text for the new width.
1760 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT | REORDER );
1762 // Store the actual control's size to restore later.
1763 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
1765 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
1766 static_cast<OperationsMask>( onlyOnceOperations |
1768 naturalSize.GetVectorXY() );
1770 // Do not do again the only once operations.
1771 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1773 // Do the size related operations again.
1774 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1777 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1779 // Stores the natural size to avoid recalculate it again
1780 // unless the text/style changes.
1781 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
1783 mImpl->mRecalculateNaturalSize = false;
1785 // Clear the update info. This info will be set the next time the text is updated.
1786 mImpl->mTextUpdateInfo.Clear();
1788 // Restore the actual control's size.
1789 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
1791 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1795 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
1797 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1800 naturalSize.x = ConvertToEven( naturalSize.x );
1801 naturalSize.y = ConvertToEven( naturalSize.y );
1806 float Controller::GetHeightForWidth( float width )
1808 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
1809 // Make sure the model is up-to-date before layouting
1810 ProcessModifyEvents();
1813 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ||
1814 mImpl->mTextUpdateInfo.mFullRelayoutNeeded ||
1815 mImpl->mTextUpdateInfo.mClearAll )
1817 // Operations that can be done only once until the text changes.
1818 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1825 GET_GLYPH_METRICS );
1827 // Set the update info to relayout the whole text.
1828 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1829 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1831 // Make sure the model is up-to-date before layouting
1832 mImpl->UpdateModel( onlyOnceOperations );
1835 // Layout the text for the new width.
1836 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
1838 // Store the actual control's width.
1839 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
1841 DoRelayout( Size( width, MAX_FLOAT ),
1842 static_cast<OperationsMask>( onlyOnceOperations |
1846 // Do not do again the only once operations.
1847 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1849 // Do the size related operations again.
1850 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1854 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1856 // Clear the update info. This info will be set the next time the text is updated.
1857 mImpl->mTextUpdateInfo.Clear();
1859 // Restore the actual control's width.
1860 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
1862 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
1866 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
1867 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
1870 return layoutSize.height;
1873 int Controller::GetLineCount( float width )
1875 GetHeightForWidth( width );
1876 int numberofLines = mImpl->mModel->GetNumberOfLines();
1877 return numberofLines;
1880 const ModelInterface* const Controller::GetTextModel() const
1882 return mImpl->mModel.Get();
1885 float Controller::GetScrollAmountByUserInput()
1887 float scrollAmount = 0.0f;
1889 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
1891 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
1892 mImpl->mEventData->mCheckScrollAmount = false;
1894 return scrollAmount;
1897 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
1899 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
1902 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
1903 layoutHeight = layout.height;
1904 scrollPosition = mImpl->mModel->mScrollPosition.y;
1905 isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
1909 void Controller::SetHiddenInputOption(const Property::Map& options )
1911 if( NULL == mImpl->mHiddenInput )
1913 mImpl->mHiddenInput = new HiddenText( this );
1915 mImpl->mHiddenInput->SetProperties(options);
1918 void Controller::GetHiddenInputOption(Property::Map& options )
1920 if( NULL != mImpl->mHiddenInput )
1922 mImpl->mHiddenInput->GetProperties(options);
1926 void Controller::SetPlaceholderProperty( const Property::Map& map )
1928 const Property::Map::SizeType count = map.Count();
1930 for( Property::Map::SizeType position = 0; position < count; ++position )
1932 KeyValuePair keyValue = map.GetKeyValue( position );
1933 Property::Key& key = keyValue.first;
1934 Property::Value& value = keyValue.second;
1936 if( key == PLACEHOLDER_TEXT )
1938 std::string text = "";
1940 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
1942 else if( key == PLACEHOLDER_TEXT_FOCUSED )
1944 std::string text = "";
1946 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
1948 else if( key == PLACEHOLDER_COLOR )
1951 value.Get( textColor );
1952 if( GetPlaceholderTextColor() != textColor )
1954 SetPlaceholderTextColor( textColor );
1957 else if( key == PLACEHOLDER_FONT_FAMILY )
1959 std::string fontFamily = "";
1960 value.Get( fontFamily );
1961 SetPlaceholderFontFamily( fontFamily );
1963 else if( key == PLACEHOLDER_FONT_STYLE )
1965 SetFontStyleProperty( this, value, Text::FontStyle::PLACEHOLDER );
1967 else if( key == PLACEHOLDER_POINT_SIZE )
1970 value.Get( pointSize );
1971 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
1973 SetPlaceholderTextFontSize( pointSize, Text::Controller::POINT_SIZE );
1976 else if( key == PLACEHOLDER_PIXEL_SIZE )
1979 value.Get( pixelSize );
1980 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
1982 SetPlaceholderTextFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
1988 void Controller::GetPlaceholderProperty( Property::Map& map )
1990 if( NULL != mImpl->mEventData )
1992 if( !mImpl->mEventData->mPlaceholderTextActive.empty() )
1994 map[ PLACEHOLDER_TEXT_FOCUSED ] = mImpl->mEventData->mPlaceholderTextActive;
1996 if( !mImpl->mEventData->mPlaceholderTextInactive.empty() )
1998 map[ PLACEHOLDER_TEXT ] = mImpl->mEventData->mPlaceholderTextInactive;
2001 map[ PLACEHOLDER_COLOR ] = mImpl->mEventData->mPlaceholderTextColor;
2002 map[ PLACEHOLDER_FONT_FAMILY ] = GetPlaceholderFontFamily();
2004 Property::Value fontStyleMapGet;
2005 GetFontStyleProperty( this, fontStyleMapGet, Text::FontStyle::PLACEHOLDER );
2006 map[ PLACEHOLDER_FONT_STYLE ] = fontStyleMapGet;
2008 // Choose font size : POINT_SIZE or PIXEL_SIZE
2009 if( !mImpl->mEventData->mIsPlaceholderPixelSize )
2011 map[ PLACEHOLDER_POINT_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE );
2015 map[ PLACEHOLDER_PIXEL_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE );
2020 // public : Relayout.
2022 Controller::UpdateTextType Controller::Relayout( const Size& size )
2024 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
2026 UpdateTextType updateTextType = NONE_UPDATED;
2028 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
2030 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
2032 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
2033 updateTextType = MODEL_UPDATED;
2036 // Clear the update info. This info will be set the next time the text is updated.
2037 mImpl->mTextUpdateInfo.Clear();
2039 // Not worth to relayout if width or height is equal to zero.
2040 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
2042 return updateTextType;
2045 // Whether a new size has been set.
2046 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
2050 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
2052 // Layout operations that need to be done if the size changes.
2053 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2056 UPDATE_LAYOUT_SIZE |
2058 // Set the update info to relayout the whole text.
2059 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2060 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2062 // Store the size used to layout the text.
2063 mImpl->mModel->mVisualModel->mControlSize = size;
2066 // Whether there are modify events.
2067 if( 0u != mImpl->mModifyEvents.Count() )
2069 // Style operations that need to be done if the text is modified.
2070 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2074 // Make sure the model is up-to-date before layouting.
2075 ProcessModifyEvents();
2076 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
2080 updated = DoRelayout( size,
2081 mImpl->mOperationsPending,
2082 layoutSize ) || updated;
2086 updateTextType = MODEL_UPDATED;
2089 // Do not re-do any operation until something changes.
2090 mImpl->mOperationsPending = NO_OPERATION;
2091 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
2093 // Whether the text control is editable
2094 const bool isEditable = NULL != mImpl->mEventData;
2096 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
2098 if( newSize && isEditable )
2100 offset = mImpl->mModel->mScrollPosition;
2103 if( !isEditable || !IsMultiLineEnabled() )
2105 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
2106 CalculateVerticalOffset( size );
2113 // If there is a new size, the scroll position needs to be clamped.
2114 mImpl->ClampHorizontalScroll( layoutSize );
2116 // Update the decorator's positions is needed if there is a new size.
2117 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
2120 // Move the cursor, grab handle etc.
2121 if( mImpl->ProcessInputEvents() )
2123 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
2127 // Clear the update info. This info will be set the next time the text is updated.
2128 mImpl->mTextUpdateInfo.Clear();
2129 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
2131 return updateTextType;
2134 void Controller::RequestRelayout()
2136 mImpl->RequestRelayout();
2139 // public : Input style change signals.
2141 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
2143 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
2146 void Controller::ProcessInputStyleChangedSignals()
2148 if( NULL == mImpl->mEventData )
2154 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
2155 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
2159 const InputStyle::Mask mask = *it;
2161 if( NULL != mImpl->mEditableControlInterface )
2163 // Emit the input style changed signal.
2164 mImpl->mEditableControlInterface->InputStyleChanged( mask );
2168 mImpl->mEventData->mInputStyleChangedQueue.Clear();
2171 // public : Text-input Event Queuing.
2173 void Controller::KeyboardFocusGainEvent()
2175 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
2177 if( NULL != mImpl->mEventData )
2179 if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
2180 ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
2182 mImpl->ChangeState( EventData::EDITING );
2183 mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
2184 mImpl->mEventData->mUpdateInputStyle = true;
2186 mImpl->NotifyImfMultiLineStatus();
2187 if( mImpl->IsShowingPlaceholderText() )
2189 // Show alternative placeholder-text when editing
2190 ShowPlaceholderText();
2193 mImpl->RequestRelayout();
2197 void Controller::KeyboardFocusLostEvent()
2199 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
2201 if( NULL != mImpl->mEventData )
2203 if( EventData::INTERRUPTED != mImpl->mEventData->mState )
2205 mImpl->ChangeState( EventData::INACTIVE );
2207 if( !mImpl->IsShowingRealText() )
2209 // Revert to regular placeholder-text when not editing
2210 ShowPlaceholderText();
2214 mImpl->RequestRelayout();
2217 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
2219 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
2221 bool textChanged = false;
2222 bool relayoutNeeded = false;
2224 if( ( NULL != mImpl->mEventData ) &&
2225 ( keyEvent.state == KeyEvent::Down ) )
2227 int keyCode = keyEvent.keyCode;
2228 const std::string& keyString = keyEvent.keyPressed;
2230 const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
2232 // Pre-process to separate modifying events from non-modifying input events.
2235 // In some platforms arrive key events with no key code.
2239 else if( Dali::DALI_KEY_ESCAPE == keyCode )
2241 // Escape key is a special case which causes focus loss
2242 KeyboardFocusLostEvent();
2244 // Will request for relayout.
2245 relayoutNeeded = true;
2247 else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) ||
2248 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
2249 ( Dali::DALI_KEY_CURSOR_UP == keyCode ) ||
2250 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) )
2252 // If don't have any text, do nothing.
2253 if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
2258 uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition;
2259 uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2260 uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition );
2261 uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines();
2263 // Logic to determine whether this text control will lose focus or not.
2264 if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition ) ||
2265 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition) ||
2266 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) ||
2267 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) ||
2268 ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) ||
2269 ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) )
2274 mImpl->mEventData->mCheckScrollAmount = true;
2275 Event event( Event::CURSOR_KEY_EVENT );
2276 event.p1.mInt = keyCode;
2277 mImpl->mEventData->mEventQueue.push_back( event );
2279 // Will request for relayout.
2280 relayoutNeeded = true;
2282 else if( Dali::DALI_KEY_BACKSPACE == keyCode )
2284 textChanged = BackspaceKeyEvent();
2286 // Will request for relayout.
2287 relayoutNeeded = true;
2289 else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
2290 IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
2291 IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
2293 // Power key/Menu/Home key behaviour does not allow edit mode to resume.
2294 mImpl->ChangeState( EventData::INACTIVE );
2296 // Will request for relayout.
2297 relayoutNeeded = true;
2299 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2301 else if( Dali::DALI_KEY_SHIFT_LEFT == keyCode )
2303 // DALI_KEY_SHIFT_LEFT is the key code for the Left Shift. It's sent (by the imf?) when the predictive text is enabled
2304 // and a character is typed after the type of a upper case latin character.
2309 else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
2311 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2317 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
2319 // IMF manager is no longer handling key-events
2320 mImpl->ClearPreEditFlag();
2322 InsertText( keyString, COMMIT );
2325 // Will request for relayout.
2326 relayoutNeeded = true;
2329 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
2330 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
2332 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
2333 ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
2334 ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
2336 // Should not change the state if the key is the shift send by the imf manager.
2337 // Otherwise, when the state is SELECTING the text controller can't send the right
2338 // surrounding info to the imf.
2339 mImpl->ChangeState( EventData::EDITING );
2341 // Will request for relayout.
2342 relayoutNeeded = true;
2345 if( relayoutNeeded )
2347 mImpl->RequestRelayout();
2352 ( NULL != mImpl->mEditableControlInterface ) )
2354 // Do this last since it provides callbacks into application code
2355 mImpl->mEditableControlInterface->TextChanged();
2361 void Controller::TapEvent( unsigned int tapCount, float x, float y )
2363 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
2365 if( NULL != mImpl->mEventData )
2367 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
2368 EventData::State state( mImpl->mEventData->mState );
2369 bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
2371 if( mImpl->IsClipboardVisible() )
2373 if( EventData::INACTIVE == state || EventData::EDITING == state)
2375 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2377 relayoutNeeded = true;
2379 else if( 1u == tapCount )
2381 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
2383 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
2386 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
2388 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2389 relayoutNeeded = true;
2393 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
2395 // Hide placeholder text
2399 if( EventData::INACTIVE == state )
2401 mImpl->ChangeState( EventData::EDITING );
2403 else if( !mImpl->IsClipboardEmpty() )
2405 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
2407 relayoutNeeded = true;
2410 else if( 2u == tapCount )
2412 if( mImpl->mEventData->mSelectionEnabled &&
2413 mImpl->IsShowingRealText() )
2415 relayoutNeeded = true;
2416 mImpl->mEventData->mIsLeftHandleSelected = true;
2417 mImpl->mEventData->mIsRightHandleSelected = true;
2421 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
2422 if( relayoutNeeded )
2424 Event event( Event::TAP_EVENT );
2425 event.p1.mUint = tapCount;
2426 event.p2.mFloat = x;
2427 event.p3.mFloat = y;
2428 mImpl->mEventData->mEventQueue.push_back( event );
2430 mImpl->RequestRelayout();
2434 // Reset keyboard as tap event has occurred.
2435 mImpl->ResetImfManager();
2438 void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
2440 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
2442 if( NULL != mImpl->mEventData )
2444 Event event( Event::PAN_EVENT );
2445 event.p1.mInt = state;
2446 event.p2.mFloat = displacement.x;
2447 event.p3.mFloat = displacement.y;
2448 mImpl->mEventData->mEventQueue.push_back( event );
2450 mImpl->RequestRelayout();
2454 void Controller::LongPressEvent( Gesture::State state, float x, float y )
2456 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
2458 if( ( state == Gesture::Started ) &&
2459 ( NULL != mImpl->mEventData ) )
2461 // The 1st long-press on inactive text-field is treated as tap
2462 if( EventData::INACTIVE == mImpl->mEventData->mState )
2464 mImpl->ChangeState( EventData::EDITING );
2466 Event event( Event::TAP_EVENT );
2468 event.p2.mFloat = x;
2469 event.p3.mFloat = y;
2470 mImpl->mEventData->mEventQueue.push_back( event );
2472 mImpl->RequestRelayout();
2474 else if( !mImpl->IsShowingRealText() )
2476 Event event( Event::LONG_PRESS_EVENT );
2477 event.p1.mInt = state;
2478 event.p2.mFloat = x;
2479 event.p3.mFloat = y;
2480 mImpl->mEventData->mEventQueue.push_back( event );
2481 mImpl->RequestRelayout();
2483 else if( !mImpl->IsClipboardVisible() )
2485 // Reset the imf manager to commit the pre-edit before selecting the text.
2486 mImpl->ResetImfManager();
2488 Event event( Event::LONG_PRESS_EVENT );
2489 event.p1.mInt = state;
2490 event.p2.mFloat = x;
2491 event.p3.mFloat = y;
2492 mImpl->mEventData->mEventQueue.push_back( event );
2493 mImpl->RequestRelayout();
2495 mImpl->mEventData->mIsLeftHandleSelected = true;
2496 mImpl->mEventData->mIsRightHandleSelected = true;
2501 ImfManager::ImfCallbackData Controller::OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
2503 // Whether the text needs to be relaid-out.
2504 bool requestRelayout = false;
2506 // Whether to retrieve the text and cursor position to be sent to the IMF manager.
2507 bool retrieveText = false;
2508 bool retrieveCursor = false;
2510 switch( imfEvent.eventName )
2512 case ImfManager::COMMIT:
2514 InsertText( imfEvent.predictiveString, Text::Controller::COMMIT );
2515 requestRelayout = true;
2516 retrieveCursor = true;
2519 case ImfManager::PREEDIT:
2521 InsertText( imfEvent.predictiveString, Text::Controller::PRE_EDIT );
2522 requestRelayout = true;
2523 retrieveCursor = true;
2526 case ImfManager::DELETESURROUNDING:
2528 const bool textDeleted = RemoveText( imfEvent.cursorOffset,
2529 imfEvent.numberOfChars,
2530 DONT_UPDATE_INPUT_STYLE );
2534 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2535 !mImpl->IsPlaceholderAvailable() )
2537 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2541 ShowPlaceholderText();
2543 mImpl->mEventData->mUpdateCursorPosition = true;
2544 mImpl->mEventData->mScrollAfterDelete = true;
2546 requestRelayout = true;
2550 case ImfManager::GETSURROUNDING:
2552 retrieveText = true;
2553 retrieveCursor = true;
2556 case ImfManager::PRIVATECOMMAND:
2558 // PRIVATECOMMAND event is just for getting the private command message
2559 retrieveText = true;
2560 retrieveCursor = true;
2563 case ImfManager::VOID:
2570 if( requestRelayout )
2572 mImpl->mOperationsPending = ALL_OPERATIONS;
2573 mImpl->RequestRelayout();
2577 CharacterIndex cursorPosition = 0u;
2578 Length numberOfWhiteSpaces = 0u;
2580 if( retrieveCursor )
2582 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
2584 cursorPosition = mImpl->GetLogicalCursorPosition();
2586 if( cursorPosition < numberOfWhiteSpaces )
2588 cursorPosition = 0u;
2592 cursorPosition -= numberOfWhiteSpaces;
2598 mImpl->GetText( numberOfWhiteSpaces, text );
2601 ImfManager::ImfCallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
2603 if( requestRelayout &&
2604 ( NULL != mImpl->mEditableControlInterface ) )
2606 // Do this last since it provides callbacks into application code
2607 mImpl->mEditableControlInterface->TextChanged();
2610 return callbackData;
2613 void Controller::PasteClipboardItemEvent()
2615 // Retrieve the clipboard contents first
2616 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
2617 std::string stringToPaste( notifier.GetContent() );
2619 // Commit the current pre-edit text; the contents of the clipboard should be appended
2620 mImpl->ResetImfManager();
2622 // Temporary disable hiding clipboard
2623 mImpl->SetClipboardHideEnable( false );
2626 PasteText( stringToPaste );
2628 mImpl->SetClipboardHideEnable( true );
2631 // protected : Inherit from Text::Decorator::ControllerInterface.
2633 void Controller::GetTargetSize( Vector2& targetSize )
2635 targetSize = mImpl->mModel->mVisualModel->mControlSize;
2638 void Controller::AddDecoration( Actor& actor, bool needsClipping )
2640 if( NULL != mImpl->mEditableControlInterface )
2642 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
2646 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
2648 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
2650 if( NULL != mImpl->mEventData )
2652 switch( handleType )
2656 Event event( Event::GRAB_HANDLE_EVENT );
2657 event.p1.mUint = state;
2658 event.p2.mFloat = x;
2659 event.p3.mFloat = y;
2661 mImpl->mEventData->mEventQueue.push_back( event );
2664 case LEFT_SELECTION_HANDLE:
2666 Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
2667 event.p1.mUint = state;
2668 event.p2.mFloat = x;
2669 event.p3.mFloat = y;
2671 mImpl->mEventData->mEventQueue.push_back( event );
2674 case RIGHT_SELECTION_HANDLE:
2676 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
2677 event.p1.mUint = state;
2678 event.p2.mFloat = x;
2679 event.p3.mFloat = y;
2681 mImpl->mEventData->mEventQueue.push_back( event );
2684 case LEFT_SELECTION_HANDLE_MARKER:
2685 case RIGHT_SELECTION_HANDLE_MARKER:
2687 // Markers do not move the handles.
2690 case HANDLE_TYPE_COUNT:
2692 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
2696 mImpl->RequestRelayout();
2700 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
2702 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
2704 if( NULL == mImpl->mEventData )
2711 case Toolkit::TextSelectionPopup::CUT:
2713 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
2714 mImpl->mOperationsPending = ALL_OPERATIONS;
2716 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2717 !mImpl->IsPlaceholderAvailable() )
2719 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2723 ShowPlaceholderText();
2726 mImpl->mEventData->mUpdateCursorPosition = true;
2727 mImpl->mEventData->mScrollAfterDelete = true;
2729 mImpl->RequestRelayout();
2731 if( NULL != mImpl->mEditableControlInterface )
2733 mImpl->mEditableControlInterface->TextChanged();
2737 case Toolkit::TextSelectionPopup::COPY:
2739 mImpl->SendSelectionToClipboard( false ); // Text not modified
2741 mImpl->mEventData->mUpdateCursorPosition = true;
2743 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
2746 case Toolkit::TextSelectionPopup::PASTE:
2748 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
2751 case Toolkit::TextSelectionPopup::SELECT:
2753 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
2755 if( mImpl->mEventData->mSelectionEnabled )
2757 // Creates a SELECT event.
2758 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
2762 case Toolkit::TextSelectionPopup::SELECT_ALL:
2764 // Creates a SELECT_ALL event
2765 SelectEvent( 0.f, 0.f, true );
2768 case Toolkit::TextSelectionPopup::CLIPBOARD:
2770 mImpl->ShowClipboard();
2773 case Toolkit::TextSelectionPopup::NONE:
2781 void Controller::DisplayTimeExpired()
2783 mImpl->mEventData->mUpdateCursorPosition = true;
2784 // Apply modifications to the model
2785 mImpl->mOperationsPending = ALL_OPERATIONS;
2787 mImpl->RequestRelayout();
2790 // private : Update.
2792 void Controller::InsertText( const std::string& text, Controller::InsertType type )
2794 bool removedPrevious = false;
2795 bool removedSelected = false;
2796 bool maxLengthReached = false;
2798 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
2800 if( NULL == mImpl->mEventData )
2805 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
2806 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
2807 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
2809 // TODO: At the moment the underline runs are only for pre-edit.
2810 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
2812 // Remove the previous IMF pre-edit.
2813 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
2815 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
2816 mImpl->mEventData->mPreEditLength,
2817 DONT_UPDATE_INPUT_STYLE );
2819 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
2820 mImpl->mEventData->mPreEditLength = 0u;
2824 // Remove the previous Selection.
2825 removedSelected = RemoveSelectedText();
2829 Vector<Character> utf32Characters;
2830 Length characterCount = 0u;
2834 // Convert text into UTF-32
2835 utf32Characters.Resize( text.size() );
2837 // This is a bit horrible but std::string returns a (signed) char*
2838 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
2840 // Transform a text array encoded in utf8 into an array encoded in utf32.
2841 // It returns the actual number of characters.
2842 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
2843 utf32Characters.Resize( characterCount );
2845 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
2846 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
2849 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
2851 // The placeholder text is no longer needed
2852 if( mImpl->IsShowingPlaceholderText() )
2857 mImpl->ChangeState( EventData::EDITING );
2859 // Handle the IMF (predicitive text) state changes
2860 if( COMMIT == type )
2862 // IMF manager is no longer handling key-events
2863 mImpl->ClearPreEditFlag();
2867 if( !mImpl->mEventData->mPreEditFlag )
2869 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
2871 // Record the start of the pre-edit text
2872 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
2875 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
2876 mImpl->mEventData->mPreEditFlag = true;
2878 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
2881 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
2883 // Restrict new text to fit within Maximum characters setting.
2884 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
2885 maxLengthReached = ( characterCount > maxSizeOfNewText );
2887 // The cursor position.
2888 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
2890 // Update the text's style.
2892 // Updates the text style runs by adding characters.
2893 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
2895 // Get the character index from the cursor index.
2896 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
2898 // Retrieve the text's style for the given index.
2900 mImpl->RetrieveDefaultInputStyle( style );
2901 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
2903 // Whether to add a new text color run.
2904 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor );
2906 // Whether to add a new font run.
2907 const bool addFontNameRun = style.familyName != mImpl->mEventData->mInputStyle.familyName;
2908 const bool addFontWeightRun = style.weight != mImpl->mEventData->mInputStyle.weight;
2909 const bool addFontWidthRun = style.width != mImpl->mEventData->mInputStyle.width;
2910 const bool addFontSlantRun = style.slant != mImpl->mEventData->mInputStyle.slant;
2911 const bool addFontSizeRun = style.size != mImpl->mEventData->mInputStyle.size;
2916 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
2917 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
2919 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
2920 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
2921 colorRun.characterRun.characterIndex = cursorIndex;
2922 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
2925 if( addFontNameRun ||
2931 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
2932 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
2934 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
2936 if( addFontNameRun )
2938 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
2939 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
2940 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
2941 fontDescriptionRun.familyDefined = true;
2943 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
2946 if( addFontWeightRun )
2948 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
2949 fontDescriptionRun.weightDefined = true;
2952 if( addFontWidthRun )
2954 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
2955 fontDescriptionRun.widthDefined = true;
2958 if( addFontSlantRun )
2960 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
2961 fontDescriptionRun.slantDefined = true;
2964 if( addFontSizeRun )
2966 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
2967 fontDescriptionRun.sizeDefined = true;
2970 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
2971 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
2974 // Insert at current cursor position.
2975 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
2977 if( cursorIndex < numberOfCharactersInModel )
2979 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
2983 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
2986 // Mark the first paragraph to be updated.
2987 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
2989 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
2990 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2991 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
2992 mImpl->mTextUpdateInfo.mClearAll = true;
2996 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
2997 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
3000 // Update the cursor index.
3001 cursorIndex += maxSizeOfNewText;
3003 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 );
3006 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
3007 mImpl->IsPlaceholderAvailable() )
3009 // Show place-holder if empty after removing the pre-edit text
3010 ShowPlaceholderText();
3011 mImpl->mEventData->mUpdateCursorPosition = true;
3012 mImpl->ClearPreEditFlag();
3014 else if( removedPrevious ||
3016 ( 0 != utf32Characters.Count() ) )
3018 // Queue an inserted event
3019 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
3021 mImpl->mEventData->mUpdateCursorPosition = true;
3022 if( removedSelected )
3024 mImpl->mEventData->mScrollAfterDelete = true;
3028 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3032 if( maxLengthReached )
3034 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
3036 mImpl->ResetImfManager();
3038 if( NULL != mImpl->mEditableControlInterface )
3040 // Do this last since it provides callbacks into application code
3041 mImpl->mEditableControlInterface->MaxLengthReached();
3046 void Controller::PasteText( const std::string& stringToPaste )
3048 InsertText( stringToPaste, Text::Controller::COMMIT );
3049 mImpl->ChangeState( EventData::EDITING );
3050 mImpl->RequestRelayout();
3052 if( NULL != mImpl->mEditableControlInterface )
3054 // Do this last since it provides callbacks into application code
3055 mImpl->mEditableControlInterface->TextChanged();
3059 bool Controller::RemoveText( int cursorOffset,
3060 int numberOfCharacters,
3061 UpdateInputStyleType type )
3063 bool removed = false;
3065 if( NULL == mImpl->mEventData )
3070 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
3071 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
3073 if( !mImpl->IsShowingPlaceholderText() )
3075 // Delete at current cursor position
3076 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
3077 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3079 CharacterIndex cursorIndex = 0;
3081 // Validate the cursor position & number of characters
3082 if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
3084 cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
3087 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
3089 numberOfCharacters = currentText.Count() - cursorIndex;
3092 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.
3093 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
3095 // Mark the paragraphs to be updated.
3096 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3098 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3099 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3100 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
3101 mImpl->mTextUpdateInfo.mClearAll = true;
3105 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3106 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
3109 // Update the input style and remove the text's style before removing the text.
3111 if( UPDATE_INPUT_STYLE == type )
3113 // Keep a copy of the current input style.
3114 InputStyle currentInputStyle;
3115 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
3117 // Set first the default input style.
3118 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
3120 // Update the input style.
3121 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
3123 // Compare if the input style has changed.
3124 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
3126 if( hasInputStyleChanged )
3128 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
3129 // Queue the input style changed signal.
3130 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
3134 // Updates the text style runs by removing characters. Runs with no characters are removed.
3135 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
3137 // Remove the characters.
3138 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
3139 Vector<Character>::Iterator last = first + numberOfCharacters;
3141 currentText.Erase( first, last );
3143 // Cursor position retreat
3144 oldCursorIndex = cursorIndex;
3146 mImpl->mEventData->mScrollAfterDelete = true;
3148 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
3156 bool Controller::RemoveSelectedText()
3158 bool textRemoved( false );
3160 if( EventData::SELECTING == mImpl->mEventData->mState )
3162 std::string removedString;
3163 mImpl->RetrieveSelection( removedString, true );
3165 if( !removedString.empty() )
3168 mImpl->ChangeState( EventData::EDITING );
3175 // private : Relayout.
3177 bool Controller::DoRelayout( const Size& size,
3178 OperationsMask operationsRequired,
3181 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
3182 bool viewUpdated( false );
3184 // Calculate the operations to be done.
3185 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
3187 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
3188 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
3190 // Get the current layout size.
3191 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3193 if( NO_OPERATION != ( LAYOUT & operations ) )
3195 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
3197 // Some vectors with data needed to layout and reorder may be void
3198 // after the first time the text has been laid out.
3199 // Fill the vectors again.
3201 // Calculate the number of glyphs to layout.
3202 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
3203 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
3204 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
3205 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
3207 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
3208 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
3209 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
3210 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
3212 if( 0u == totalNumberOfGlyphs )
3214 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3216 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
3219 // Nothing else to do if there is no glyphs.
3220 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
3224 const Vector<LineBreakInfo>& lineBreakInfo = mImpl->mModel->mLogicalModel->mLineBreakInfo;
3225 const Vector<WordBreakInfo>& wordBreakInfo = mImpl->mModel->mLogicalModel->mWordBreakInfo;
3226 const Vector<CharacterDirection>& characterDirection = mImpl->mModel->mLogicalModel->mCharacterDirections;
3227 const Vector<GlyphInfo>& glyphs = mImpl->mModel->mVisualModel->mGlyphs;
3228 const Vector<CharacterIndex>& glyphsToCharactersMap = mImpl->mModel->mVisualModel->mGlyphsToCharacters;
3229 const Vector<Length>& charactersPerGlyph = mImpl->mModel->mVisualModel->mCharactersPerGlyph;
3230 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
3232 // Set the layout parameters.
3233 Layout::Parameters layoutParameters( size,
3235 lineBreakInfo.Begin(),
3236 wordBreakInfo.Begin(),
3237 ( 0u != characterDirection.Count() ) ? characterDirection.Begin() : NULL,
3239 glyphsToCharactersMap.Begin(),
3240 charactersPerGlyph.Begin(),
3241 charactersToGlyphBuffer,
3242 glyphsPerCharacterBuffer,
3243 totalNumberOfGlyphs,
3244 mImpl->mModel->mHorizontalAlignment,
3245 mImpl->mModel->mLineWrapMode );
3247 // Resize the vector of positions to have the same size than the vector of glyphs.
3248 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
3249 glyphPositions.Resize( totalNumberOfGlyphs );
3251 // Whether the last character is a new paragraph character.
3252 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
3253 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
3255 // The initial glyph and the number of glyphs to layout.
3256 layoutParameters.startGlyphIndex = startGlyphIndex;
3257 layoutParameters.numberOfGlyphs = numberOfGlyphs;
3258 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
3259 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
3261 // Update the visual model.
3263 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
3265 mImpl->mModel->mVisualModel->mLines,
3267 mImpl->mModel->mElideEnabled );
3269 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
3273 layoutSize = newLayoutSize;
3275 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
3277 mImpl->mAutoScrollDirectionRTL = false;
3280 // Reorder the lines
3281 if( NO_OPERATION != ( REORDER & operations ) )
3283 Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = mImpl->mModel->mLogicalModel->mBidirectionalParagraphInfo;
3284 Vector<BidirectionalLineInfoRun>& bidirectionalLineInfo = mImpl->mModel->mLogicalModel->mBidirectionalLineInfo;
3286 // Check first if there are paragraphs with bidirectional info.
3287 if( 0u != bidirectionalInfo.Count() )
3290 const Length numberOfLines = mImpl->mModel->mVisualModel->mLines.Count();
3292 // Reorder the lines.
3293 bidirectionalLineInfo.Reserve( numberOfLines ); // Reserve because is not known yet how many lines have right to left characters.
3294 ReorderLines( bidirectionalInfo,
3296 requestedNumberOfCharacters,
3297 mImpl->mModel->mVisualModel->mLines,
3298 bidirectionalLineInfo );
3300 // Set the bidirectional info per line into the layout parameters.
3301 layoutParameters.lineBidirectionalInfoRunsBuffer = bidirectionalLineInfo.Begin();
3302 layoutParameters.numberOfBidirectionalInfoRuns = bidirectionalLineInfo.Count();
3304 // Re-layout the text. Reorder those lines with right to left characters.
3305 mImpl->mLayoutEngine.ReLayoutRightToLeftLines( layoutParameters,
3307 requestedNumberOfCharacters,
3310 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && ( numberOfLines > 0 ) )
3312 const LineRun* const firstline = mImpl->mModel->mVisualModel->mLines.Begin();
3315 mImpl->mAutoScrollDirectionRTL = firstline->direction;
3321 // Sets the layout size.
3322 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3324 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
3329 if( NO_OPERATION != ( ALIGN & operations ) )
3331 // The laid-out lines.
3332 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
3334 // Need to align with the control's size as the text may contain lines
3335 // starting either with left to right text or right to left.
3336 mImpl->mLayoutEngine.Align( size,
3338 requestedNumberOfCharacters,
3339 mImpl->mModel->mHorizontalAlignment,
3341 mImpl->mModel->mAlignmentOffset );
3345 #if defined(DEBUG_ENABLED)
3346 std::string currentText;
3347 GetText( currentText );
3348 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mAutoScrollDirectionRTL[%s] [%s]\n", this, (mImpl->mAutoScrollDirectionRTL)?"true":"false", currentText.c_str() );
3350 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
3354 void Controller::CalculateVerticalOffset( const Size& controlSize )
3356 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3358 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
3360 // Get the line height of the default font.
3361 layoutSize.height = mImpl->GetDefaultFontLineHeight();
3364 switch( mImpl->mModel->mVerticalAlignment )
3366 case Layout::VERTICAL_ALIGN_TOP:
3368 mImpl->mModel->mScrollPosition.y = 0.f;
3371 case Layout::VERTICAL_ALIGN_CENTER:
3373 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
3376 case Layout::VERTICAL_ALIGN_BOTTOM:
3378 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
3384 // private : Events.
3386 void Controller::ProcessModifyEvents()
3388 Vector<ModifyEvent>& events = mImpl->mModifyEvents;
3390 if( 0u == events.Count() )
3396 for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
3397 endIt = events.End();
3401 const ModifyEvent& event = *it;
3403 if( ModifyEvent::TEXT_REPLACED == event.type )
3405 // A (single) replace event should come first, otherwise we wasted time processing NOOP events
3406 DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
3408 TextReplacedEvent();
3410 else if( ModifyEvent::TEXT_INSERTED == event.type )
3412 TextInsertedEvent();
3414 else if( ModifyEvent::TEXT_DELETED == event.type )
3416 // Placeholder-text cannot be deleted
3417 if( !mImpl->IsShowingPlaceholderText() )
3424 if( NULL != mImpl->mEventData )
3426 // When the text is being modified, delay cursor blinking
3427 mImpl->mEventData->mDecorator->DelayCursorBlink();
3430 // Discard temporary text
3434 void Controller::TextReplacedEvent()
3436 // The natural size needs to be re-calculated.
3437 mImpl->mRecalculateNaturalSize = true;
3439 // Apply modifications to the model
3440 mImpl->mOperationsPending = ALL_OPERATIONS;
3443 void Controller::TextInsertedEvent()
3445 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
3447 if( NULL == mImpl->mEventData )
3452 mImpl->mEventData->mCheckScrollAmount = true;
3454 // The natural size needs to be re-calculated.
3455 mImpl->mRecalculateNaturalSize = true;
3457 // Apply modifications to the model; TODO - Optimize this
3458 mImpl->mOperationsPending = ALL_OPERATIONS;
3461 void Controller::TextDeletedEvent()
3463 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
3465 if( NULL == mImpl->mEventData )
3470 mImpl->mEventData->mCheckScrollAmount = true;
3472 // The natural size needs to be re-calculated.
3473 mImpl->mRecalculateNaturalSize = true;
3475 // Apply modifications to the model; TODO - Optimize this
3476 mImpl->mOperationsPending = ALL_OPERATIONS;
3479 void Controller::SelectEvent( float x, float y, bool selectAll )
3481 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
3483 if( NULL != mImpl->mEventData )
3487 Event event( Event::SELECT_ALL );
3488 mImpl->mEventData->mEventQueue.push_back( event );
3492 Event event( Event::SELECT );
3493 event.p2.mFloat = x;
3494 event.p3.mFloat = y;
3495 mImpl->mEventData->mEventQueue.push_back( event );
3498 mImpl->mEventData->mCheckScrollAmount = true;
3499 mImpl->mEventData->mIsLeftHandleSelected = true;
3500 mImpl->mEventData->mIsRightHandleSelected = true;
3501 mImpl->RequestRelayout();
3505 bool Controller::BackspaceKeyEvent()
3507 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p DALI_KEY_BACKSPACE\n", this );
3509 bool removed = false;
3511 if( NULL == mImpl->mEventData )
3516 // IMF manager is no longer handling key-events
3517 mImpl->ClearPreEditFlag();
3519 if( EventData::SELECTING == mImpl->mEventData->mState )
3521 removed = RemoveSelectedText();
3523 else if( mImpl->mEventData->mPrimaryCursorPosition > 0 )
3525 // Remove the character before the current cursor position
3526 removed = RemoveText( -1,
3528 UPDATE_INPUT_STYLE );
3533 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3534 !mImpl->IsPlaceholderAvailable() )
3536 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3540 ShowPlaceholderText();
3542 mImpl->mEventData->mUpdateCursorPosition = true;
3543 mImpl->mEventData->mScrollAfterDelete = true;
3549 // private : Helpers.
3551 void Controller::ResetText()
3554 mImpl->mModel->mLogicalModel->mText.Clear();
3556 // We have cleared everything including the placeholder-text
3557 mImpl->PlaceholderCleared();
3559 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3560 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3561 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
3563 // Clear any previous text.
3564 mImpl->mTextUpdateInfo.mClearAll = true;
3566 // The natural size needs to be re-calculated.
3567 mImpl->mRecalculateNaturalSize = true;
3569 // Apply modifications to the model
3570 mImpl->mOperationsPending = ALL_OPERATIONS;
3573 void Controller::ShowPlaceholderText()
3575 if( mImpl->IsPlaceholderAvailable() )
3577 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
3579 if( NULL == mImpl->mEventData )
3584 mImpl->mEventData->mIsShowingPlaceholderText = true;
3586 // Disable handles when showing place-holder text
3587 mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
3588 mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
3589 mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
3591 const char* text( NULL );
3594 // TODO - Switch Placeholder text when changing state
3595 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
3596 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
3598 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
3599 size = mImpl->mEventData->mPlaceholderTextActive.size();
3603 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
3604 size = mImpl->mEventData->mPlaceholderTextInactive.size();
3607 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3608 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3610 // Reset model for showing placeholder.
3611 mImpl->mModel->mLogicalModel->mText.Clear();
3612 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
3614 // Convert text into UTF-32
3615 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
3616 utf32Characters.Resize( size );
3618 // This is a bit horrible but std::string returns a (signed) char*
3619 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
3621 // Transform a text array encoded in utf8 into an array encoded in utf32.
3622 // It returns the actual number of characters.
3623 const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
3624 utf32Characters.Resize( characterCount );
3626 // The characters to be added.
3627 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
3629 // Reset the cursor position
3630 mImpl->mEventData->mPrimaryCursorPosition = 0;
3632 // The natural size needs to be re-calculated.
3633 mImpl->mRecalculateNaturalSize = true;
3635 // Apply modifications to the model
3636 mImpl->mOperationsPending = ALL_OPERATIONS;
3638 // Update the rest of the model during size negotiation
3639 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
3643 void Controller::ClearFontData()
3645 if( mImpl->mFontDefaults )
3647 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
3650 // Set flags to update the model.
3651 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3652 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3653 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
3655 mImpl->mTextUpdateInfo.mClearAll = true;
3656 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
3657 mImpl->mRecalculateNaturalSize = true;
3659 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
3664 UPDATE_LAYOUT_SIZE |
3669 void Controller::ClearStyleData()
3671 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
3672 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
3675 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
3677 // Reset the cursor position
3678 if( NULL != mImpl->mEventData )
3680 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
3682 // Update the cursor if it's in editing mode.
3683 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
3685 mImpl->mEventData->mUpdateCursorPosition = true;
3690 void Controller::ResetScrollPosition()
3692 if( NULL != mImpl->mEventData )
3694 // Reset the scroll position.
3695 mImpl->mModel->mScrollPosition = Vector2::ZERO;
3696 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3700 void Controller::SetControlInterface( ControlInterface* controlInterface )
3702 mImpl->mControlInterface = controlInterface;
3705 // private : Private contructors & copy operator.
3707 Controller::Controller()
3710 mImpl = new Controller::Impl( NULL, NULL );
3713 Controller::Controller( ControlInterface* controlInterface )
3715 mImpl = new Controller::Impl( controlInterface, NULL );
3718 Controller::Controller( ControlInterface* controlInterface,
3719 EditableControlInterface* editableControlInterface )
3721 mImpl = new Controller::Impl( controlInterface,
3722 editableControlInterface );
3725 // The copy constructor and operator are left unimplemented.
3727 // protected : Destructor.
3729 Controller::~Controller()
3736 } // namespace Toolkit