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 return mImpl->mFontDefaults->weightDefined;
692 FontWeight Controller::GetDefaultFontWeight() const
694 if( NULL != mImpl->mFontDefaults )
696 return mImpl->mFontDefaults->mFontDescription.weight;
699 return TextAbstraction::FontWeight::NORMAL;
702 void Controller::SetPlaceholderTextFontWeight( FontWeight weight )
704 if( NULL != mImpl->mEventData )
706 if( NULL == mImpl->mEventData->mPlaceholderFont )
708 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
711 mImpl->mEventData->mPlaceholderFont->mFontDescription.weight = weight;
712 mImpl->mEventData->mPlaceholderFont->weightDefined = true;
714 mImpl->RequestRelayout();
718 bool Controller::IsPlaceholderTextFontWeightDefined() const
720 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
722 return mImpl->mEventData->mPlaceholderFont->weightDefined;
727 FontWeight Controller::GetPlaceholderTextFontWeight() const
729 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
731 return mImpl->mEventData->mPlaceholderFont->mFontDescription.weight;
734 return TextAbstraction::FontWeight::NORMAL;
737 void Controller::SetDefaultFontWidth( FontWidth width )
739 if( NULL == mImpl->mFontDefaults )
741 mImpl->mFontDefaults = new FontDefaults();
744 mImpl->mFontDefaults->mFontDescription.width = width;
745 mImpl->mFontDefaults->widthDefined = true;
747 // Clear the font-specific data
750 mImpl->RequestRelayout();
753 bool Controller::IsDefaultFontWidthDefined() const
755 return mImpl->mFontDefaults->widthDefined;
758 FontWidth Controller::GetDefaultFontWidth() const
760 if( NULL != mImpl->mFontDefaults )
762 return mImpl->mFontDefaults->mFontDescription.width;
765 return TextAbstraction::FontWidth::NORMAL;
768 void Controller::SetPlaceholderTextFontWidth( FontWidth width )
770 if( NULL != mImpl->mEventData )
772 if( NULL == mImpl->mEventData->mPlaceholderFont )
774 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
777 mImpl->mEventData->mPlaceholderFont->mFontDescription.width = width;
778 mImpl->mEventData->mPlaceholderFont->widthDefined = true;
780 mImpl->RequestRelayout();
784 bool Controller::IsPlaceholderTextFontWidthDefined() const
786 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
788 return mImpl->mEventData->mPlaceholderFont->widthDefined;
793 FontWidth Controller::GetPlaceholderTextFontWidth() const
795 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
797 return mImpl->mEventData->mPlaceholderFont->mFontDescription.width;
800 return TextAbstraction::FontWidth::NORMAL;
803 void Controller::SetDefaultFontSlant( FontSlant slant )
805 if( NULL == mImpl->mFontDefaults )
807 mImpl->mFontDefaults = new FontDefaults();
810 mImpl->mFontDefaults->mFontDescription.slant = slant;
811 mImpl->mFontDefaults->slantDefined = true;
813 // Clear the font-specific data
816 mImpl->RequestRelayout();
819 bool Controller::IsDefaultFontSlantDefined() const
821 return mImpl->mFontDefaults->slantDefined;
824 FontSlant Controller::GetDefaultFontSlant() const
826 if( NULL != mImpl->mFontDefaults )
828 return mImpl->mFontDefaults->mFontDescription.slant;
831 return TextAbstraction::FontSlant::NORMAL;
834 void Controller::SetPlaceholderTextFontSlant( FontSlant slant )
836 if( NULL != mImpl->mEventData )
838 if( NULL == mImpl->mEventData->mPlaceholderFont )
840 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
843 mImpl->mEventData->mPlaceholderFont->mFontDescription.slant = slant;
844 mImpl->mEventData->mPlaceholderFont->slantDefined = true;
846 mImpl->RequestRelayout();
850 bool Controller::IsPlaceholderTextFontSlantDefined() const
852 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
854 return mImpl->mEventData->mPlaceholderFont->slantDefined;
859 FontSlant Controller::GetPlaceholderTextFontSlant() const
861 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
863 return mImpl->mEventData->mPlaceholderFont->mFontDescription.slant;
866 return TextAbstraction::FontSlant::NORMAL;
869 void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
871 if( NULL == mImpl->mFontDefaults )
873 mImpl->mFontDefaults = new FontDefaults();
880 mImpl->mFontDefaults->mDefaultPointSize = fontSize;
881 mImpl->mFontDefaults->sizeDefined = true;
886 // Point size = Pixel size * 72.f / DPI
887 unsigned int horizontalDpi = 0u;
888 unsigned int verticalDpi = 0u;
889 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
890 fontClient.GetDpi( horizontalDpi, verticalDpi );
892 mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
893 mImpl->mFontDefaults->sizeDefined = true;
898 // Clear the font-specific data
901 mImpl->RequestRelayout();
904 float Controller::GetDefaultFontSize( FontSizeType type ) const
907 if( NULL != mImpl->mFontDefaults )
913 value = mImpl->mFontDefaults->mDefaultPointSize;
918 // Pixel size = Point size * DPI / 72.f
919 unsigned int horizontalDpi = 0u;
920 unsigned int verticalDpi = 0u;
921 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
922 fontClient.GetDpi( horizontalDpi, verticalDpi );
924 value = mImpl->mFontDefaults->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
934 void Controller::SetPlaceholderTextFontSize( float fontSize, FontSizeType type )
936 if( NULL != mImpl->mEventData )
938 if( NULL == mImpl->mEventData->mPlaceholderFont )
940 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
947 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = fontSize;
948 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
949 mImpl->mEventData->mIsPlaceholderPixelSize = false; // Font size flag
954 // Point size = Pixel size * 72.f / DPI
955 unsigned int horizontalDpi = 0u;
956 unsigned int verticalDpi = 0u;
957 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
958 fontClient.GetDpi( horizontalDpi, verticalDpi );
960 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
961 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
962 mImpl->mEventData->mIsPlaceholderPixelSize = true; // Font size flag
967 mImpl->RequestRelayout();
971 float Controller::GetPlaceholderTextFontSize( FontSizeType type ) const
974 if( NULL != mImpl->mEventData )
980 if( NULL != mImpl->mEventData->mPlaceholderFont )
982 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize;
986 // If the placeholder text font size is not set, then return the default font size.
987 value = GetDefaultFontSize( POINT_SIZE );
993 if( NULL != mImpl->mEventData->mPlaceholderFont )
995 // Pixel size = Point size * DPI / 72.f
996 unsigned int horizontalDpi = 0u;
997 unsigned int verticalDpi = 0u;
998 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
999 fontClient.GetDpi( horizontalDpi, verticalDpi );
1001 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1005 // If the placeholder text font size is not set, then return the default font size.
1006 value = GetDefaultFontSize( PIXEL_SIZE );
1017 void Controller::SetDefaultColor( const Vector4& color )
1019 mImpl->mTextColor = color;
1021 if( !mImpl->IsShowingPlaceholderText() )
1023 mImpl->mModel->mVisualModel->SetTextColor( color );
1025 mImpl->RequestRelayout();
1029 const Vector4& Controller::GetDefaultColor() const
1031 return mImpl->mTextColor;
1034 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
1036 if( NULL != mImpl->mEventData )
1038 mImpl->mEventData->mPlaceholderTextColor = textColor;
1041 if( mImpl->IsShowingPlaceholderText() )
1043 mImpl->mModel->mVisualModel->SetTextColor( textColor );
1044 mImpl->RequestRelayout();
1048 const Vector4& Controller::GetPlaceholderTextColor() const
1050 if( NULL != mImpl->mEventData )
1052 return mImpl->mEventData->mPlaceholderTextColor;
1055 return Color::BLACK;
1058 void Controller::SetShadowOffset( const Vector2& shadowOffset )
1060 mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
1062 mImpl->RequestRelayout();
1065 const Vector2& Controller::GetShadowOffset() const
1067 return mImpl->mModel->mVisualModel->GetShadowOffset();
1070 void Controller::SetShadowColor( const Vector4& shadowColor )
1072 mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
1074 mImpl->RequestRelayout();
1077 const Vector4& Controller::GetShadowColor() const
1079 return mImpl->mModel->mVisualModel->GetShadowColor();
1082 void Controller::SetUnderlineColor( const Vector4& color )
1084 mImpl->mModel->mVisualModel->SetUnderlineColor( color );
1086 mImpl->RequestRelayout();
1089 const Vector4& Controller::GetUnderlineColor() const
1091 return mImpl->mModel->mVisualModel->GetUnderlineColor();
1094 void Controller::SetUnderlineEnabled( bool enabled )
1096 mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
1098 mImpl->RequestRelayout();
1101 bool Controller::IsUnderlineEnabled() const
1103 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
1106 void Controller::SetUnderlineHeight( float height )
1108 mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
1110 mImpl->RequestRelayout();
1113 float Controller::GetUnderlineHeight() const
1115 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
1118 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
1120 if( NULL == mImpl->mEmbossDefaults )
1122 mImpl->mEmbossDefaults = new EmbossDefaults();
1125 mImpl->mEmbossDefaults->properties = embossProperties;
1128 const std::string& Controller::GetDefaultEmbossProperties() const
1130 if( NULL != mImpl->mEmbossDefaults )
1132 return mImpl->mEmbossDefaults->properties;
1135 return EMPTY_STRING;
1138 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
1140 if( NULL == mImpl->mOutlineDefaults )
1142 mImpl->mOutlineDefaults = new OutlineDefaults();
1145 mImpl->mOutlineDefaults->properties = outlineProperties;
1148 const std::string& Controller::GetDefaultOutlineProperties() const
1150 if( NULL != mImpl->mOutlineDefaults )
1152 return mImpl->mOutlineDefaults->properties;
1155 return EMPTY_STRING;
1158 void Controller::SetDefaultLineSpacing( float lineSpacing )
1160 //TODO finish implementation
1161 mImpl->mLayoutEngine.SetDefaultLineSpacing( lineSpacing );
1164 float Controller::GetDefaultLineSpacing() const
1166 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
1169 void Controller::SetInputColor( const Vector4& color )
1171 if( NULL != mImpl->mEventData )
1173 mImpl->mEventData->mInputStyle.textColor = color;
1174 mImpl->mEventData->mInputStyle.isDefaultColor = false;
1176 if( EventData::SELECTING == mImpl->mEventData->mState )
1178 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
1180 // Get start and end position of selection
1181 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
1182 const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
1184 // Add the color run.
1185 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1186 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
1188 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
1189 colorRun.color = color;
1190 colorRun.characterRun.characterIndex = startOfSelectedText;
1191 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1193 // Request to relayout.
1194 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1195 mImpl->RequestRelayout();
1197 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1198 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1199 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1204 const Vector4& Controller::GetInputColor() const
1206 if( NULL != mImpl->mEventData )
1208 return mImpl->mEventData->mInputStyle.textColor;
1211 // Return the default text's color if there is no EventData.
1212 return mImpl->mTextColor;
1216 void Controller::SetInputFontFamily( const std::string& fontFamily )
1218 if( NULL != mImpl->mEventData )
1220 mImpl->mEventData->mInputStyle.familyName = fontFamily;
1221 mImpl->mEventData->mInputStyle.isFamilyDefined = true;
1223 if( EventData::SELECTING == mImpl->mEventData->mState )
1225 CharacterIndex startOfSelectedText = 0u;
1226 Length lengthOfSelectedText = 0u;
1227 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1228 mImpl->mModel->mLogicalModel,
1229 startOfSelectedText,
1230 lengthOfSelectedText );
1232 fontDescriptionRun.familyLength = fontFamily.size();
1233 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
1234 memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength );
1235 fontDescriptionRun.familyDefined = true;
1237 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
1239 // Request to relayout.
1240 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1245 UPDATE_LAYOUT_SIZE |
1248 mImpl->mRecalculateNaturalSize = true;
1249 mImpl->RequestRelayout();
1251 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1252 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1253 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1255 // As the font changes, recalculate the handle positions is needed.
1256 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1257 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1258 mImpl->mEventData->mUpdateHighlightBox = true;
1259 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1264 const std::string& Controller::GetInputFontFamily() const
1266 if( NULL != mImpl->mEventData )
1268 return mImpl->mEventData->mInputStyle.familyName;
1271 // Return the default font's family if there is no EventData.
1272 return GetDefaultFontFamily();
1275 void Controller::SetInputFontWeight( FontWeight weight )
1277 if( NULL != mImpl->mEventData )
1279 mImpl->mEventData->mInputStyle.weight = weight;
1280 mImpl->mEventData->mInputStyle.isWeightDefined = true;
1282 if( EventData::SELECTING == mImpl->mEventData->mState )
1284 CharacterIndex startOfSelectedText = 0u;
1285 Length lengthOfSelectedText = 0u;
1286 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1287 mImpl->mModel->mLogicalModel,
1288 startOfSelectedText,
1289 lengthOfSelectedText );
1291 fontDescriptionRun.weight = weight;
1292 fontDescriptionRun.weightDefined = true;
1294 // Request to relayout.
1295 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1300 UPDATE_LAYOUT_SIZE |
1303 mImpl->mRecalculateNaturalSize = true;
1304 mImpl->RequestRelayout();
1306 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1307 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1308 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1310 // As the font might change, recalculate the handle positions is needed.
1311 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1312 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1313 mImpl->mEventData->mUpdateHighlightBox = true;
1314 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1319 bool Controller::IsInputFontWeightDefined() const
1321 bool defined = false;
1323 if( NULL != mImpl->mEventData )
1325 defined = mImpl->mEventData->mInputStyle.isWeightDefined;
1331 FontWeight Controller::GetInputFontWeight() const
1333 if( NULL != mImpl->mEventData )
1335 return mImpl->mEventData->mInputStyle.weight;
1338 return GetDefaultFontWeight();
1341 void Controller::SetInputFontWidth( FontWidth width )
1343 if( NULL != mImpl->mEventData )
1345 mImpl->mEventData->mInputStyle.width = width;
1346 mImpl->mEventData->mInputStyle.isWidthDefined = true;
1348 if( EventData::SELECTING == mImpl->mEventData->mState )
1350 CharacterIndex startOfSelectedText = 0u;
1351 Length lengthOfSelectedText = 0u;
1352 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1353 mImpl->mModel->mLogicalModel,
1354 startOfSelectedText,
1355 lengthOfSelectedText );
1357 fontDescriptionRun.width = width;
1358 fontDescriptionRun.widthDefined = true;
1360 // Request to relayout.
1361 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1366 UPDATE_LAYOUT_SIZE |
1369 mImpl->mRecalculateNaturalSize = true;
1370 mImpl->RequestRelayout();
1372 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1373 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1374 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1376 // As the font might change, recalculate the handle positions is needed.
1377 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1378 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1379 mImpl->mEventData->mUpdateHighlightBox = true;
1380 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1385 bool Controller::IsInputFontWidthDefined() const
1387 bool defined = false;
1389 if( NULL != mImpl->mEventData )
1391 defined = mImpl->mEventData->mInputStyle.isWidthDefined;
1397 FontWidth Controller::GetInputFontWidth() const
1399 if( NULL != mImpl->mEventData )
1401 return mImpl->mEventData->mInputStyle.width;
1404 return GetDefaultFontWidth();
1407 void Controller::SetInputFontSlant( FontSlant slant )
1409 if( NULL != mImpl->mEventData )
1411 mImpl->mEventData->mInputStyle.slant = slant;
1412 mImpl->mEventData->mInputStyle.isSlantDefined = true;
1414 if( EventData::SELECTING == mImpl->mEventData->mState )
1416 CharacterIndex startOfSelectedText = 0u;
1417 Length lengthOfSelectedText = 0u;
1418 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1419 mImpl->mModel->mLogicalModel,
1420 startOfSelectedText,
1421 lengthOfSelectedText );
1423 fontDescriptionRun.slant = slant;
1424 fontDescriptionRun.slantDefined = true;
1426 // Request to relayout.
1427 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1432 UPDATE_LAYOUT_SIZE |
1435 mImpl->mRecalculateNaturalSize = true;
1436 mImpl->RequestRelayout();
1438 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1439 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1440 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1442 // As the font might change, recalculate the handle positions is needed.
1443 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1444 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1445 mImpl->mEventData->mUpdateHighlightBox = true;
1446 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1451 bool Controller::IsInputFontSlantDefined() const
1453 bool defined = false;
1455 if( NULL != mImpl->mEventData )
1457 defined = mImpl->mEventData->mInputStyle.isSlantDefined;
1463 FontSlant Controller::GetInputFontSlant() const
1465 if( NULL != mImpl->mEventData )
1467 return mImpl->mEventData->mInputStyle.slant;
1470 return GetDefaultFontSlant();
1473 void Controller::SetInputFontPointSize( float size )
1475 if( NULL != mImpl->mEventData )
1477 mImpl->mEventData->mInputStyle.size = size;
1478 mImpl->mEventData->mInputStyle.isSizeDefined = true;
1480 if( EventData::SELECTING == mImpl->mEventData->mState )
1482 CharacterIndex startOfSelectedText = 0u;
1483 Length lengthOfSelectedText = 0u;
1484 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1485 mImpl->mModel->mLogicalModel,
1486 startOfSelectedText,
1487 lengthOfSelectedText );
1489 fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
1490 fontDescriptionRun.sizeDefined = true;
1492 // Request to relayout.
1493 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1498 UPDATE_LAYOUT_SIZE |
1501 mImpl->mRecalculateNaturalSize = true;
1502 mImpl->RequestRelayout();
1504 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1505 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1506 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1508 // As the font might change, recalculate the handle positions is needed.
1509 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1510 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1511 mImpl->mEventData->mUpdateHighlightBox = true;
1512 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1517 float Controller::GetInputFontPointSize() const
1519 if( NULL != mImpl->mEventData )
1521 return mImpl->mEventData->mInputStyle.size;
1524 // Return the default font's point size if there is no EventData.
1525 return GetDefaultFontSize( Text::Controller::POINT_SIZE );
1528 void Controller::SetInputLineSpacing( float lineSpacing )
1530 if( NULL != mImpl->mEventData )
1532 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1533 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1537 float Controller::GetInputLineSpacing() const
1539 if( NULL != mImpl->mEventData )
1541 return mImpl->mEventData->mInputStyle.lineSpacing;
1547 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1549 if( NULL != mImpl->mEventData )
1551 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1555 const std::string& Controller::GetInputShadowProperties() const
1557 if( NULL != mImpl->mEventData )
1559 return mImpl->mEventData->mInputStyle.shadowProperties;
1562 return EMPTY_STRING;
1565 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1567 if( NULL != mImpl->mEventData )
1569 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1573 const std::string& Controller::GetInputUnderlineProperties() const
1575 if( NULL != mImpl->mEventData )
1577 return mImpl->mEventData->mInputStyle.underlineProperties;
1580 return EMPTY_STRING;
1583 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
1585 if( NULL != mImpl->mEventData )
1587 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1591 const std::string& Controller::GetInputEmbossProperties() const
1593 if( NULL != mImpl->mEventData )
1595 return mImpl->mEventData->mInputStyle.embossProperties;
1598 return GetDefaultEmbossProperties();
1601 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
1603 if( NULL != mImpl->mEventData )
1605 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1609 const std::string& Controller::GetInputOutlineProperties() const
1611 if( NULL != mImpl->mEventData )
1613 return mImpl->mEventData->mInputStyle.outlineProperties;
1616 return GetDefaultOutlineProperties();
1619 void Controller::SetInputModePassword( bool passwordInput )
1621 if( NULL != mImpl->mEventData )
1623 mImpl->mEventData->mPasswordInput = passwordInput;
1627 bool Controller::IsInputModePassword()
1629 if( NULL != mImpl->mEventData )
1631 return mImpl->mEventData->mPasswordInput;
1636 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
1638 if( NULL != mImpl->mEventData )
1640 mImpl->mEventData->mDoubleTapAction = action;
1644 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1646 NoTextTap::Action action = NoTextTap::NO_ACTION;
1648 if( NULL != mImpl->mEventData )
1650 action = mImpl->mEventData->mDoubleTapAction;
1656 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
1658 if( NULL != mImpl->mEventData )
1660 mImpl->mEventData->mLongPressAction = action;
1664 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1666 NoTextTap::Action action = NoTextTap::NO_ACTION;
1668 if( NULL != mImpl->mEventData )
1670 action = mImpl->mEventData->mLongPressAction;
1676 bool Controller::IsUnderlineSetByString()
1678 return mImpl->mUnderlineSetByString;
1681 void Controller::UnderlineSetByString( bool setByString )
1683 mImpl->mUnderlineSetByString = setByString;
1686 bool Controller::IsShadowSetByString()
1688 return mImpl->mShadowSetByString;
1691 void Controller::ShadowSetByString( bool setByString )
1693 mImpl->mShadowSetByString = setByString;
1696 bool Controller::IsFontStyleSetByString()
1698 return mImpl->mFontStyleSetByString;
1701 void Controller::FontStyleSetByString( bool setByString )
1703 mImpl->mFontStyleSetByString = setByString;
1706 // public : Queries & retrieves.
1708 Layout::Engine& Controller::GetLayoutEngine()
1710 return mImpl->mLayoutEngine;
1713 View& Controller::GetView()
1715 return mImpl->mView;
1718 Vector3 Controller::GetNaturalSize()
1720 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
1721 Vector3 naturalSize;
1723 // Make sure the model is up-to-date before layouting
1724 ProcessModifyEvents();
1726 if( mImpl->mRecalculateNaturalSize )
1728 // Operations that can be done only once until the text changes.
1729 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1736 GET_GLYPH_METRICS );
1738 // Set the update info to relayout the whole text.
1739 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1740 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1742 // Make sure the model is up-to-date before layouting
1743 mImpl->UpdateModel( onlyOnceOperations );
1745 // Layout the text for the new width.
1746 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT | REORDER );
1748 // Store the actual control's size to restore later.
1749 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
1751 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
1752 static_cast<OperationsMask>( onlyOnceOperations |
1754 naturalSize.GetVectorXY() );
1756 // Do not do again the only once operations.
1757 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1759 // Do the size related operations again.
1760 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1763 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1765 // Stores the natural size to avoid recalculate it again
1766 // unless the text/style changes.
1767 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
1769 mImpl->mRecalculateNaturalSize = false;
1771 // Clear the update info. This info will be set the next time the text is updated.
1772 mImpl->mTextUpdateInfo.Clear();
1774 // Restore the actual control's size.
1775 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
1777 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1781 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
1783 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1786 naturalSize.x = ConvertToEven( naturalSize.x );
1787 naturalSize.y = ConvertToEven( naturalSize.y );
1792 float Controller::GetHeightForWidth( float width )
1794 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
1795 // Make sure the model is up-to-date before layouting
1796 ProcessModifyEvents();
1799 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ||
1800 mImpl->mTextUpdateInfo.mFullRelayoutNeeded ||
1801 mImpl->mTextUpdateInfo.mClearAll )
1803 // Operations that can be done only once until the text changes.
1804 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1811 GET_GLYPH_METRICS );
1813 // Set the update info to relayout the whole text.
1814 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1815 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1817 // Make sure the model is up-to-date before layouting
1818 mImpl->UpdateModel( onlyOnceOperations );
1821 // Layout the text for the new width.
1822 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
1824 // Store the actual control's width.
1825 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
1827 DoRelayout( Size( width, MAX_FLOAT ),
1828 static_cast<OperationsMask>( onlyOnceOperations |
1832 // Do not do again the only once operations.
1833 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1835 // Do the size related operations again.
1836 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1840 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1842 // Clear the update info. This info will be set the next time the text is updated.
1843 mImpl->mTextUpdateInfo.Clear();
1845 // Restore the actual control's width.
1846 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
1848 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
1852 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
1853 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
1856 return layoutSize.height;
1859 int Controller::GetLineCount( float width )
1861 GetHeightForWidth( width );
1862 int numberofLines = mImpl->mModel->GetNumberOfLines();
1863 return numberofLines;
1866 const ModelInterface* const Controller::GetTextModel() const
1868 return mImpl->mModel.Get();
1871 float Controller::GetScrollAmountByUserInput()
1873 float scrollAmount = 0.0f;
1875 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
1877 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
1878 mImpl->mEventData->mCheckScrollAmount = false;
1880 return scrollAmount;
1883 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
1885 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
1888 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
1889 layoutHeight = layout.height;
1890 scrollPosition = mImpl->mModel->mScrollPosition.y;
1891 isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
1895 void Controller::SetHiddenInputOption(const Property::Map& options )
1897 if( NULL == mImpl->mHiddenInput )
1899 mImpl->mHiddenInput = new HiddenText( this );
1901 mImpl->mHiddenInput->SetProperties(options);
1904 void Controller::GetHiddenInputOption(Property::Map& options )
1906 if( NULL != mImpl->mHiddenInput )
1908 mImpl->mHiddenInput->GetProperties(options);
1912 void Controller::SetPlaceholderProperty( const Property::Map& map )
1914 const Property::Map::SizeType count = map.Count();
1916 for( Property::Map::SizeType position = 0; position < count; ++position )
1918 KeyValuePair keyValue = map.GetKeyValue( position );
1919 Property::Key& key = keyValue.first;
1920 Property::Value& value = keyValue.second;
1922 if( key == PLACEHOLDER_TEXT )
1924 std::string text = "";
1926 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
1928 else if( key == PLACEHOLDER_TEXT_FOCUSED )
1930 std::string text = "";
1932 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
1934 else if( key == PLACEHOLDER_COLOR )
1937 value.Get( textColor );
1938 if( GetPlaceholderTextColor() != textColor )
1940 SetPlaceholderTextColor( textColor );
1943 else if( key == PLACEHOLDER_FONT_FAMILY )
1945 std::string fontFamily = "";
1946 value.Get( fontFamily );
1947 SetPlaceholderFontFamily( fontFamily );
1949 else if( key == PLACEHOLDER_FONT_STYLE )
1951 SetFontStyleProperty( this, value, Text::FontStyle::PLACEHOLDER );
1953 else if( key == PLACEHOLDER_POINT_SIZE )
1956 value.Get( pointSize );
1957 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
1959 SetPlaceholderTextFontSize( pointSize, Text::Controller::POINT_SIZE );
1962 else if( key == PLACEHOLDER_PIXEL_SIZE )
1965 value.Get( pixelSize );
1966 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
1968 SetPlaceholderTextFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
1974 void Controller::GetPlaceholderProperty( Property::Map& map )
1976 if( NULL != mImpl->mEventData )
1978 if( !mImpl->mEventData->mPlaceholderTextActive.empty() )
1980 map[ PLACEHOLDER_TEXT_FOCUSED ] = mImpl->mEventData->mPlaceholderTextActive;
1982 if( !mImpl->mEventData->mPlaceholderTextInactive.empty() )
1984 map[ PLACEHOLDER_TEXT ] = mImpl->mEventData->mPlaceholderTextInactive;
1987 map[ PLACEHOLDER_COLOR ] = mImpl->mEventData->mPlaceholderTextColor;
1988 map[ PLACEHOLDER_FONT_FAMILY ] = GetPlaceholderFontFamily();
1990 Property::Value fontStyleMapGet;
1991 GetFontStyleProperty( this, fontStyleMapGet, Text::FontStyle::PLACEHOLDER );
1992 map[ PLACEHOLDER_FONT_STYLE ] = fontStyleMapGet;
1994 // Choose font size : POINT_SIZE or PIXEL_SIZE
1995 if( !mImpl->mEventData->mIsPlaceholderPixelSize )
1997 map[ PLACEHOLDER_POINT_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE );
2001 map[ PLACEHOLDER_PIXEL_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE );
2006 // public : Relayout.
2008 Controller::UpdateTextType Controller::Relayout( const Size& size )
2010 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
2012 UpdateTextType updateTextType = NONE_UPDATED;
2014 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
2016 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
2018 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
2019 updateTextType = MODEL_UPDATED;
2022 // Clear the update info. This info will be set the next time the text is updated.
2023 mImpl->mTextUpdateInfo.Clear();
2025 // Not worth to relayout if width or height is equal to zero.
2026 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
2028 return updateTextType;
2031 // Whether a new size has been set.
2032 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
2036 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
2038 // Layout operations that need to be done if the size changes.
2039 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2042 UPDATE_LAYOUT_SIZE |
2044 // Set the update info to relayout the whole text.
2045 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2046 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2048 // Store the size used to layout the text.
2049 mImpl->mModel->mVisualModel->mControlSize = size;
2052 // Whether there are modify events.
2053 if( 0u != mImpl->mModifyEvents.Count() )
2055 // Style operations that need to be done if the text is modified.
2056 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2060 // Make sure the model is up-to-date before layouting.
2061 ProcessModifyEvents();
2062 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
2066 updated = DoRelayout( size,
2067 mImpl->mOperationsPending,
2068 layoutSize ) || updated;
2072 updateTextType = MODEL_UPDATED;
2075 // Do not re-do any operation until something changes.
2076 mImpl->mOperationsPending = NO_OPERATION;
2077 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
2079 // Whether the text control is editable
2080 const bool isEditable = NULL != mImpl->mEventData;
2082 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
2084 if( newSize && isEditable )
2086 offset = mImpl->mModel->mScrollPosition;
2089 if( !isEditable || !IsMultiLineEnabled() )
2091 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
2092 CalculateVerticalOffset( size );
2099 // If there is a new size, the scroll position needs to be clamped.
2100 mImpl->ClampHorizontalScroll( layoutSize );
2102 // Update the decorator's positions is needed if there is a new size.
2103 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
2106 // Move the cursor, grab handle etc.
2107 if( mImpl->ProcessInputEvents() )
2109 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
2113 // Clear the update info. This info will be set the next time the text is updated.
2114 mImpl->mTextUpdateInfo.Clear();
2115 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
2117 return updateTextType;
2120 void Controller::RequestRelayout()
2122 mImpl->RequestRelayout();
2125 // public : Input style change signals.
2127 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
2129 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
2132 void Controller::ProcessInputStyleChangedSignals()
2134 if( NULL == mImpl->mEventData )
2140 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
2141 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
2145 const InputStyle::Mask mask = *it;
2147 if( NULL != mImpl->mEditableControlInterface )
2149 // Emit the input style changed signal.
2150 mImpl->mEditableControlInterface->InputStyleChanged( mask );
2154 mImpl->mEventData->mInputStyleChangedQueue.Clear();
2157 // public : Text-input Event Queuing.
2159 void Controller::KeyboardFocusGainEvent()
2161 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
2163 if( NULL != mImpl->mEventData )
2165 if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
2166 ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
2168 mImpl->ChangeState( EventData::EDITING );
2169 mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
2170 mImpl->mEventData->mUpdateInputStyle = true;
2172 mImpl->NotifyImfMultiLineStatus();
2173 if( mImpl->IsShowingPlaceholderText() )
2175 // Show alternative placeholder-text when editing
2176 ShowPlaceholderText();
2179 mImpl->RequestRelayout();
2183 void Controller::KeyboardFocusLostEvent()
2185 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
2187 if( NULL != mImpl->mEventData )
2189 if( EventData::INTERRUPTED != mImpl->mEventData->mState )
2191 mImpl->ChangeState( EventData::INACTIVE );
2193 if( !mImpl->IsShowingRealText() )
2195 // Revert to regular placeholder-text when not editing
2196 ShowPlaceholderText();
2200 mImpl->RequestRelayout();
2203 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
2205 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
2207 bool textChanged = false;
2208 bool relayoutNeeded = false;
2210 if( ( NULL != mImpl->mEventData ) &&
2211 ( keyEvent.state == KeyEvent::Down ) )
2213 int keyCode = keyEvent.keyCode;
2214 const std::string& keyString = keyEvent.keyPressed;
2216 const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
2218 // Pre-process to separate modifying events from non-modifying input events.
2221 // In some platforms arrive key events with no key code.
2225 else if( Dali::DALI_KEY_ESCAPE == keyCode || Dali::DALI_KEY_BACK == keyCode )
2230 else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) ||
2231 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
2232 ( Dali::DALI_KEY_CURSOR_UP == keyCode ) ||
2233 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) )
2235 // If don't have any text, do nothing.
2236 if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
2241 uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition;
2242 uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2243 uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition );
2244 uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines();
2246 // Logic to determine whether this text control will lose focus or not.
2247 if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition ) ||
2248 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition) ||
2249 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) ||
2250 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) ||
2251 ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) ||
2252 ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) )
2257 mImpl->mEventData->mCheckScrollAmount = true;
2258 Event event( Event::CURSOR_KEY_EVENT );
2259 event.p1.mInt = keyCode;
2260 mImpl->mEventData->mEventQueue.push_back( event );
2262 // Will request for relayout.
2263 relayoutNeeded = true;
2265 else if( Dali::DALI_KEY_BACKSPACE == keyCode )
2267 textChanged = BackspaceKeyEvent();
2269 // Will request for relayout.
2270 relayoutNeeded = true;
2272 else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
2273 IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
2274 IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
2276 // Power key/Menu/Home key behaviour does not allow edit mode to resume.
2277 mImpl->ChangeState( EventData::INACTIVE );
2279 // Will request for relayout.
2280 relayoutNeeded = true;
2282 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2284 else if( Dali::DALI_KEY_SHIFT_LEFT == keyCode )
2286 // DALI_KEY_SHIFT_LEFT is the key code for the Left Shift. It's sent (by the imf?) when the predictive text is enabled
2287 // and a character is typed after the type of a upper case latin character.
2292 else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
2294 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2300 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
2302 // IMF manager is no longer handling key-events
2303 mImpl->ClearPreEditFlag();
2305 InsertText( keyString, COMMIT );
2308 // Will request for relayout.
2309 relayoutNeeded = true;
2312 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
2313 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
2315 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
2316 ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
2317 ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
2319 // Should not change the state if the key is the shift send by the imf manager.
2320 // Otherwise, when the state is SELECTING the text controller can't send the right
2321 // surrounding info to the imf.
2322 mImpl->ChangeState( EventData::EDITING );
2324 // Will request for relayout.
2325 relayoutNeeded = true;
2328 if( relayoutNeeded )
2330 mImpl->RequestRelayout();
2335 ( NULL != mImpl->mEditableControlInterface ) )
2337 // Do this last since it provides callbacks into application code
2338 mImpl->mEditableControlInterface->TextChanged();
2344 void Controller::TapEvent( unsigned int tapCount, float x, float y )
2346 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
2348 if( NULL != mImpl->mEventData )
2350 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
2351 EventData::State state( mImpl->mEventData->mState );
2352 bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
2354 if( mImpl->IsClipboardVisible() )
2356 if( EventData::INACTIVE == state || EventData::EDITING == state)
2358 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2360 relayoutNeeded = true;
2362 else if( 1u == tapCount )
2364 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
2366 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
2369 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
2371 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2372 relayoutNeeded = true;
2376 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
2378 // Hide placeholder text
2382 if( EventData::INACTIVE == state )
2384 mImpl->ChangeState( EventData::EDITING );
2386 else if( !mImpl->IsClipboardEmpty() )
2388 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
2390 relayoutNeeded = true;
2393 else if( 2u == tapCount )
2395 if( mImpl->mEventData->mSelectionEnabled &&
2396 mImpl->IsShowingRealText() )
2398 relayoutNeeded = true;
2399 mImpl->mEventData->mIsLeftHandleSelected = true;
2400 mImpl->mEventData->mIsRightHandleSelected = true;
2404 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
2405 if( relayoutNeeded )
2407 Event event( Event::TAP_EVENT );
2408 event.p1.mUint = tapCount;
2409 event.p2.mFloat = x;
2410 event.p3.mFloat = y;
2411 mImpl->mEventData->mEventQueue.push_back( event );
2413 mImpl->RequestRelayout();
2417 // Reset keyboard as tap event has occurred.
2418 mImpl->ResetImfManager();
2421 void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
2423 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
2425 if( NULL != mImpl->mEventData )
2427 Event event( Event::PAN_EVENT );
2428 event.p1.mInt = state;
2429 event.p2.mFloat = displacement.x;
2430 event.p3.mFloat = displacement.y;
2431 mImpl->mEventData->mEventQueue.push_back( event );
2433 mImpl->RequestRelayout();
2437 void Controller::LongPressEvent( Gesture::State state, float x, float y )
2439 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
2441 if( ( state == Gesture::Started ) &&
2442 ( NULL != mImpl->mEventData ) )
2444 // The 1st long-press on inactive text-field is treated as tap
2445 if( EventData::INACTIVE == mImpl->mEventData->mState )
2447 mImpl->ChangeState( EventData::EDITING );
2449 Event event( Event::TAP_EVENT );
2451 event.p2.mFloat = x;
2452 event.p3.mFloat = y;
2453 mImpl->mEventData->mEventQueue.push_back( event );
2455 mImpl->RequestRelayout();
2457 else if( !mImpl->IsShowingRealText() )
2459 Event event( Event::LONG_PRESS_EVENT );
2460 event.p1.mInt = state;
2461 event.p2.mFloat = x;
2462 event.p3.mFloat = y;
2463 mImpl->mEventData->mEventQueue.push_back( event );
2464 mImpl->RequestRelayout();
2466 else if( !mImpl->IsClipboardVisible() )
2468 // Reset the imf manager to commit the pre-edit before selecting the text.
2469 mImpl->ResetImfManager();
2471 Event event( Event::LONG_PRESS_EVENT );
2472 event.p1.mInt = state;
2473 event.p2.mFloat = x;
2474 event.p3.mFloat = y;
2475 mImpl->mEventData->mEventQueue.push_back( event );
2476 mImpl->RequestRelayout();
2478 mImpl->mEventData->mIsLeftHandleSelected = true;
2479 mImpl->mEventData->mIsRightHandleSelected = true;
2484 ImfManager::ImfCallbackData Controller::OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
2486 // Whether the text needs to be relaid-out.
2487 bool requestRelayout = false;
2489 // Whether to retrieve the text and cursor position to be sent to the IMF manager.
2490 bool retrieveText = false;
2491 bool retrieveCursor = false;
2493 switch( imfEvent.eventName )
2495 case ImfManager::COMMIT:
2497 InsertText( imfEvent.predictiveString, Text::Controller::COMMIT );
2498 requestRelayout = true;
2499 retrieveCursor = true;
2502 case ImfManager::PREEDIT:
2504 InsertText( imfEvent.predictiveString, Text::Controller::PRE_EDIT );
2505 requestRelayout = true;
2506 retrieveCursor = true;
2509 case ImfManager::DELETESURROUNDING:
2511 const bool textDeleted = RemoveText( imfEvent.cursorOffset,
2512 imfEvent.numberOfChars,
2513 DONT_UPDATE_INPUT_STYLE );
2517 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2518 !mImpl->IsPlaceholderAvailable() )
2520 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2524 ShowPlaceholderText();
2526 mImpl->mEventData->mUpdateCursorPosition = true;
2527 mImpl->mEventData->mScrollAfterDelete = true;
2529 requestRelayout = true;
2533 case ImfManager::GETSURROUNDING:
2535 retrieveText = true;
2536 retrieveCursor = true;
2539 case ImfManager::PRIVATECOMMAND:
2541 // PRIVATECOMMAND event is just for getting the private command message
2542 retrieveText = true;
2543 retrieveCursor = true;
2546 case ImfManager::VOID:
2553 if( requestRelayout )
2555 mImpl->mOperationsPending = ALL_OPERATIONS;
2556 mImpl->RequestRelayout();
2560 CharacterIndex cursorPosition = 0u;
2561 Length numberOfWhiteSpaces = 0u;
2563 if( retrieveCursor )
2565 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
2567 cursorPosition = mImpl->GetLogicalCursorPosition();
2569 if( cursorPosition < numberOfWhiteSpaces )
2571 cursorPosition = 0u;
2575 cursorPosition -= numberOfWhiteSpaces;
2581 mImpl->GetText( numberOfWhiteSpaces, text );
2584 ImfManager::ImfCallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
2586 if( requestRelayout &&
2587 ( NULL != mImpl->mEditableControlInterface ) )
2589 // Do this last since it provides callbacks into application code
2590 mImpl->mEditableControlInterface->TextChanged();
2593 return callbackData;
2596 void Controller::PasteClipboardItemEvent()
2598 // Retrieve the clipboard contents first
2599 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
2600 std::string stringToPaste( notifier.GetContent() );
2602 // Commit the current pre-edit text; the contents of the clipboard should be appended
2603 mImpl->ResetImfManager();
2605 // Temporary disable hiding clipboard
2606 mImpl->SetClipboardHideEnable( false );
2609 PasteText( stringToPaste );
2611 mImpl->SetClipboardHideEnable( true );
2614 // protected : Inherit from Text::Decorator::ControllerInterface.
2616 void Controller::GetTargetSize( Vector2& targetSize )
2618 targetSize = mImpl->mModel->mVisualModel->mControlSize;
2621 void Controller::AddDecoration( Actor& actor, bool needsClipping )
2623 if( NULL != mImpl->mEditableControlInterface )
2625 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
2629 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
2631 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
2633 if( NULL != mImpl->mEventData )
2635 switch( handleType )
2639 Event event( Event::GRAB_HANDLE_EVENT );
2640 event.p1.mUint = state;
2641 event.p2.mFloat = x;
2642 event.p3.mFloat = y;
2644 mImpl->mEventData->mEventQueue.push_back( event );
2647 case LEFT_SELECTION_HANDLE:
2649 Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
2650 event.p1.mUint = state;
2651 event.p2.mFloat = x;
2652 event.p3.mFloat = y;
2654 mImpl->mEventData->mEventQueue.push_back( event );
2657 case RIGHT_SELECTION_HANDLE:
2659 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
2660 event.p1.mUint = state;
2661 event.p2.mFloat = x;
2662 event.p3.mFloat = y;
2664 mImpl->mEventData->mEventQueue.push_back( event );
2667 case LEFT_SELECTION_HANDLE_MARKER:
2668 case RIGHT_SELECTION_HANDLE_MARKER:
2670 // Markers do not move the handles.
2673 case HANDLE_TYPE_COUNT:
2675 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
2679 mImpl->RequestRelayout();
2683 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
2685 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
2687 if( NULL == mImpl->mEventData )
2694 case Toolkit::TextSelectionPopup::CUT:
2696 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
2697 mImpl->mOperationsPending = ALL_OPERATIONS;
2699 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2700 !mImpl->IsPlaceholderAvailable() )
2702 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2706 ShowPlaceholderText();
2709 mImpl->mEventData->mUpdateCursorPosition = true;
2710 mImpl->mEventData->mScrollAfterDelete = true;
2712 mImpl->RequestRelayout();
2714 if( NULL != mImpl->mEditableControlInterface )
2716 mImpl->mEditableControlInterface->TextChanged();
2720 case Toolkit::TextSelectionPopup::COPY:
2722 mImpl->SendSelectionToClipboard( false ); // Text not modified
2724 mImpl->mEventData->mUpdateCursorPosition = true;
2726 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
2729 case Toolkit::TextSelectionPopup::PASTE:
2731 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
2734 case Toolkit::TextSelectionPopup::SELECT:
2736 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
2738 if( mImpl->mEventData->mSelectionEnabled )
2740 // Creates a SELECT event.
2741 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
2745 case Toolkit::TextSelectionPopup::SELECT_ALL:
2747 // Creates a SELECT_ALL event
2748 SelectEvent( 0.f, 0.f, true );
2751 case Toolkit::TextSelectionPopup::CLIPBOARD:
2753 mImpl->ShowClipboard();
2756 case Toolkit::TextSelectionPopup::NONE:
2764 void Controller::DisplayTimeExpired()
2766 mImpl->mEventData->mUpdateCursorPosition = true;
2767 // Apply modifications to the model
2768 mImpl->mOperationsPending = ALL_OPERATIONS;
2770 mImpl->RequestRelayout();
2773 // private : Update.
2775 void Controller::InsertText( const std::string& text, Controller::InsertType type )
2777 bool removedPrevious = false;
2778 bool removedSelected = false;
2779 bool maxLengthReached = false;
2781 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
2783 if( NULL == mImpl->mEventData )
2788 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
2789 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
2790 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
2792 // TODO: At the moment the underline runs are only for pre-edit.
2793 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
2795 // Remove the previous IMF pre-edit.
2796 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
2798 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
2799 mImpl->mEventData->mPreEditLength,
2800 DONT_UPDATE_INPUT_STYLE );
2802 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
2803 mImpl->mEventData->mPreEditLength = 0u;
2807 // Remove the previous Selection.
2808 removedSelected = RemoveSelectedText();
2812 Vector<Character> utf32Characters;
2813 Length characterCount = 0u;
2817 // Convert text into UTF-32
2818 utf32Characters.Resize( text.size() );
2820 // This is a bit horrible but std::string returns a (signed) char*
2821 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
2823 // Transform a text array encoded in utf8 into an array encoded in utf32.
2824 // It returns the actual number of characters.
2825 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
2826 utf32Characters.Resize( characterCount );
2828 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
2829 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
2832 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
2834 // The placeholder text is no longer needed
2835 if( mImpl->IsShowingPlaceholderText() )
2840 mImpl->ChangeState( EventData::EDITING );
2842 // Handle the IMF (predicitive text) state changes
2843 if( COMMIT == type )
2845 // IMF manager is no longer handling key-events
2846 mImpl->ClearPreEditFlag();
2850 if( !mImpl->mEventData->mPreEditFlag )
2852 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
2854 // Record the start of the pre-edit text
2855 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
2858 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
2859 mImpl->mEventData->mPreEditFlag = true;
2861 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
2864 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
2866 // Restrict new text to fit within Maximum characters setting.
2867 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
2868 maxLengthReached = ( characterCount > maxSizeOfNewText );
2870 // The cursor position.
2871 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
2873 // Update the text's style.
2875 // Updates the text style runs by adding characters.
2876 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
2878 // Get the character index from the cursor index.
2879 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
2881 // Retrieve the text's style for the given index.
2883 mImpl->RetrieveDefaultInputStyle( style );
2884 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
2886 // Whether to add a new text color run.
2887 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor );
2889 // Whether to add a new font run.
2890 const bool addFontNameRun = style.familyName != mImpl->mEventData->mInputStyle.familyName;
2891 const bool addFontWeightRun = style.weight != mImpl->mEventData->mInputStyle.weight;
2892 const bool addFontWidthRun = style.width != mImpl->mEventData->mInputStyle.width;
2893 const bool addFontSlantRun = style.slant != mImpl->mEventData->mInputStyle.slant;
2894 const bool addFontSizeRun = style.size != mImpl->mEventData->mInputStyle.size;
2899 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
2900 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
2902 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
2903 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
2904 colorRun.characterRun.characterIndex = cursorIndex;
2905 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
2908 if( addFontNameRun ||
2914 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
2915 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
2917 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
2919 if( addFontNameRun )
2921 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
2922 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
2923 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
2924 fontDescriptionRun.familyDefined = true;
2926 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
2929 if( addFontWeightRun )
2931 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
2932 fontDescriptionRun.weightDefined = true;
2935 if( addFontWidthRun )
2937 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
2938 fontDescriptionRun.widthDefined = true;
2941 if( addFontSlantRun )
2943 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
2944 fontDescriptionRun.slantDefined = true;
2947 if( addFontSizeRun )
2949 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
2950 fontDescriptionRun.sizeDefined = true;
2953 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
2954 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
2957 // Insert at current cursor position.
2958 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
2960 if( cursorIndex < numberOfCharactersInModel )
2962 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
2966 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
2969 // Mark the first paragraph to be updated.
2970 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
2972 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
2973 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2974 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
2975 mImpl->mTextUpdateInfo.mClearAll = true;
2979 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
2980 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
2983 // Update the cursor index.
2984 cursorIndex += maxSizeOfNewText;
2986 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 );
2989 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
2990 mImpl->IsPlaceholderAvailable() )
2992 // Show place-holder if empty after removing the pre-edit text
2993 ShowPlaceholderText();
2994 mImpl->mEventData->mUpdateCursorPosition = true;
2995 mImpl->ClearPreEditFlag();
2997 else if( removedPrevious ||
2999 ( 0 != utf32Characters.Count() ) )
3001 // Queue an inserted event
3002 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
3004 mImpl->mEventData->mUpdateCursorPosition = true;
3005 if( removedSelected )
3007 mImpl->mEventData->mScrollAfterDelete = true;
3011 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3015 if( maxLengthReached )
3017 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
3019 mImpl->ResetImfManager();
3021 if( NULL != mImpl->mEditableControlInterface )
3023 // Do this last since it provides callbacks into application code
3024 mImpl->mEditableControlInterface->MaxLengthReached();
3029 void Controller::PasteText( const std::string& stringToPaste )
3031 InsertText( stringToPaste, Text::Controller::COMMIT );
3032 mImpl->ChangeState( EventData::EDITING );
3033 mImpl->RequestRelayout();
3035 if( NULL != mImpl->mEditableControlInterface )
3037 // Do this last since it provides callbacks into application code
3038 mImpl->mEditableControlInterface->TextChanged();
3042 bool Controller::RemoveText( int cursorOffset,
3043 int numberOfCharacters,
3044 UpdateInputStyleType type )
3046 bool removed = false;
3048 if( NULL == mImpl->mEventData )
3053 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
3054 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
3056 if( !mImpl->IsShowingPlaceholderText() )
3058 // Delete at current cursor position
3059 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
3060 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3062 CharacterIndex cursorIndex = 0;
3064 // Validate the cursor position & number of characters
3065 if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
3067 cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
3070 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
3072 numberOfCharacters = currentText.Count() - cursorIndex;
3075 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.
3076 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
3078 // Mark the paragraphs to be updated.
3079 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3081 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3082 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3083 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
3084 mImpl->mTextUpdateInfo.mClearAll = true;
3088 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3089 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
3092 // Update the input style and remove the text's style before removing the text.
3094 if( UPDATE_INPUT_STYLE == type )
3096 // Keep a copy of the current input style.
3097 InputStyle currentInputStyle;
3098 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
3100 // Set first the default input style.
3101 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
3103 // Update the input style.
3104 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
3106 // Compare if the input style has changed.
3107 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
3109 if( hasInputStyleChanged )
3111 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
3112 // Queue the input style changed signal.
3113 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
3117 // Updates the text style runs by removing characters. Runs with no characters are removed.
3118 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
3120 // Remove the characters.
3121 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
3122 Vector<Character>::Iterator last = first + numberOfCharacters;
3124 currentText.Erase( first, last );
3126 // Cursor position retreat
3127 oldCursorIndex = cursorIndex;
3129 mImpl->mEventData->mScrollAfterDelete = true;
3131 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
3139 bool Controller::RemoveSelectedText()
3141 bool textRemoved( false );
3143 if( EventData::SELECTING == mImpl->mEventData->mState )
3145 std::string removedString;
3146 mImpl->RetrieveSelection( removedString, true );
3148 if( !removedString.empty() )
3151 mImpl->ChangeState( EventData::EDITING );
3158 // private : Relayout.
3160 bool Controller::DoRelayout( const Size& size,
3161 OperationsMask operationsRequired,
3164 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
3165 bool viewUpdated( false );
3167 // Calculate the operations to be done.
3168 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
3170 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
3171 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
3173 // Get the current layout size.
3174 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3176 if( NO_OPERATION != ( LAYOUT & operations ) )
3178 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
3180 // Some vectors with data needed to layout and reorder may be void
3181 // after the first time the text has been laid out.
3182 // Fill the vectors again.
3184 // Calculate the number of glyphs to layout.
3185 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
3186 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
3187 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
3188 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
3190 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
3191 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
3192 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
3193 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
3195 if( 0u == totalNumberOfGlyphs )
3197 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3199 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
3202 // Nothing else to do if there is no glyphs.
3203 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
3207 const Vector<LineBreakInfo>& lineBreakInfo = mImpl->mModel->mLogicalModel->mLineBreakInfo;
3208 const Vector<WordBreakInfo>& wordBreakInfo = mImpl->mModel->mLogicalModel->mWordBreakInfo;
3209 const Vector<CharacterDirection>& characterDirection = mImpl->mModel->mLogicalModel->mCharacterDirections;
3210 const Vector<GlyphInfo>& glyphs = mImpl->mModel->mVisualModel->mGlyphs;
3211 const Vector<CharacterIndex>& glyphsToCharactersMap = mImpl->mModel->mVisualModel->mGlyphsToCharacters;
3212 const Vector<Length>& charactersPerGlyph = mImpl->mModel->mVisualModel->mCharactersPerGlyph;
3213 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
3215 // Set the layout parameters.
3216 Layout::Parameters layoutParameters( size,
3218 lineBreakInfo.Begin(),
3219 wordBreakInfo.Begin(),
3220 ( 0u != characterDirection.Count() ) ? characterDirection.Begin() : NULL,
3222 glyphsToCharactersMap.Begin(),
3223 charactersPerGlyph.Begin(),
3224 charactersToGlyphBuffer,
3225 glyphsPerCharacterBuffer,
3226 totalNumberOfGlyphs,
3227 mImpl->mModel->mHorizontalAlignment,
3228 mImpl->mModel->mLineWrapMode );
3230 // Resize the vector of positions to have the same size than the vector of glyphs.
3231 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
3232 glyphPositions.Resize( totalNumberOfGlyphs );
3234 // Whether the last character is a new paragraph character.
3235 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
3236 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
3238 // The initial glyph and the number of glyphs to layout.
3239 layoutParameters.startGlyphIndex = startGlyphIndex;
3240 layoutParameters.numberOfGlyphs = numberOfGlyphs;
3241 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
3242 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
3244 // Update the visual model.
3246 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
3248 mImpl->mModel->mVisualModel->mLines,
3250 mImpl->mModel->mElideEnabled );
3252 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
3256 layoutSize = newLayoutSize;
3258 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
3260 mImpl->mAutoScrollDirectionRTL = false;
3263 // Reorder the lines
3264 if( NO_OPERATION != ( REORDER & operations ) )
3266 Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = mImpl->mModel->mLogicalModel->mBidirectionalParagraphInfo;
3267 Vector<BidirectionalLineInfoRun>& bidirectionalLineInfo = mImpl->mModel->mLogicalModel->mBidirectionalLineInfo;
3269 // Check first if there are paragraphs with bidirectional info.
3270 if( 0u != bidirectionalInfo.Count() )
3273 const Length numberOfLines = mImpl->mModel->mVisualModel->mLines.Count();
3275 // Reorder the lines.
3276 bidirectionalLineInfo.Reserve( numberOfLines ); // Reserve because is not known yet how many lines have right to left characters.
3277 ReorderLines( bidirectionalInfo,
3279 requestedNumberOfCharacters,
3280 mImpl->mModel->mVisualModel->mLines,
3281 bidirectionalLineInfo );
3283 // Set the bidirectional info per line into the layout parameters.
3284 layoutParameters.lineBidirectionalInfoRunsBuffer = bidirectionalLineInfo.Begin();
3285 layoutParameters.numberOfBidirectionalInfoRuns = bidirectionalLineInfo.Count();
3287 // Re-layout the text. Reorder those lines with right to left characters.
3288 mImpl->mLayoutEngine.ReLayoutRightToLeftLines( layoutParameters,
3290 requestedNumberOfCharacters,
3293 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && ( numberOfLines > 0 ) )
3295 const LineRun* const firstline = mImpl->mModel->mVisualModel->mLines.Begin();
3298 mImpl->mAutoScrollDirectionRTL = firstline->direction;
3304 // Sets the layout size.
3305 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3307 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
3312 if( NO_OPERATION != ( ALIGN & operations ) )
3314 // The laid-out lines.
3315 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
3317 // Need to align with the control's size as the text may contain lines
3318 // starting either with left to right text or right to left.
3319 mImpl->mLayoutEngine.Align( size,
3321 requestedNumberOfCharacters,
3322 mImpl->mModel->mHorizontalAlignment,
3324 mImpl->mModel->mAlignmentOffset );
3328 #if defined(DEBUG_ENABLED)
3329 std::string currentText;
3330 GetText( currentText );
3331 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mAutoScrollDirectionRTL[%s] [%s]\n", this, (mImpl->mAutoScrollDirectionRTL)?"true":"false", currentText.c_str() );
3333 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
3337 void Controller::CalculateVerticalOffset( const Size& controlSize )
3339 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3341 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
3343 // Get the line height of the default font.
3344 layoutSize.height = mImpl->GetDefaultFontLineHeight();
3347 switch( mImpl->mModel->mVerticalAlignment )
3349 case Layout::VERTICAL_ALIGN_TOP:
3351 mImpl->mModel->mScrollPosition.y = 0.f;
3354 case Layout::VERTICAL_ALIGN_CENTER:
3356 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
3359 case Layout::VERTICAL_ALIGN_BOTTOM:
3361 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
3367 // private : Events.
3369 void Controller::ProcessModifyEvents()
3371 Vector<ModifyEvent>& events = mImpl->mModifyEvents;
3373 if( 0u == events.Count() )
3379 for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
3380 endIt = events.End();
3384 const ModifyEvent& event = *it;
3386 if( ModifyEvent::TEXT_REPLACED == event.type )
3388 // A (single) replace event should come first, otherwise we wasted time processing NOOP events
3389 DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
3391 TextReplacedEvent();
3393 else if( ModifyEvent::TEXT_INSERTED == event.type )
3395 TextInsertedEvent();
3397 else if( ModifyEvent::TEXT_DELETED == event.type )
3399 // Placeholder-text cannot be deleted
3400 if( !mImpl->IsShowingPlaceholderText() )
3407 if( NULL != mImpl->mEventData )
3409 // When the text is being modified, delay cursor blinking
3410 mImpl->mEventData->mDecorator->DelayCursorBlink();
3413 // Discard temporary text
3417 void Controller::TextReplacedEvent()
3419 // The natural size needs to be re-calculated.
3420 mImpl->mRecalculateNaturalSize = true;
3422 // Apply modifications to the model
3423 mImpl->mOperationsPending = ALL_OPERATIONS;
3426 void Controller::TextInsertedEvent()
3428 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
3430 if( NULL == mImpl->mEventData )
3435 mImpl->mEventData->mCheckScrollAmount = true;
3437 // The natural size needs to be re-calculated.
3438 mImpl->mRecalculateNaturalSize = true;
3440 // Apply modifications to the model; TODO - Optimize this
3441 mImpl->mOperationsPending = ALL_OPERATIONS;
3444 void Controller::TextDeletedEvent()
3446 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
3448 if( NULL == mImpl->mEventData )
3453 mImpl->mEventData->mCheckScrollAmount = true;
3455 // The natural size needs to be re-calculated.
3456 mImpl->mRecalculateNaturalSize = true;
3458 // Apply modifications to the model; TODO - Optimize this
3459 mImpl->mOperationsPending = ALL_OPERATIONS;
3462 void Controller::SelectEvent( float x, float y, bool selectAll )
3464 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
3466 if( NULL != mImpl->mEventData )
3470 Event event( Event::SELECT_ALL );
3471 mImpl->mEventData->mEventQueue.push_back( event );
3475 Event event( Event::SELECT );
3476 event.p2.mFloat = x;
3477 event.p3.mFloat = y;
3478 mImpl->mEventData->mEventQueue.push_back( event );
3481 mImpl->mEventData->mCheckScrollAmount = true;
3482 mImpl->mEventData->mIsLeftHandleSelected = true;
3483 mImpl->mEventData->mIsRightHandleSelected = true;
3484 mImpl->RequestRelayout();
3488 bool Controller::BackspaceKeyEvent()
3490 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p DALI_KEY_BACKSPACE\n", this );
3492 bool removed = false;
3494 if( NULL == mImpl->mEventData )
3499 // IMF manager is no longer handling key-events
3500 mImpl->ClearPreEditFlag();
3502 if( EventData::SELECTING == mImpl->mEventData->mState )
3504 removed = RemoveSelectedText();
3506 else if( mImpl->mEventData->mPrimaryCursorPosition > 0 )
3508 // Remove the character before the current cursor position
3509 removed = RemoveText( -1,
3511 UPDATE_INPUT_STYLE );
3516 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3517 !mImpl->IsPlaceholderAvailable() )
3519 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3523 ShowPlaceholderText();
3525 mImpl->mEventData->mUpdateCursorPosition = true;
3526 mImpl->mEventData->mScrollAfterDelete = true;
3532 // private : Helpers.
3534 void Controller::ResetText()
3537 mImpl->mModel->mLogicalModel->mText.Clear();
3539 // We have cleared everything including the placeholder-text
3540 mImpl->PlaceholderCleared();
3542 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3543 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3544 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
3546 // Clear any previous text.
3547 mImpl->mTextUpdateInfo.mClearAll = true;
3549 // The natural size needs to be re-calculated.
3550 mImpl->mRecalculateNaturalSize = true;
3552 // Apply modifications to the model
3553 mImpl->mOperationsPending = ALL_OPERATIONS;
3556 void Controller::ShowPlaceholderText()
3558 if( mImpl->IsPlaceholderAvailable() )
3560 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
3562 if( NULL == mImpl->mEventData )
3567 mImpl->mEventData->mIsShowingPlaceholderText = true;
3569 // Disable handles when showing place-holder text
3570 mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
3571 mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
3572 mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
3574 const char* text( NULL );
3577 // TODO - Switch Placeholder text when changing state
3578 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
3579 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
3581 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
3582 size = mImpl->mEventData->mPlaceholderTextActive.size();
3586 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
3587 size = mImpl->mEventData->mPlaceholderTextInactive.size();
3590 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3591 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3593 // Reset model for showing placeholder.
3594 mImpl->mModel->mLogicalModel->mText.Clear();
3595 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
3597 // Convert text into UTF-32
3598 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
3599 utf32Characters.Resize( size );
3601 // This is a bit horrible but std::string returns a (signed) char*
3602 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
3604 // Transform a text array encoded in utf8 into an array encoded in utf32.
3605 // It returns the actual number of characters.
3606 const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
3607 utf32Characters.Resize( characterCount );
3609 // The characters to be added.
3610 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
3612 // Reset the cursor position
3613 mImpl->mEventData->mPrimaryCursorPosition = 0;
3615 // The natural size needs to be re-calculated.
3616 mImpl->mRecalculateNaturalSize = true;
3618 // Apply modifications to the model
3619 mImpl->mOperationsPending = ALL_OPERATIONS;
3621 // Update the rest of the model during size negotiation
3622 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
3626 void Controller::ClearFontData()
3628 if( mImpl->mFontDefaults )
3630 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
3633 // Set flags to update the model.
3634 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3635 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3636 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
3638 mImpl->mTextUpdateInfo.mClearAll = true;
3639 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
3640 mImpl->mRecalculateNaturalSize = true;
3642 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
3647 UPDATE_LAYOUT_SIZE |
3652 void Controller::ClearStyleData()
3654 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
3655 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
3658 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
3660 // Reset the cursor position
3661 if( NULL != mImpl->mEventData )
3663 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
3665 // Update the cursor if it's in editing mode.
3666 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
3668 mImpl->mEventData->mUpdateCursorPosition = true;
3673 void Controller::ResetScrollPosition()
3675 if( NULL != mImpl->mEventData )
3677 // Reset the scroll position.
3678 mImpl->mModel->mScrollPosition = Vector2::ZERO;
3679 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3683 void Controller::SetControlInterface( ControlInterface* controlInterface )
3685 mImpl->mControlInterface = controlInterface;
3688 bool Controller::ShouldClearFocusOnEscape() const
3690 return mImpl->mShouldClearFocusOnEscape;
3693 // private : Private contructors & copy operator.
3695 Controller::Controller()
3698 mImpl = new Controller::Impl( NULL, NULL );
3701 Controller::Controller( ControlInterface* controlInterface )
3703 mImpl = new Controller::Impl( controlInterface, NULL );
3706 Controller::Controller( ControlInterface* controlInterface,
3707 EditableControlInterface* editableControlInterface )
3709 mImpl = new Controller::Impl( controlInterface,
3710 editableControlInterface );
3713 // The copy constructor and operator are left unimplemented.
3715 // protected : Destructor.
3717 Controller::~Controller()
3724 } // namespace Toolkit