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>
28 #include <dali/devel-api/adaptor-framework/key-devel.h>
31 #include <dali-toolkit/public-api/controls/text-controls/placeholder-properties.h>
32 #include <dali-toolkit/internal/text/bidirectional-support.h>
33 #include <dali-toolkit/internal/text/character-set-conversion.h>
34 #include <dali-toolkit/internal/text/layouts/layout-parameters.h>
35 #include <dali-toolkit/internal/text/markup-processor.h>
36 #include <dali-toolkit/internal/text/multi-language-support.h>
37 #include <dali-toolkit/internal/text/text-controller-impl.h>
38 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
39 #include <dali-toolkit/internal/text/text-font-style.h>
44 #if defined(DEBUG_ENABLED)
45 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
48 const int MAX_NUMBER_OF_CHARACTERS = 200000;
50 const float MAX_FLOAT = std::numeric_limits<float>::max();
52 const std::string EMPTY_STRING("");
54 const std::string KEY_C_NAME = "c";
55 const std::string KEY_V_NAME = "v";
56 const std::string KEY_X_NAME = "x";
58 const char * const PLACEHOLDER_TEXT = "text";
59 const char * const PLACEHOLDER_TEXT_FOCUSED = "textFocused";
60 const char * const PLACEHOLDER_COLOR = "color";
61 const char * const PLACEHOLDER_FONT_FAMILY = "fontFamily";
62 const char * const PLACEHOLDER_FONT_STYLE = "fontStyle";
63 const char * const PLACEHOLDER_POINT_SIZE = "pointSize";
64 const char * const PLACEHOLDER_PIXEL_SIZE = "pixelSize";
65 const char * const PLACEHOLDER_ELLIPSIS = "ellipsis";
67 float ConvertToEven( float value )
69 int intValue(static_cast<int>( value ));
70 return static_cast<float>(intValue % 2 == 0) ? intValue : (intValue + 1);
85 * @brief Adds a new font description run for the selected text.
87 * The new font parameters are added after the call to this method.
89 * @param[in] eventData The event data pointer.
90 * @param[in] logicalModel The logical model where to add the new font description run.
91 * @param[out] startOfSelectedText Index to the first selected character.
92 * @param[out] lengthOfSelectedText Number of selected characters.
94 FontDescriptionRun& UpdateSelectionFontStyleRun( EventData* eventData,
95 LogicalModelPtr logicalModel,
96 CharacterIndex& startOfSelectedText,
97 Length& lengthOfSelectedText )
99 const bool handlesCrossed = eventData->mLeftSelectionPosition > eventData->mRightSelectionPosition;
101 // Get start and end position of selection
102 startOfSelectedText = handlesCrossed ? eventData->mRightSelectionPosition : eventData->mLeftSelectionPosition;
103 lengthOfSelectedText = ( handlesCrossed ? eventData->mLeftSelectionPosition : eventData->mRightSelectionPosition ) - startOfSelectedText;
106 const VectorBase::SizeType numberOfRuns = logicalModel->mFontDescriptionRuns.Count();
107 logicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
109 FontDescriptionRun& fontDescriptionRun = *( logicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
111 fontDescriptionRun.characterRun.characterIndex = startOfSelectedText;
112 fontDescriptionRun.characterRun.numberOfCharacters = lengthOfSelectedText;
114 // Recalculate the selection highlight as the metrics may have changed.
115 eventData->mUpdateLeftSelectionPosition = true;
116 eventData->mUpdateRightSelectionPosition = true;
117 eventData->mUpdateHighlightBox = true;
119 return fontDescriptionRun;
122 // public : Constructor.
124 ControllerPtr Controller::New()
126 return ControllerPtr( new Controller() );
129 ControllerPtr Controller::New( ControlInterface* controlInterface )
131 return ControllerPtr( new Controller( controlInterface ) );
134 ControllerPtr Controller::New( ControlInterface* controlInterface,
135 EditableControlInterface* editableControlInterface )
137 return ControllerPtr( new Controller( controlInterface,
138 editableControlInterface ) );
141 // public : Configure the text controller.
143 void Controller::EnableTextInput( DecoratorPtr decorator )
147 delete mImpl->mEventData;
148 mImpl->mEventData = NULL;
150 // Nothing else to do.
154 if( NULL == mImpl->mEventData )
156 mImpl->mEventData = new EventData( decorator );
160 void Controller::SetGlyphType( TextAbstraction::GlyphType glyphType )
162 // Metrics for bitmap & vector based glyphs are different
163 mImpl->mMetrics->SetGlyphType( glyphType );
165 // Clear the font-specific data
168 mImpl->RequestRelayout();
171 void Controller::SetMarkupProcessorEnabled( bool enable )
173 mImpl->mMarkupProcessorEnabled = enable;
176 //If Text was already set, call the SetText again for enabling markup
183 bool Controller::IsMarkupProcessorEnabled() const
185 return mImpl->mMarkupProcessorEnabled;
188 void Controller::SetAutoScrollEnabled( bool enable )
190 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 );
192 if( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX )
196 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled for SINGLE_LINE_BOX\n" );
197 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
207 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled Disabling autoscroll\n");
208 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
215 mImpl->mIsAutoScrollEnabled = enable;
216 mImpl->RequestRelayout();
220 DALI_LOG_WARNING( "Attempted AutoScrolling on a non SINGLE_LINE_BOX, request ignored\n" );
221 mImpl->mIsAutoScrollEnabled = false;
225 bool Controller::IsAutoScrollEnabled() const
227 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::IsAutoScrollEnabled[%s]\n", mImpl->mIsAutoScrollEnabled?"true":"false" );
229 return mImpl->mIsAutoScrollEnabled;
232 CharacterDirection Controller::GetAutoScrollDirection() const
234 return mImpl->mIsTextDirectionRTL;
237 float Controller::GetAutoScrollLineAlignment() const
241 if( mImpl->mModel->mVisualModel &&
242 ( 0u != mImpl->mModel->mVisualModel->mLines.Count() ) )
244 offset = ( *mImpl->mModel->mVisualModel->mLines.Begin() ).alignmentOffset;
250 void Controller::SetHorizontalScrollEnabled( bool enable )
252 if( ( NULL != mImpl->mEventData ) &&
253 mImpl->mEventData->mDecorator )
255 mImpl->mEventData->mDecorator->SetHorizontalScrollEnabled( enable );
258 bool Controller::IsHorizontalScrollEnabled() const
260 if( ( NULL != mImpl->mEventData ) &&
261 mImpl->mEventData->mDecorator )
263 return mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
269 void Controller::SetVerticalScrollEnabled( bool enable )
271 if( ( NULL != mImpl->mEventData ) &&
272 mImpl->mEventData->mDecorator )
274 if( mImpl->mEventData->mDecorator )
276 mImpl->mEventData->mDecorator->SetVerticalScrollEnabled( enable );
281 bool Controller::IsVerticalScrollEnabled() const
283 if( ( NULL != mImpl->mEventData ) &&
284 mImpl->mEventData->mDecorator )
286 return mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
292 void Controller::SetSmoothHandlePanEnabled( bool enable )
294 if( ( NULL != mImpl->mEventData ) &&
295 mImpl->mEventData->mDecorator )
297 mImpl->mEventData->mDecorator->SetSmoothHandlePanEnabled( enable );
301 bool Controller::IsSmoothHandlePanEnabled() const
303 if( ( NULL != mImpl->mEventData ) &&
304 mImpl->mEventData->mDecorator )
306 return mImpl->mEventData->mDecorator->IsSmoothHandlePanEnabled();
312 void Controller::SetMaximumNumberOfCharacters( Length maxCharacters )
314 mImpl->mMaximumNumberOfCharacters = maxCharacters;
317 int Controller::GetMaximumNumberOfCharacters()
319 return mImpl->mMaximumNumberOfCharacters;
322 void Controller::SetEnableCursorBlink( bool enable )
324 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "TextInput disabled" );
326 if( NULL != mImpl->mEventData )
328 mImpl->mEventData->mCursorBlinkEnabled = enable;
331 mImpl->mEventData->mDecorator )
333 mImpl->mEventData->mDecorator->StopCursorBlink();
338 bool Controller::GetEnableCursorBlink() const
340 if( NULL != mImpl->mEventData )
342 return mImpl->mEventData->mCursorBlinkEnabled;
348 void Controller::SetMultiLineEnabled( bool enable )
350 const Layout::Engine::Type layout = enable ? Layout::Engine::MULTI_LINE_BOX : Layout::Engine::SINGLE_LINE_BOX;
352 if( layout != mImpl->mLayoutEngine.GetLayout() )
354 // Set the layout type.
355 mImpl->mLayoutEngine.SetLayout( layout );
357 // Set the flags to redo the layout operations
358 const OperationsMask layoutOperations = static_cast<OperationsMask>( LAYOUT |
363 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
364 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | layoutOperations );
366 mImpl->RequestRelayout();
370 bool Controller::IsMultiLineEnabled() const
372 return Layout::Engine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
375 void Controller::SetHorizontalAlignment( Text::HorizontalAlignment::Type alignment )
377 if( alignment != mImpl->mModel->mHorizontalAlignment )
379 // Set the alignment.
380 mImpl->mModel->mHorizontalAlignment = alignment;
382 // Set the flag to redo the alignment operation.
383 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
385 mImpl->RequestRelayout();
389 Text::HorizontalAlignment::Type Controller::GetHorizontalAlignment() const
391 return mImpl->mModel->mHorizontalAlignment;
394 void Controller::SetVerticalAlignment( VerticalAlignment::Type alignment )
396 if( alignment != mImpl->mModel->mVerticalAlignment )
398 // Set the alignment.
399 mImpl->mModel->mVerticalAlignment = alignment;
401 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
403 mImpl->RequestRelayout();
407 VerticalAlignment::Type Controller::GetVerticalAlignment() const
409 return mImpl->mModel->mVerticalAlignment;
412 void Controller::SetLineWrapMode( Text::LineWrap::Mode lineWrapMode )
414 if( lineWrapMode != mImpl->mModel->mLineWrapMode )
416 // Set the text wrap mode.
417 mImpl->mModel->mLineWrapMode = lineWrapMode;
420 // Update Text layout for applying wrap mode
421 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
426 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
427 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
428 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
431 mImpl->RequestRelayout();
435 Text::LineWrap::Mode Controller::GetLineWrapMode() const
437 return mImpl->mModel->mLineWrapMode;
440 void Controller::SetTextElideEnabled( bool enabled )
442 mImpl->mModel->mElideEnabled = enabled;
445 bool Controller::IsTextElideEnabled() const
447 return mImpl->mModel->mElideEnabled;
450 void Controller::SetPlaceholderTextElideEnabled( bool enabled )
452 mImpl->mEventData->mIsPlaceholderElideEnabled = enabled;
453 mImpl->mEventData->mPlaceholderEllipsisFlag = true;
455 // Update placeholder if there is no text
456 if( mImpl->IsShowingPlaceholderText() ||
457 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
459 ShowPlaceholderText();
463 bool Controller::IsPlaceholderTextElideEnabled() const
465 return mImpl->mEventData->mIsPlaceholderElideEnabled;
468 void Controller::SetSelectionEnabled( bool enabled )
470 mImpl->mEventData->mSelectionEnabled = enabled;
473 bool Controller::IsSelectionEnabled() const
475 return mImpl->mEventData->mSelectionEnabled;
478 void Controller::SetShiftSelectionEnabled( bool enabled )
480 mImpl->mEventData->mShiftSelectionFlag = enabled;
483 bool Controller::IsShiftSelectionEnabled() const
485 return mImpl->mEventData->mShiftSelectionFlag;
490 void Controller::SetText( const std::string& text )
492 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" );
494 // Reset keyboard as text changed
495 mImpl->ResetImfManager();
497 // Remove the previously set text and style.
503 CharacterIndex lastCursorIndex = 0u;
505 if( NULL != mImpl->mEventData )
507 // If popup shown then hide it by switching to Editing state
508 if( ( EventData::SELECTING == mImpl->mEventData->mState ) ||
509 ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
510 ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) ||
511 ( EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState ) )
513 mImpl->ChangeState( EventData::EDITING );
519 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mTextColor );
521 MarkupProcessData markupProcessData( mImpl->mModel->mLogicalModel->mColorRuns,
522 mImpl->mModel->mLogicalModel->mFontDescriptionRuns );
524 Length textSize = 0u;
525 const uint8_t* utf8 = NULL;
526 if( mImpl->mMarkupProcessorEnabled )
528 ProcessMarkupString( text, markupProcessData );
529 textSize = markupProcessData.markupProcessedText.size();
531 // This is a bit horrible but std::string returns a (signed) char*
532 utf8 = reinterpret_cast<const uint8_t*>( markupProcessData.markupProcessedText.c_str() );
536 textSize = text.size();
538 // This is a bit horrible but std::string returns a (signed) char*
539 utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
542 // Convert text into UTF-32
543 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
544 utf32Characters.Resize( textSize );
546 // Transform a text array encoded in utf8 into an array encoded in utf32.
547 // It returns the actual number of characters.
548 Length characterCount = Utf8ToUtf32( utf8, textSize, utf32Characters.Begin() );
549 utf32Characters.Resize( characterCount );
551 DALI_ASSERT_DEBUG( textSize >= characterCount && "Invalid UTF32 conversion length" );
552 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", this, textSize, mImpl->mModel->mLogicalModel->mText.Count() );
554 // The characters to be added.
555 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
557 // To reset the cursor position
558 lastCursorIndex = characterCount;
560 // Update the rest of the model during size negotiation
561 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
563 // The natural size needs to be re-calculated.
564 mImpl->mRecalculateNaturalSize = true;
566 // The text direction needs to be updated.
567 mImpl->mUpdateTextDirection = true;
569 // Apply modifications to the model
570 mImpl->mOperationsPending = ALL_OPERATIONS;
574 ShowPlaceholderText();
577 // Resets the cursor position.
578 ResetCursorPosition( lastCursorIndex );
580 // Scrolls the text to make the cursor visible.
581 ResetScrollPosition();
583 mImpl->RequestRelayout();
585 if( NULL != mImpl->mEventData )
587 // Cancel previously queued events
588 mImpl->mEventData->mEventQueue.clear();
591 // Do this last since it provides callbacks into application code.
592 if( NULL != mImpl->mEditableControlInterface )
594 mImpl->mEditableControlInterface->TextChanged();
598 void Controller::GetText( std::string& text ) const
600 if( !mImpl->IsShowingPlaceholderText() )
602 // Retrieves the text string.
603 mImpl->GetText( 0u, text );
607 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this );
611 void Controller::SetPlaceholderText( PlaceholderType type, const std::string& text )
613 if( NULL != mImpl->mEventData )
615 if( PLACEHOLDER_TYPE_INACTIVE == type )
617 mImpl->mEventData->mPlaceholderTextInactive = text;
621 mImpl->mEventData->mPlaceholderTextActive = text;
624 // Update placeholder if there is no text
625 if( mImpl->IsShowingPlaceholderText() ||
626 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
628 ShowPlaceholderText();
633 void Controller::GetPlaceholderText( PlaceholderType type, std::string& text ) const
635 if( NULL != mImpl->mEventData )
637 if( PLACEHOLDER_TYPE_INACTIVE == type )
639 text = mImpl->mEventData->mPlaceholderTextInactive;
643 text = mImpl->mEventData->mPlaceholderTextActive;
648 void Controller::UpdateAfterFontChange( const std::string& newDefaultFont )
650 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
652 if( !mImpl->mFontDefaults->familyDefined ) // If user defined font then should not update when system font changes
654 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
655 mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
659 mImpl->RequestRelayout();
663 // public : Default style & Input style
665 void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
667 if( NULL == mImpl->mFontDefaults )
669 mImpl->mFontDefaults = new FontDefaults();
672 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
673 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
674 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
676 // Clear the font-specific data
679 mImpl->RequestRelayout();
682 const std::string& Controller::GetDefaultFontFamily() const
684 if( NULL != mImpl->mFontDefaults )
686 return mImpl->mFontDefaults->mFontDescription.family;
692 void Controller::SetPlaceholderFontFamily( const std::string& placeholderTextFontFamily )
694 if( NULL != mImpl->mEventData )
696 if( NULL == mImpl->mEventData->mPlaceholderFont )
698 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
701 mImpl->mEventData->mPlaceholderFont->mFontDescription.family = placeholderTextFontFamily;
702 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetPlaceholderFontFamily %s\n", placeholderTextFontFamily.c_str());
703 mImpl->mEventData->mPlaceholderFont->familyDefined = !placeholderTextFontFamily.empty();
705 mImpl->RequestRelayout();
709 const std::string& Controller::GetPlaceholderFontFamily() const
711 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
713 return mImpl->mEventData->mPlaceholderFont->mFontDescription.family;
719 void Controller::SetDefaultFontWeight( FontWeight weight )
721 if( NULL == mImpl->mFontDefaults )
723 mImpl->mFontDefaults = new FontDefaults();
726 mImpl->mFontDefaults->mFontDescription.weight = weight;
727 mImpl->mFontDefaults->weightDefined = true;
729 // Clear the font-specific data
732 mImpl->RequestRelayout();
735 bool Controller::IsDefaultFontWeightDefined() const
737 if( NULL != mImpl->mFontDefaults )
739 return mImpl->mFontDefaults->weightDefined;
745 FontWeight Controller::GetDefaultFontWeight() const
747 if( NULL != mImpl->mFontDefaults )
749 return mImpl->mFontDefaults->mFontDescription.weight;
752 return TextAbstraction::FontWeight::NORMAL;
755 void Controller::SetPlaceholderTextFontWeight( FontWeight weight )
757 if( NULL != mImpl->mEventData )
759 if( NULL == mImpl->mEventData->mPlaceholderFont )
761 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
764 mImpl->mEventData->mPlaceholderFont->mFontDescription.weight = weight;
765 mImpl->mEventData->mPlaceholderFont->weightDefined = true;
767 mImpl->RequestRelayout();
771 bool Controller::IsPlaceholderTextFontWeightDefined() const
773 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
775 return mImpl->mEventData->mPlaceholderFont->weightDefined;
780 FontWeight Controller::GetPlaceholderTextFontWeight() const
782 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
784 return mImpl->mEventData->mPlaceholderFont->mFontDescription.weight;
787 return TextAbstraction::FontWeight::NORMAL;
790 void Controller::SetDefaultFontWidth( FontWidth width )
792 if( NULL == mImpl->mFontDefaults )
794 mImpl->mFontDefaults = new FontDefaults();
797 mImpl->mFontDefaults->mFontDescription.width = width;
798 mImpl->mFontDefaults->widthDefined = true;
800 // Clear the font-specific data
803 mImpl->RequestRelayout();
806 bool Controller::IsDefaultFontWidthDefined() const
808 if( NULL != mImpl->mFontDefaults )
810 return mImpl->mFontDefaults->widthDefined;
816 FontWidth Controller::GetDefaultFontWidth() const
818 if( NULL != mImpl->mFontDefaults )
820 return mImpl->mFontDefaults->mFontDescription.width;
823 return TextAbstraction::FontWidth::NORMAL;
826 void Controller::SetPlaceholderTextFontWidth( FontWidth width )
828 if( NULL != mImpl->mEventData )
830 if( NULL == mImpl->mEventData->mPlaceholderFont )
832 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
835 mImpl->mEventData->mPlaceholderFont->mFontDescription.width = width;
836 mImpl->mEventData->mPlaceholderFont->widthDefined = true;
838 mImpl->RequestRelayout();
842 bool Controller::IsPlaceholderTextFontWidthDefined() const
844 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
846 return mImpl->mEventData->mPlaceholderFont->widthDefined;
851 FontWidth Controller::GetPlaceholderTextFontWidth() const
853 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
855 return mImpl->mEventData->mPlaceholderFont->mFontDescription.width;
858 return TextAbstraction::FontWidth::NORMAL;
861 void Controller::SetDefaultFontSlant( FontSlant slant )
863 if( NULL == mImpl->mFontDefaults )
865 mImpl->mFontDefaults = new FontDefaults();
868 mImpl->mFontDefaults->mFontDescription.slant = slant;
869 mImpl->mFontDefaults->slantDefined = true;
871 // Clear the font-specific data
874 mImpl->RequestRelayout();
877 bool Controller::IsDefaultFontSlantDefined() const
879 if( NULL != mImpl->mFontDefaults )
881 return mImpl->mFontDefaults->slantDefined;
886 FontSlant Controller::GetDefaultFontSlant() const
888 if( NULL != mImpl->mFontDefaults )
890 return mImpl->mFontDefaults->mFontDescription.slant;
893 return TextAbstraction::FontSlant::NORMAL;
896 void Controller::SetPlaceholderTextFontSlant( FontSlant slant )
898 if( NULL != mImpl->mEventData )
900 if( NULL == mImpl->mEventData->mPlaceholderFont )
902 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
905 mImpl->mEventData->mPlaceholderFont->mFontDescription.slant = slant;
906 mImpl->mEventData->mPlaceholderFont->slantDefined = true;
908 mImpl->RequestRelayout();
912 bool Controller::IsPlaceholderTextFontSlantDefined() const
914 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
916 return mImpl->mEventData->mPlaceholderFont->slantDefined;
921 FontSlant Controller::GetPlaceholderTextFontSlant() const
923 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
925 return mImpl->mEventData->mPlaceholderFont->mFontDescription.slant;
928 return TextAbstraction::FontSlant::NORMAL;
931 void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
933 if( NULL == mImpl->mFontDefaults )
935 mImpl->mFontDefaults = new FontDefaults();
942 mImpl->mFontDefaults->mDefaultPointSize = fontSize;
943 mImpl->mFontDefaults->sizeDefined = true;
948 // Point size = Pixel size * 72.f / DPI
949 unsigned int horizontalDpi = 0u;
950 unsigned int verticalDpi = 0u;
951 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
952 fontClient.GetDpi( horizontalDpi, verticalDpi );
954 mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
955 mImpl->mFontDefaults->sizeDefined = true;
960 // Clear the font-specific data
963 mImpl->RequestRelayout();
966 float Controller::GetDefaultFontSize( FontSizeType type ) const
969 if( NULL != mImpl->mFontDefaults )
975 value = mImpl->mFontDefaults->mDefaultPointSize;
980 // Pixel size = Point size * DPI / 72.f
981 unsigned int horizontalDpi = 0u;
982 unsigned int verticalDpi = 0u;
983 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
984 fontClient.GetDpi( horizontalDpi, verticalDpi );
986 value = mImpl->mFontDefaults->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
996 void Controller::SetPlaceholderTextFontSize( float fontSize, FontSizeType type )
998 if( NULL != mImpl->mEventData )
1000 if( NULL == mImpl->mEventData->mPlaceholderFont )
1002 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
1009 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = fontSize;
1010 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1011 mImpl->mEventData->mIsPlaceholderPixelSize = false; // Font size flag
1016 // Point size = Pixel size * 72.f / DPI
1017 unsigned int horizontalDpi = 0u;
1018 unsigned int verticalDpi = 0u;
1019 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1020 fontClient.GetDpi( horizontalDpi, verticalDpi );
1022 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
1023 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1024 mImpl->mEventData->mIsPlaceholderPixelSize = true; // Font size flag
1029 mImpl->RequestRelayout();
1033 float Controller::GetPlaceholderTextFontSize( FontSizeType type ) const
1036 if( NULL != mImpl->mEventData )
1042 if( NULL != mImpl->mEventData->mPlaceholderFont )
1044 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize;
1048 // If the placeholder text font size is not set, then return the default font size.
1049 value = GetDefaultFontSize( POINT_SIZE );
1055 if( NULL != mImpl->mEventData->mPlaceholderFont )
1057 // Pixel size = Point size * DPI / 72.f
1058 unsigned int horizontalDpi = 0u;
1059 unsigned int verticalDpi = 0u;
1060 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1061 fontClient.GetDpi( horizontalDpi, verticalDpi );
1063 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1067 // If the placeholder text font size is not set, then return the default font size.
1068 value = GetDefaultFontSize( PIXEL_SIZE );
1079 void Controller::SetDefaultColor( const Vector4& color )
1081 mImpl->mTextColor = color;
1083 if( !mImpl->IsShowingPlaceholderText() )
1085 mImpl->mModel->mVisualModel->SetTextColor( color );
1087 mImpl->RequestRelayout();
1091 const Vector4& Controller::GetDefaultColor() const
1093 return mImpl->mTextColor;
1096 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
1098 if( NULL != mImpl->mEventData )
1100 mImpl->mEventData->mPlaceholderTextColor = textColor;
1103 if( mImpl->IsShowingPlaceholderText() )
1105 mImpl->mModel->mVisualModel->SetTextColor( textColor );
1106 mImpl->RequestRelayout();
1110 const Vector4& Controller::GetPlaceholderTextColor() const
1112 if( NULL != mImpl->mEventData )
1114 return mImpl->mEventData->mPlaceholderTextColor;
1117 return Color::BLACK;
1120 void Controller::SetShadowOffset( const Vector2& shadowOffset )
1122 mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
1124 mImpl->RequestRelayout();
1127 const Vector2& Controller::GetShadowOffset() const
1129 return mImpl->mModel->mVisualModel->GetShadowOffset();
1132 void Controller::SetShadowColor( const Vector4& shadowColor )
1134 mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
1136 mImpl->RequestRelayout();
1139 const Vector4& Controller::GetShadowColor() const
1141 return mImpl->mModel->mVisualModel->GetShadowColor();
1144 void Controller::SetShadowBlurRadius( const float& shadowBlurRadius )
1146 if ( fabsf( GetShadowBlurRadius() - shadowBlurRadius ) > Math::MACHINE_EPSILON_1 )
1148 mImpl->mModel->mVisualModel->SetShadowBlurRadius( shadowBlurRadius );
1150 mImpl->RequestRelayout();
1154 const float& Controller::GetShadowBlurRadius() const
1156 return mImpl->mModel->mVisualModel->GetShadowBlurRadius();
1159 void Controller::SetUnderlineColor( const Vector4& color )
1161 mImpl->mModel->mVisualModel->SetUnderlineColor( color );
1163 mImpl->RequestRelayout();
1166 const Vector4& Controller::GetUnderlineColor() const
1168 return mImpl->mModel->mVisualModel->GetUnderlineColor();
1171 void Controller::SetUnderlineEnabled( bool enabled )
1173 mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
1175 mImpl->RequestRelayout();
1178 bool Controller::IsUnderlineEnabled() const
1180 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
1183 void Controller::SetUnderlineHeight( float height )
1185 mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
1187 mImpl->RequestRelayout();
1190 float Controller::GetUnderlineHeight() const
1192 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
1195 void Controller::SetOutlineColor( const Vector4& color )
1197 mImpl->mModel->mVisualModel->SetOutlineColor( color );
1199 mImpl->RequestRelayout();
1202 const Vector4& Controller::GetOutlineColor() const
1204 return mImpl->mModel->mVisualModel->GetOutlineColor();
1207 void Controller::SetOutlineWidth( unsigned int width )
1209 mImpl->mModel->mVisualModel->SetOutlineWidth( width );
1211 mImpl->RequestRelayout();
1214 unsigned int Controller::GetOutlineWidth() const
1216 return mImpl->mModel->mVisualModel->GetOutlineWidth();
1219 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
1221 if( NULL == mImpl->mEmbossDefaults )
1223 mImpl->mEmbossDefaults = new EmbossDefaults();
1226 mImpl->mEmbossDefaults->properties = embossProperties;
1229 const std::string& Controller::GetDefaultEmbossProperties() const
1231 if( NULL != mImpl->mEmbossDefaults )
1233 return mImpl->mEmbossDefaults->properties;
1236 return EMPTY_STRING;
1239 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
1241 if( NULL == mImpl->mOutlineDefaults )
1243 mImpl->mOutlineDefaults = new OutlineDefaults();
1246 mImpl->mOutlineDefaults->properties = outlineProperties;
1249 const std::string& Controller::GetDefaultOutlineProperties() const
1251 if( NULL != mImpl->mOutlineDefaults )
1253 return mImpl->mOutlineDefaults->properties;
1256 return EMPTY_STRING;
1259 bool Controller::SetDefaultLineSpacing( float lineSpacing )
1261 if( std::abs(lineSpacing - mImpl->mLayoutEngine.GetDefaultLineSpacing()) > Math::MACHINE_EPSILON_1000 )
1263 mImpl->mLayoutEngine.SetDefaultLineSpacing(lineSpacing);
1264 mImpl->mRecalculateNaturalSize = true;
1270 float Controller::GetDefaultLineSpacing() const
1272 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
1275 void Controller::SetInputColor( const Vector4& color )
1277 if( NULL != mImpl->mEventData )
1279 mImpl->mEventData->mInputStyle.textColor = color;
1280 mImpl->mEventData->mInputStyle.isDefaultColor = false;
1282 if( EventData::SELECTING == mImpl->mEventData->mState )
1284 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
1286 // Get start and end position of selection
1287 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
1288 const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
1290 // Add the color run.
1291 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1292 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
1294 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
1295 colorRun.color = color;
1296 colorRun.characterRun.characterIndex = startOfSelectedText;
1297 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1299 // Request to relayout.
1300 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1301 mImpl->RequestRelayout();
1303 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1304 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1305 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1310 const Vector4& Controller::GetInputColor() const
1312 if( NULL != mImpl->mEventData )
1314 return mImpl->mEventData->mInputStyle.textColor;
1317 // Return the default text's color if there is no EventData.
1318 return mImpl->mTextColor;
1322 void Controller::SetInputFontFamily( const std::string& fontFamily )
1324 if( NULL != mImpl->mEventData )
1326 mImpl->mEventData->mInputStyle.familyName = fontFamily;
1327 mImpl->mEventData->mInputStyle.isFamilyDefined = true;
1329 if( EventData::SELECTING == mImpl->mEventData->mState )
1331 CharacterIndex startOfSelectedText = 0u;
1332 Length lengthOfSelectedText = 0u;
1333 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1334 mImpl->mModel->mLogicalModel,
1335 startOfSelectedText,
1336 lengthOfSelectedText );
1338 fontDescriptionRun.familyLength = fontFamily.size();
1339 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
1340 memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength );
1341 fontDescriptionRun.familyDefined = true;
1343 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
1345 // Request to relayout.
1346 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1351 UPDATE_LAYOUT_SIZE |
1354 mImpl->mRecalculateNaturalSize = true;
1355 mImpl->RequestRelayout();
1357 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1358 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1359 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1361 // As the font changes, recalculate the handle positions is needed.
1362 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1363 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1364 mImpl->mEventData->mUpdateHighlightBox = true;
1365 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1370 const std::string& Controller::GetInputFontFamily() const
1372 if( NULL != mImpl->mEventData )
1374 return mImpl->mEventData->mInputStyle.familyName;
1377 // Return the default font's family if there is no EventData.
1378 return GetDefaultFontFamily();
1381 void Controller::SetInputFontWeight( FontWeight weight )
1383 if( NULL != mImpl->mEventData )
1385 mImpl->mEventData->mInputStyle.weight = weight;
1386 mImpl->mEventData->mInputStyle.isWeightDefined = true;
1388 if( EventData::SELECTING == mImpl->mEventData->mState )
1390 CharacterIndex startOfSelectedText = 0u;
1391 Length lengthOfSelectedText = 0u;
1392 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1393 mImpl->mModel->mLogicalModel,
1394 startOfSelectedText,
1395 lengthOfSelectedText );
1397 fontDescriptionRun.weight = weight;
1398 fontDescriptionRun.weightDefined = true;
1400 // Request to relayout.
1401 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1406 UPDATE_LAYOUT_SIZE |
1409 mImpl->mRecalculateNaturalSize = true;
1410 mImpl->RequestRelayout();
1412 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1413 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1414 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1416 // As the font might change, recalculate the handle positions is needed.
1417 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1418 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1419 mImpl->mEventData->mUpdateHighlightBox = true;
1420 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1425 bool Controller::IsInputFontWeightDefined() const
1427 bool defined = false;
1429 if( NULL != mImpl->mEventData )
1431 defined = mImpl->mEventData->mInputStyle.isWeightDefined;
1437 FontWeight Controller::GetInputFontWeight() const
1439 if( NULL != mImpl->mEventData )
1441 return mImpl->mEventData->mInputStyle.weight;
1444 return GetDefaultFontWeight();
1447 void Controller::SetInputFontWidth( FontWidth width )
1449 if( NULL != mImpl->mEventData )
1451 mImpl->mEventData->mInputStyle.width = width;
1452 mImpl->mEventData->mInputStyle.isWidthDefined = true;
1454 if( EventData::SELECTING == mImpl->mEventData->mState )
1456 CharacterIndex startOfSelectedText = 0u;
1457 Length lengthOfSelectedText = 0u;
1458 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1459 mImpl->mModel->mLogicalModel,
1460 startOfSelectedText,
1461 lengthOfSelectedText );
1463 fontDescriptionRun.width = width;
1464 fontDescriptionRun.widthDefined = true;
1466 // Request to relayout.
1467 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1472 UPDATE_LAYOUT_SIZE |
1475 mImpl->mRecalculateNaturalSize = true;
1476 mImpl->RequestRelayout();
1478 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1479 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1480 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1482 // As the font might change, recalculate the handle positions is needed.
1483 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1484 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1485 mImpl->mEventData->mUpdateHighlightBox = true;
1486 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1491 bool Controller::IsInputFontWidthDefined() const
1493 bool defined = false;
1495 if( NULL != mImpl->mEventData )
1497 defined = mImpl->mEventData->mInputStyle.isWidthDefined;
1503 FontWidth Controller::GetInputFontWidth() const
1505 if( NULL != mImpl->mEventData )
1507 return mImpl->mEventData->mInputStyle.width;
1510 return GetDefaultFontWidth();
1513 void Controller::SetInputFontSlant( FontSlant slant )
1515 if( NULL != mImpl->mEventData )
1517 mImpl->mEventData->mInputStyle.slant = slant;
1518 mImpl->mEventData->mInputStyle.isSlantDefined = true;
1520 if( EventData::SELECTING == mImpl->mEventData->mState )
1522 CharacterIndex startOfSelectedText = 0u;
1523 Length lengthOfSelectedText = 0u;
1524 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1525 mImpl->mModel->mLogicalModel,
1526 startOfSelectedText,
1527 lengthOfSelectedText );
1529 fontDescriptionRun.slant = slant;
1530 fontDescriptionRun.slantDefined = true;
1532 // Request to relayout.
1533 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1538 UPDATE_LAYOUT_SIZE |
1541 mImpl->mRecalculateNaturalSize = true;
1542 mImpl->RequestRelayout();
1544 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1545 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1546 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1548 // As the font might change, recalculate the handle positions is needed.
1549 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1550 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1551 mImpl->mEventData->mUpdateHighlightBox = true;
1552 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1557 bool Controller::IsInputFontSlantDefined() const
1559 bool defined = false;
1561 if( NULL != mImpl->mEventData )
1563 defined = mImpl->mEventData->mInputStyle.isSlantDefined;
1569 FontSlant Controller::GetInputFontSlant() const
1571 if( NULL != mImpl->mEventData )
1573 return mImpl->mEventData->mInputStyle.slant;
1576 return GetDefaultFontSlant();
1579 void Controller::SetInputFontPointSize( float size )
1581 if( NULL != mImpl->mEventData )
1583 mImpl->mEventData->mInputStyle.size = size;
1584 mImpl->mEventData->mInputStyle.isSizeDefined = true;
1586 if( EventData::SELECTING == mImpl->mEventData->mState )
1588 CharacterIndex startOfSelectedText = 0u;
1589 Length lengthOfSelectedText = 0u;
1590 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1591 mImpl->mModel->mLogicalModel,
1592 startOfSelectedText,
1593 lengthOfSelectedText );
1595 fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
1596 fontDescriptionRun.sizeDefined = true;
1598 // Request to relayout.
1599 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1604 UPDATE_LAYOUT_SIZE |
1607 mImpl->mRecalculateNaturalSize = true;
1608 mImpl->RequestRelayout();
1610 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1611 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1612 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1614 // As the font might change, recalculate the handle positions is needed.
1615 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1616 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1617 mImpl->mEventData->mUpdateHighlightBox = true;
1618 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1623 float Controller::GetInputFontPointSize() const
1625 if( NULL != mImpl->mEventData )
1627 return mImpl->mEventData->mInputStyle.size;
1630 // Return the default font's point size if there is no EventData.
1631 return GetDefaultFontSize( Text::Controller::POINT_SIZE );
1634 void Controller::SetInputLineSpacing( float lineSpacing )
1636 if( NULL != mImpl->mEventData )
1638 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1639 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1643 float Controller::GetInputLineSpacing() const
1645 if( NULL != mImpl->mEventData )
1647 return mImpl->mEventData->mInputStyle.lineSpacing;
1653 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1655 if( NULL != mImpl->mEventData )
1657 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1661 const std::string& Controller::GetInputShadowProperties() const
1663 if( NULL != mImpl->mEventData )
1665 return mImpl->mEventData->mInputStyle.shadowProperties;
1668 return EMPTY_STRING;
1671 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1673 if( NULL != mImpl->mEventData )
1675 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1679 const std::string& Controller::GetInputUnderlineProperties() const
1681 if( NULL != mImpl->mEventData )
1683 return mImpl->mEventData->mInputStyle.underlineProperties;
1686 return EMPTY_STRING;
1689 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
1691 if( NULL != mImpl->mEventData )
1693 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1697 const std::string& Controller::GetInputEmbossProperties() const
1699 if( NULL != mImpl->mEventData )
1701 return mImpl->mEventData->mInputStyle.embossProperties;
1704 return GetDefaultEmbossProperties();
1707 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
1709 if( NULL != mImpl->mEventData )
1711 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1715 const std::string& Controller::GetInputOutlineProperties() const
1717 if( NULL != mImpl->mEventData )
1719 return mImpl->mEventData->mInputStyle.outlineProperties;
1722 return GetDefaultOutlineProperties();
1725 void Controller::SetInputModePassword( bool passwordInput )
1727 if( NULL != mImpl->mEventData )
1729 mImpl->mEventData->mPasswordInput = passwordInput;
1733 bool Controller::IsInputModePassword()
1735 if( NULL != mImpl->mEventData )
1737 return mImpl->mEventData->mPasswordInput;
1742 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
1744 if( NULL != mImpl->mEventData )
1746 mImpl->mEventData->mDoubleTapAction = action;
1750 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1752 NoTextTap::Action action = NoTextTap::NO_ACTION;
1754 if( NULL != mImpl->mEventData )
1756 action = mImpl->mEventData->mDoubleTapAction;
1762 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
1764 if( NULL != mImpl->mEventData )
1766 mImpl->mEventData->mLongPressAction = action;
1770 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1772 NoTextTap::Action action = NoTextTap::NO_ACTION;
1774 if( NULL != mImpl->mEventData )
1776 action = mImpl->mEventData->mLongPressAction;
1782 bool Controller::IsUnderlineSetByString()
1784 return mImpl->mUnderlineSetByString;
1787 void Controller::UnderlineSetByString( bool setByString )
1789 mImpl->mUnderlineSetByString = setByString;
1792 bool Controller::IsShadowSetByString()
1794 return mImpl->mShadowSetByString;
1797 void Controller::ShadowSetByString( bool setByString )
1799 mImpl->mShadowSetByString = setByString;
1802 bool Controller::IsOutlineSetByString()
1804 return mImpl->mOutlineSetByString;
1807 void Controller::OutlineSetByString( bool setByString )
1809 mImpl->mOutlineSetByString = setByString;
1812 bool Controller::IsFontStyleSetByString()
1814 return mImpl->mFontStyleSetByString;
1817 void Controller::FontStyleSetByString( bool setByString )
1819 mImpl->mFontStyleSetByString = setByString;
1822 // public : Queries & retrieves.
1824 Layout::Engine& Controller::GetLayoutEngine()
1826 return mImpl->mLayoutEngine;
1829 View& Controller::GetView()
1831 return mImpl->mView;
1834 Vector3 Controller::GetNaturalSize()
1836 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
1837 Vector3 naturalSize;
1839 // Make sure the model is up-to-date before layouting
1840 ProcessModifyEvents();
1842 if( mImpl->mRecalculateNaturalSize )
1844 // Operations that can be done only once until the text changes.
1845 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1852 GET_GLYPH_METRICS );
1854 // Set the update info to relayout the whole text.
1855 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1856 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1858 // Make sure the model is up-to-date before layouting
1859 mImpl->UpdateModel( onlyOnceOperations );
1861 // Layout the text for the new width.
1862 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT | REORDER );
1864 // Store the actual control's size to restore later.
1865 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
1867 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
1868 static_cast<OperationsMask>( onlyOnceOperations |
1870 naturalSize.GetVectorXY() );
1872 // Do not do again the only once operations.
1873 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1875 // Do the size related operations again.
1876 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1879 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1881 // Stores the natural size to avoid recalculate it again
1882 // unless the text/style changes.
1883 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
1885 mImpl->mRecalculateNaturalSize = false;
1887 // Clear the update info. This info will be set the next time the text is updated.
1888 mImpl->mTextUpdateInfo.Clear();
1889 mImpl->mTextUpdateInfo.mClearAll = true;
1891 // Restore the actual control's size.
1892 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
1894 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1898 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
1900 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1903 naturalSize.x = ConvertToEven( naturalSize.x );
1904 naturalSize.y = ConvertToEven( naturalSize.y );
1909 float Controller::GetHeightForWidth( float width )
1911 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
1912 // Make sure the model is up-to-date before layouting
1913 ProcessModifyEvents();
1916 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ||
1917 mImpl->mTextUpdateInfo.mFullRelayoutNeeded ||
1918 mImpl->mTextUpdateInfo.mClearAll )
1920 // Operations that can be done only once until the text changes.
1921 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1928 GET_GLYPH_METRICS );
1930 // Set the update info to relayout the whole text.
1931 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1932 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1934 // Make sure the model is up-to-date before layouting
1935 mImpl->UpdateModel( onlyOnceOperations );
1938 // Layout the text for the new width.
1939 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
1941 // Store the actual control's width.
1942 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
1944 DoRelayout( Size( width, MAX_FLOAT ),
1945 static_cast<OperationsMask>( onlyOnceOperations |
1949 // Do not do again the only once operations.
1950 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1952 // Do the size related operations again.
1953 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1957 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1959 // Clear the update info. This info will be set the next time the text is updated.
1960 mImpl->mTextUpdateInfo.Clear();
1961 mImpl->mTextUpdateInfo.mClearAll = true;
1963 // Restore the actual control's width.
1964 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
1966 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
1970 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
1971 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
1974 return layoutSize.height;
1977 int Controller::GetLineCount( float width )
1979 GetHeightForWidth( width );
1980 int numberofLines = mImpl->mModel->GetNumberOfLines();
1981 return numberofLines;
1984 const ModelInterface* const Controller::GetTextModel() const
1986 return mImpl->mModel.Get();
1989 float Controller::GetScrollAmountByUserInput()
1991 float scrollAmount = 0.0f;
1993 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
1995 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
1996 mImpl->mEventData->mCheckScrollAmount = false;
1998 return scrollAmount;
2001 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
2003 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
2006 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
2007 layoutHeight = layout.height;
2008 scrollPosition = mImpl->mModel->mScrollPosition.y;
2009 isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
2013 void Controller::SetHiddenInputOption(const Property::Map& options )
2015 if( NULL == mImpl->mHiddenInput )
2017 mImpl->mHiddenInput = new HiddenText( this );
2019 mImpl->mHiddenInput->SetProperties(options);
2022 void Controller::GetHiddenInputOption(Property::Map& options )
2024 if( NULL != mImpl->mHiddenInput )
2026 mImpl->mHiddenInput->GetProperties(options);
2030 void Controller::SetPlaceholderProperty( const Property::Map& map )
2032 const Property::Map::SizeType count = map.Count();
2034 for( Property::Map::SizeType position = 0; position < count; ++position )
2036 KeyValuePair keyValue = map.GetKeyValue( position );
2037 Property::Key& key = keyValue.first;
2038 Property::Value& value = keyValue.second;
2040 if( key == Toolkit::Text::PlaceHolder::Property::TEXT || key == PLACEHOLDER_TEXT )
2042 std::string text = "";
2044 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
2046 else if( key == Toolkit::Text::PlaceHolder::Property::TEXT_FOCUSED || key == PLACEHOLDER_TEXT_FOCUSED )
2048 std::string text = "";
2050 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
2052 else if( key == Toolkit::Text::PlaceHolder::Property::COLOR || key == PLACEHOLDER_COLOR )
2055 value.Get( textColor );
2056 if( GetPlaceholderTextColor() != textColor )
2058 SetPlaceholderTextColor( textColor );
2061 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_FAMILY || key == PLACEHOLDER_FONT_FAMILY )
2063 std::string fontFamily = "";
2064 value.Get( fontFamily );
2065 SetPlaceholderFontFamily( fontFamily );
2067 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_STYLE || key == PLACEHOLDER_FONT_STYLE )
2069 SetFontStyleProperty( this, value, Text::FontStyle::PLACEHOLDER );
2071 else if( key == Toolkit::Text::PlaceHolder::Property::POINT_SIZE || key == PLACEHOLDER_POINT_SIZE )
2074 value.Get( pointSize );
2075 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
2077 SetPlaceholderTextFontSize( pointSize, Text::Controller::POINT_SIZE );
2080 else if( key == Toolkit::Text::PlaceHolder::Property::PIXEL_SIZE || key == PLACEHOLDER_PIXEL_SIZE )
2083 value.Get( pixelSize );
2084 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
2086 SetPlaceholderTextFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
2089 else if( key == Toolkit::Text::PlaceHolder::Property::ELLIPSIS || key == PLACEHOLDER_ELLIPSIS )
2092 value.Get( ellipsis );
2093 SetPlaceholderTextElideEnabled( ellipsis );
2098 void Controller::GetPlaceholderProperty( Property::Map& map )
2100 if( NULL != mImpl->mEventData )
2102 if( !mImpl->mEventData->mPlaceholderTextActive.empty() )
2104 map[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = mImpl->mEventData->mPlaceholderTextActive;
2106 if( !mImpl->mEventData->mPlaceholderTextInactive.empty() )
2108 map[ Text::PlaceHolder::Property::TEXT ] = mImpl->mEventData->mPlaceholderTextInactive;
2111 map[ Text::PlaceHolder::Property::COLOR ] = mImpl->mEventData->mPlaceholderTextColor;
2112 map[ Text::PlaceHolder::Property::FONT_FAMILY ] = GetPlaceholderFontFamily();
2114 Property::Value fontStyleMapGet;
2115 GetFontStyleProperty( this, fontStyleMapGet, Text::FontStyle::PLACEHOLDER );
2116 map[ Text::PlaceHolder::Property::FONT_STYLE ] = fontStyleMapGet;
2118 // Choose font size : POINT_SIZE or PIXEL_SIZE
2119 if( !mImpl->mEventData->mIsPlaceholderPixelSize )
2121 map[ Text::PlaceHolder::Property::POINT_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE );
2125 map[ Text::PlaceHolder::Property::PIXEL_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE );
2128 if( mImpl->mEventData->mPlaceholderEllipsisFlag )
2130 map[ Text::PlaceHolder::Property::ELLIPSIS ] = IsPlaceholderTextElideEnabled();
2135 Toolkit::DevelText::TextDirection::Type Controller::GetTextDirection()
2137 // Make sure the model is up-to-date before layouting
2138 ProcessModifyEvents();
2140 if ( mImpl->mUpdateTextDirection )
2142 // Operations that can be done only once until the text changes.
2143 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2150 GET_GLYPH_METRICS );
2152 // Set the update info to relayout the whole text.
2153 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2154 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2156 // Make sure the model is up-to-date before layouting
2157 mImpl->UpdateModel( onlyOnceOperations );
2159 Vector3 naturalSize;
2160 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
2161 static_cast<OperationsMask>( onlyOnceOperations |
2162 LAYOUT | REORDER | UPDATE_DIRECTION ),
2163 naturalSize.GetVectorXY() );
2165 // Do not do again the only once operations.
2166 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2168 // Clear the update info. This info will be set the next time the text is updated.
2169 mImpl->mTextUpdateInfo.Clear();
2171 mImpl->mUpdateTextDirection = false;
2174 return mImpl->mIsTextDirectionRTL ? Toolkit::DevelText::TextDirection::RIGHT_TO_LEFT : Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT;
2177 Toolkit::DevelText::VerticalLineAlignment::Type Controller::GetVerticalLineAlignment() const
2179 return mImpl->mModel->GetVerticalLineAlignment();
2182 void Controller::SetVerticalLineAlignment( Toolkit::DevelText::VerticalLineAlignment::Type alignment )
2184 mImpl->mModel->mVerticalLineAlignment = alignment;
2187 // public : Relayout.
2189 Controller::UpdateTextType Controller::Relayout( const Size& size )
2191 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
2193 UpdateTextType updateTextType = NONE_UPDATED;
2195 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
2197 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
2199 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
2200 updateTextType = MODEL_UPDATED;
2203 // Clear the update info. This info will be set the next time the text is updated.
2204 mImpl->mTextUpdateInfo.Clear();
2206 // Not worth to relayout if width or height is equal to zero.
2207 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
2209 return updateTextType;
2212 // Whether a new size has been set.
2213 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
2217 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
2219 if( ( 0 == mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd ) &&
2220 ( 0 == mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) &&
2221 ( ( mImpl->mModel->mVisualModel->mControlSize.width < Math::MACHINE_EPSILON_1000 ) || ( mImpl->mModel->mVisualModel->mControlSize.height < Math::MACHINE_EPSILON_1000 ) ) )
2223 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
2226 // Layout operations that need to be done if the size changes.
2227 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2230 UPDATE_LAYOUT_SIZE |
2232 // Set the update info to relayout the whole text.
2233 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2234 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2236 // Store the size used to layout the text.
2237 mImpl->mModel->mVisualModel->mControlSize = size;
2240 // Whether there are modify events.
2241 if( 0u != mImpl->mModifyEvents.Count() )
2243 // Style operations that need to be done if the text is modified.
2244 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2248 // Set the update info to elide the text.
2249 if( mImpl->mModel->mElideEnabled ||
2250 ( ( NULL != mImpl->mEventData ) && mImpl->mEventData->mIsPlaceholderElideEnabled ) )
2252 // Update Text layout for applying elided
2253 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2256 UPDATE_LAYOUT_SIZE |
2258 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2259 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2262 // Make sure the model is up-to-date before layouting.
2263 ProcessModifyEvents();
2264 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
2268 updated = DoRelayout( size,
2269 mImpl->mOperationsPending,
2270 layoutSize ) || updated;
2274 updateTextType = MODEL_UPDATED;
2277 // Do not re-do any operation until something changes.
2278 mImpl->mOperationsPending = NO_OPERATION;
2279 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
2281 // Whether the text control is editable
2282 const bool isEditable = NULL != mImpl->mEventData;
2284 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
2286 if( newSize && isEditable )
2288 offset = mImpl->mModel->mScrollPosition;
2291 if( !isEditable || !IsMultiLineEnabled() )
2293 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
2294 CalculateVerticalOffset( size );
2301 // If there is a new size, the scroll position needs to be clamped.
2302 mImpl->ClampHorizontalScroll( layoutSize );
2304 // Update the decorator's positions is needed if there is a new size.
2305 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
2308 // Move the cursor, grab handle etc.
2309 if( mImpl->ProcessInputEvents() )
2311 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
2315 // Clear the update info. This info will be set the next time the text is updated.
2316 mImpl->mTextUpdateInfo.Clear();
2317 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
2319 return updateTextType;
2322 void Controller::RequestRelayout()
2324 mImpl->RequestRelayout();
2327 // public : Input style change signals.
2329 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
2331 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
2334 void Controller::ProcessInputStyleChangedSignals()
2336 if( NULL == mImpl->mEventData )
2342 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
2343 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
2347 const InputStyle::Mask mask = *it;
2349 if( NULL != mImpl->mEditableControlInterface )
2351 // Emit the input style changed signal.
2352 mImpl->mEditableControlInterface->InputStyleChanged( mask );
2356 mImpl->mEventData->mInputStyleChangedQueue.Clear();
2359 // public : Text-input Event Queuing.
2361 void Controller::KeyboardFocusGainEvent()
2363 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
2365 if( NULL != mImpl->mEventData )
2367 if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
2368 ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
2370 mImpl->ChangeState( EventData::EDITING );
2371 mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
2372 mImpl->mEventData->mUpdateInputStyle = true;
2374 mImpl->NotifyImfMultiLineStatus();
2375 if( mImpl->IsShowingPlaceholderText() )
2377 // Show alternative placeholder-text when editing
2378 ShowPlaceholderText();
2381 mImpl->RequestRelayout();
2385 void Controller::KeyboardFocusLostEvent()
2387 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
2389 if( NULL != mImpl->mEventData )
2391 if( EventData::INTERRUPTED != mImpl->mEventData->mState )
2393 mImpl->ChangeState( EventData::INACTIVE );
2395 if( !mImpl->IsShowingRealText() )
2397 // Revert to regular placeholder-text when not editing
2398 ShowPlaceholderText();
2402 mImpl->RequestRelayout();
2405 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
2407 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
2409 bool textChanged = false;
2410 bool relayoutNeeded = false;
2412 if( ( NULL != mImpl->mEventData ) &&
2413 ( keyEvent.state == KeyEvent::Down ) )
2415 int keyCode = keyEvent.keyCode;
2416 const std::string& keyString = keyEvent.keyPressed;
2417 const std::string keyName = keyEvent.keyPressedName;
2419 const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
2421 // Pre-process to separate modifying events from non-modifying input events.
2424 // In some platforms arrive key events with no key code.
2428 else if( Dali::DALI_KEY_ESCAPE == keyCode || Dali::DALI_KEY_BACK == keyCode || Dali::DALI_KEY_SEARCH == keyCode )
2433 else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) ||
2434 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
2435 ( Dali::DALI_KEY_CURSOR_UP == keyCode ) ||
2436 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) )
2438 // If don't have any text, do nothing.
2439 if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
2444 uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition;
2445 uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2446 uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition );
2447 uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines();
2449 // Logic to determine whether this text control will lose focus or not.
2450 if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2451 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2452 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) ||
2453 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) ||
2454 ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) ||
2455 ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) )
2457 // Release the active highlight.
2458 if( mImpl->mEventData->mState == EventData::SELECTING )
2460 mImpl->ChangeState( EventData::EDITING );
2462 // Update selection position.
2463 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2464 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2465 mImpl->mEventData->mUpdateCursorPosition = true;
2466 mImpl->RequestRelayout();
2471 mImpl->mEventData->mCheckScrollAmount = true;
2472 Event event( Event::CURSOR_KEY_EVENT );
2473 event.p1.mInt = keyCode;
2474 event.p2.mBool = keyEvent.IsShiftModifier();
2475 mImpl->mEventData->mEventQueue.push_back( event );
2477 // Will request for relayout.
2478 relayoutNeeded = true;
2480 else if ( Dali::DevelKey::DALI_KEY_CONTROL_LEFT == keyCode || Dali::DevelKey::DALI_KEY_CONTROL_RIGHT == keyCode )
2482 // Left or Right Control key event is received before Ctrl-C/V/X key event is received
2483 // If not handle it here, any selected text will be deleted
2488 else if ( keyEvent.IsCtrlModifier() )
2490 bool consumed = false;
2491 if (keyName == KEY_C_NAME)
2493 // Ctrl-C to copy the selected text
2494 TextPopupButtonTouched( Toolkit::TextSelectionPopup::COPY );
2497 else if (keyName == KEY_V_NAME)
2499 // Ctrl-V to paste the copied text
2500 TextPopupButtonTouched( Toolkit::TextSelectionPopup::PASTE );
2503 else if (keyName == KEY_X_NAME)
2505 // Ctrl-X to cut the selected text
2506 TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
2511 else if( ( Dali::DALI_KEY_BACKSPACE == keyCode ) ||
2512 ( Dali::DevelKey::DALI_KEY_DELETE == keyCode ) )
2514 textChanged = DeleteEvent( keyCode );
2516 // Will request for relayout.
2517 relayoutNeeded = true;
2519 else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
2520 IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
2521 IsKey( keyEvent, static_cast<Dali::KEY>(Dali::DevelKey::DALI_KEY_SOURCE) ) ||
2522 IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
2524 // Power key/Menu/Home key behaviour does not allow edit mode to resume.
2525 mImpl->ChangeState( EventData::INACTIVE );
2527 // Will request for relayout.
2528 relayoutNeeded = true;
2530 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2532 else if( Dali::DALI_KEY_SHIFT_LEFT == keyCode )
2534 // DALI_KEY_SHIFT_LEFT is the key code for the Left Shift. It's sent (by the imf?) when the predictive text is enabled
2535 // and a character is typed after the type of a upper case latin character.
2540 else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
2542 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2548 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
2550 // IMF manager is no longer handling key-events
2551 mImpl->ClearPreEditFlag();
2553 InsertText( keyString, COMMIT );
2556 // Will request for relayout.
2557 relayoutNeeded = true;
2560 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
2561 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
2563 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
2564 ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
2565 ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
2567 // Should not change the state if the key is the shift send by the imf manager.
2568 // Otherwise, when the state is SELECTING the text controller can't send the right
2569 // surrounding info to the imf.
2570 mImpl->ChangeState( EventData::EDITING );
2572 // Will request for relayout.
2573 relayoutNeeded = true;
2576 if( relayoutNeeded )
2578 mImpl->RequestRelayout();
2583 ( NULL != mImpl->mEditableControlInterface ) )
2585 // Do this last since it provides callbacks into application code
2586 mImpl->mEditableControlInterface->TextChanged();
2592 void Controller::TapEvent( unsigned int tapCount, float x, float y )
2594 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
2596 if( NULL != mImpl->mEventData )
2598 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
2599 EventData::State state( mImpl->mEventData->mState );
2600 bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
2602 if( mImpl->IsClipboardVisible() )
2604 if( EventData::INACTIVE == state || EventData::EDITING == state)
2606 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2608 relayoutNeeded = true;
2610 else if( 1u == tapCount )
2612 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
2614 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
2617 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
2619 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2620 relayoutNeeded = true;
2624 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
2626 // Hide placeholder text
2630 if( EventData::INACTIVE == state )
2632 mImpl->ChangeState( EventData::EDITING );
2634 else if( !mImpl->IsClipboardEmpty() )
2636 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
2638 relayoutNeeded = true;
2641 else if( 2u == tapCount )
2643 if( mImpl->mEventData->mSelectionEnabled &&
2644 mImpl->IsShowingRealText() )
2646 relayoutNeeded = true;
2647 mImpl->mEventData->mIsLeftHandleSelected = true;
2648 mImpl->mEventData->mIsRightHandleSelected = true;
2652 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
2653 if( relayoutNeeded )
2655 Event event( Event::TAP_EVENT );
2656 event.p1.mUint = tapCount;
2657 event.p2.mFloat = x;
2658 event.p3.mFloat = y;
2659 mImpl->mEventData->mEventQueue.push_back( event );
2661 mImpl->RequestRelayout();
2665 // Reset keyboard as tap event has occurred.
2666 mImpl->ResetImfManager();
2669 void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
2671 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
2673 if( NULL != mImpl->mEventData )
2675 Event event( Event::PAN_EVENT );
2676 event.p1.mInt = state;
2677 event.p2.mFloat = displacement.x;
2678 event.p3.mFloat = displacement.y;
2679 mImpl->mEventData->mEventQueue.push_back( event );
2681 mImpl->RequestRelayout();
2685 void Controller::LongPressEvent( Gesture::State state, float x, float y )
2687 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
2689 if( ( state == Gesture::Started ) &&
2690 ( NULL != mImpl->mEventData ) )
2692 // The 1st long-press on inactive text-field is treated as tap
2693 if( EventData::INACTIVE == mImpl->mEventData->mState )
2695 mImpl->ChangeState( EventData::EDITING );
2697 Event event( Event::TAP_EVENT );
2699 event.p2.mFloat = x;
2700 event.p3.mFloat = y;
2701 mImpl->mEventData->mEventQueue.push_back( event );
2703 mImpl->RequestRelayout();
2705 else if( !mImpl->IsShowingRealText() )
2707 Event event( Event::LONG_PRESS_EVENT );
2708 event.p1.mInt = state;
2709 event.p2.mFloat = x;
2710 event.p3.mFloat = y;
2711 mImpl->mEventData->mEventQueue.push_back( event );
2712 mImpl->RequestRelayout();
2714 else if( !mImpl->IsClipboardVisible() )
2716 // Reset the imf manager to commit the pre-edit before selecting the text.
2717 mImpl->ResetImfManager();
2719 Event event( Event::LONG_PRESS_EVENT );
2720 event.p1.mInt = state;
2721 event.p2.mFloat = x;
2722 event.p3.mFloat = y;
2723 mImpl->mEventData->mEventQueue.push_back( event );
2724 mImpl->RequestRelayout();
2726 mImpl->mEventData->mIsLeftHandleSelected = true;
2727 mImpl->mEventData->mIsRightHandleSelected = true;
2732 ImfManager::ImfCallbackData Controller::OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
2734 // Whether the text needs to be relaid-out.
2735 bool requestRelayout = false;
2737 // Whether to retrieve the text and cursor position to be sent to the IMF manager.
2738 bool retrieveText = false;
2739 bool retrieveCursor = false;
2741 switch( imfEvent.eventName )
2743 case ImfManager::COMMIT:
2745 InsertText( imfEvent.predictiveString, Text::Controller::COMMIT );
2746 requestRelayout = true;
2747 retrieveCursor = true;
2750 case ImfManager::PREEDIT:
2752 InsertText( imfEvent.predictiveString, Text::Controller::PRE_EDIT );
2753 requestRelayout = true;
2754 retrieveCursor = true;
2757 case ImfManager::DELETESURROUNDING:
2759 const bool textDeleted = RemoveText( imfEvent.cursorOffset,
2760 imfEvent.numberOfChars,
2761 DONT_UPDATE_INPUT_STYLE );
2765 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2766 !mImpl->IsPlaceholderAvailable() )
2768 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2772 ShowPlaceholderText();
2774 mImpl->mEventData->mUpdateCursorPosition = true;
2775 mImpl->mEventData->mScrollAfterDelete = true;
2777 requestRelayout = true;
2781 case ImfManager::GETSURROUNDING:
2783 retrieveText = true;
2784 retrieveCursor = true;
2787 case ImfManager::PRIVATECOMMAND:
2789 // PRIVATECOMMAND event is just for getting the private command message
2790 retrieveText = true;
2791 retrieveCursor = true;
2794 case ImfManager::VOID:
2801 if( requestRelayout )
2803 mImpl->mOperationsPending = ALL_OPERATIONS;
2804 mImpl->RequestRelayout();
2808 CharacterIndex cursorPosition = 0u;
2809 Length numberOfWhiteSpaces = 0u;
2811 if( retrieveCursor )
2813 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
2815 cursorPosition = mImpl->GetLogicalCursorPosition();
2817 if( cursorPosition < numberOfWhiteSpaces )
2819 cursorPosition = 0u;
2823 cursorPosition -= numberOfWhiteSpaces;
2829 if( !mImpl->IsShowingPlaceholderText() )
2831 // Retrieves the normal text string.
2832 mImpl->GetText( numberOfWhiteSpaces, text );
2836 // When the current text is Placeholder Text, the surrounding text should be empty string.
2837 // It means DALi should send empty string ("") to IME.
2842 ImfManager::ImfCallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
2844 if( requestRelayout &&
2845 ( NULL != mImpl->mEditableControlInterface ) )
2847 // Do this last since it provides callbacks into application code
2848 mImpl->mEditableControlInterface->TextChanged();
2851 return callbackData;
2854 void Controller::PasteClipboardItemEvent()
2856 // Retrieve the clipboard contents first
2857 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
2858 std::string stringToPaste( notifier.GetContent() );
2860 // Commit the current pre-edit text; the contents of the clipboard should be appended
2861 mImpl->ResetImfManager();
2863 // Temporary disable hiding clipboard
2864 mImpl->SetClipboardHideEnable( false );
2867 PasteText( stringToPaste );
2869 mImpl->SetClipboardHideEnable( true );
2872 // protected : Inherit from Text::Decorator::ControllerInterface.
2874 void Controller::GetTargetSize( Vector2& targetSize )
2876 targetSize = mImpl->mModel->mVisualModel->mControlSize;
2879 void Controller::AddDecoration( Actor& actor, bool needsClipping )
2881 if( NULL != mImpl->mEditableControlInterface )
2883 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
2887 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
2889 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
2891 if( NULL != mImpl->mEventData )
2893 switch( handleType )
2897 Event event( Event::GRAB_HANDLE_EVENT );
2898 event.p1.mUint = state;
2899 event.p2.mFloat = x;
2900 event.p3.mFloat = y;
2902 mImpl->mEventData->mEventQueue.push_back( event );
2905 case LEFT_SELECTION_HANDLE:
2907 Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
2908 event.p1.mUint = state;
2909 event.p2.mFloat = x;
2910 event.p3.mFloat = y;
2912 mImpl->mEventData->mEventQueue.push_back( event );
2915 case RIGHT_SELECTION_HANDLE:
2917 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
2918 event.p1.mUint = state;
2919 event.p2.mFloat = x;
2920 event.p3.mFloat = y;
2922 mImpl->mEventData->mEventQueue.push_back( event );
2925 case LEFT_SELECTION_HANDLE_MARKER:
2926 case RIGHT_SELECTION_HANDLE_MARKER:
2928 // Markers do not move the handles.
2931 case HANDLE_TYPE_COUNT:
2933 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
2937 mImpl->RequestRelayout();
2941 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
2943 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
2945 if( NULL == mImpl->mEventData )
2952 case Toolkit::TextSelectionPopup::CUT:
2954 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
2955 mImpl->mOperationsPending = ALL_OPERATIONS;
2957 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2958 !mImpl->IsPlaceholderAvailable() )
2960 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2964 ShowPlaceholderText();
2967 mImpl->mEventData->mUpdateCursorPosition = true;
2968 mImpl->mEventData->mScrollAfterDelete = true;
2970 mImpl->RequestRelayout();
2972 if( NULL != mImpl->mEditableControlInterface )
2974 mImpl->mEditableControlInterface->TextChanged();
2978 case Toolkit::TextSelectionPopup::COPY:
2980 mImpl->SendSelectionToClipboard( false ); // Text not modified
2982 mImpl->mEventData->mUpdateCursorPosition = true;
2984 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
2987 case Toolkit::TextSelectionPopup::PASTE:
2989 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
2992 case Toolkit::TextSelectionPopup::SELECT:
2994 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
2996 if( mImpl->mEventData->mSelectionEnabled )
2998 // Creates a SELECT event.
2999 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
3003 case Toolkit::TextSelectionPopup::SELECT_ALL:
3005 // Creates a SELECT_ALL event
3006 SelectEvent( 0.f, 0.f, true );
3009 case Toolkit::TextSelectionPopup::CLIPBOARD:
3011 mImpl->ShowClipboard();
3014 case Toolkit::TextSelectionPopup::NONE:
3022 void Controller::DisplayTimeExpired()
3024 mImpl->mEventData->mUpdateCursorPosition = true;
3025 // Apply modifications to the model
3026 mImpl->mOperationsPending = ALL_OPERATIONS;
3028 mImpl->RequestRelayout();
3031 // private : Update.
3033 void Controller::InsertText( const std::string& text, Controller::InsertType type )
3035 bool removedPrevious = false;
3036 bool removedSelected = false;
3037 bool maxLengthReached = false;
3039 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
3041 if( NULL == mImpl->mEventData )
3046 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
3047 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
3048 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3050 // TODO: At the moment the underline runs are only for pre-edit.
3051 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
3053 // Remove the previous IMF pre-edit.
3054 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
3056 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
3057 mImpl->mEventData->mPreEditLength,
3058 DONT_UPDATE_INPUT_STYLE );
3060 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
3061 mImpl->mEventData->mPreEditLength = 0u;
3065 // Remove the previous Selection.
3066 removedSelected = RemoveSelectedText();
3070 Vector<Character> utf32Characters;
3071 Length characterCount = 0u;
3075 // Convert text into UTF-32
3076 utf32Characters.Resize( text.size() );
3078 // This is a bit horrible but std::string returns a (signed) char*
3079 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
3081 // Transform a text array encoded in utf8 into an array encoded in utf32.
3082 // It returns the actual number of characters.
3083 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
3084 utf32Characters.Resize( characterCount );
3086 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
3087 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
3090 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
3092 // The placeholder text is no longer needed
3093 if( mImpl->IsShowingPlaceholderText() )
3098 mImpl->ChangeState( EventData::EDITING );
3100 // Handle the IMF (predicitive text) state changes
3101 if( COMMIT == type )
3103 // IMF manager is no longer handling key-events
3104 mImpl->ClearPreEditFlag();
3108 if( !mImpl->mEventData->mPreEditFlag )
3110 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
3112 // Record the start of the pre-edit text
3113 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
3116 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
3117 mImpl->mEventData->mPreEditFlag = true;
3119 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3122 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
3124 // Restrict new text to fit within Maximum characters setting.
3125 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
3126 maxLengthReached = ( characterCount > maxSizeOfNewText );
3128 // The cursor position.
3129 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3131 // Update the text's style.
3133 // Updates the text style runs by adding characters.
3134 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
3136 // Get the character index from the cursor index.
3137 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
3139 // Retrieve the text's style for the given index.
3141 mImpl->RetrieveDefaultInputStyle( style );
3142 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
3144 // Whether to add a new text color run.
3145 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor );
3147 // Whether to add a new font run.
3148 const bool addFontNameRun = style.familyName != mImpl->mEventData->mInputStyle.familyName;
3149 const bool addFontWeightRun = style.weight != mImpl->mEventData->mInputStyle.weight;
3150 const bool addFontWidthRun = style.width != mImpl->mEventData->mInputStyle.width;
3151 const bool addFontSlantRun = style.slant != mImpl->mEventData->mInputStyle.slant;
3152 const bool addFontSizeRun = style.size != mImpl->mEventData->mInputStyle.size;
3157 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
3158 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
3160 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
3161 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
3162 colorRun.characterRun.characterIndex = cursorIndex;
3163 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3166 if( addFontNameRun ||
3172 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
3173 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
3175 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
3177 if( addFontNameRun )
3179 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
3180 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
3181 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
3182 fontDescriptionRun.familyDefined = true;
3184 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
3187 if( addFontWeightRun )
3189 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
3190 fontDescriptionRun.weightDefined = true;
3193 if( addFontWidthRun )
3195 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
3196 fontDescriptionRun.widthDefined = true;
3199 if( addFontSlantRun )
3201 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
3202 fontDescriptionRun.slantDefined = true;
3205 if( addFontSizeRun )
3207 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
3208 fontDescriptionRun.sizeDefined = true;
3211 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
3212 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3215 // Insert at current cursor position.
3216 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
3218 if( cursorIndex < numberOfCharactersInModel )
3220 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3224 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3227 // Mark the first paragraph to be updated.
3228 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3230 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3231 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3232 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
3233 mImpl->mTextUpdateInfo.mClearAll = true;
3237 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3238 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
3241 // Update the cursor index.
3242 cursorIndex += maxSizeOfNewText;
3244 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 );
3247 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
3248 mImpl->IsPlaceholderAvailable() )
3250 // Show place-holder if empty after removing the pre-edit text
3251 ShowPlaceholderText();
3252 mImpl->mEventData->mUpdateCursorPosition = true;
3253 mImpl->ClearPreEditFlag();
3255 else if( removedPrevious ||
3257 ( 0 != utf32Characters.Count() ) )
3259 // Queue an inserted event
3260 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
3262 mImpl->mEventData->mUpdateCursorPosition = true;
3263 if( removedSelected )
3265 mImpl->mEventData->mScrollAfterDelete = true;
3269 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3273 if( maxLengthReached )
3275 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
3277 mImpl->ResetImfManager();
3279 if( NULL != mImpl->mEditableControlInterface )
3281 // Do this last since it provides callbacks into application code
3282 mImpl->mEditableControlInterface->MaxLengthReached();
3287 void Controller::PasteText( const std::string& stringToPaste )
3289 InsertText( stringToPaste, Text::Controller::COMMIT );
3290 mImpl->ChangeState( EventData::EDITING );
3291 mImpl->RequestRelayout();
3293 if( NULL != mImpl->mEditableControlInterface )
3295 // Do this last since it provides callbacks into application code
3296 mImpl->mEditableControlInterface->TextChanged();
3300 bool Controller::RemoveText( int cursorOffset,
3301 int numberOfCharacters,
3302 UpdateInputStyleType type )
3304 bool removed = false;
3306 // When the users press "Delete All" button, the IME sends numberOfCharacters as '200000' value which means the max number of characters.
3307 const bool deleteAll = ( numberOfCharacters >= MAX_NUMBER_OF_CHARACTERS );
3309 if( NULL == mImpl->mEventData )
3314 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
3315 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
3317 if( !mImpl->IsShowingPlaceholderText() )
3319 // Delete at current cursor position
3320 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
3321 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3323 CharacterIndex cursorIndex = 0;
3325 // Validate the cursor position & number of characters
3326 if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
3328 cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
3331 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
3333 numberOfCharacters = currentText.Count() - cursorIndex;
3336 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.
3337 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) || deleteAll /*'Delete All' button clicked*/ )
3339 // Mark the paragraphs to be updated.
3340 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3342 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3343 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3344 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
3345 mImpl->mTextUpdateInfo.mClearAll = true;
3349 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3350 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
3353 // Update the input style and remove the text's style before removing the text.
3355 if( UPDATE_INPUT_STYLE == type )
3357 // Keep a copy of the current input style.
3358 InputStyle currentInputStyle;
3359 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
3361 // Set first the default input style.
3362 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
3364 // Update the input style.
3365 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
3367 // Compare if the input style has changed.
3368 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
3370 if( hasInputStyleChanged )
3372 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
3373 // Queue the input style changed signal.
3374 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
3378 // Updates the text style runs by removing characters. Runs with no characters are removed.
3379 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
3381 // Remove the characters.
3382 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
3383 Vector<Character>::Iterator last = first + numberOfCharacters;
3385 currentText.Erase( first, last );
3387 // Cursor position retreat
3388 oldCursorIndex = cursorIndex;
3390 mImpl->mEventData->mScrollAfterDelete = true;
3392 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
3400 bool Controller::RemoveSelectedText()
3402 bool textRemoved( false );
3404 if( EventData::SELECTING == mImpl->mEventData->mState )
3406 std::string removedString;
3407 mImpl->RetrieveSelection( removedString, true );
3409 if( !removedString.empty() )
3412 mImpl->ChangeState( EventData::EDITING );
3419 // private : Relayout.
3421 bool Controller::DoRelayout( const Size& size,
3422 OperationsMask operationsRequired,
3425 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
3426 bool viewUpdated( false );
3428 // Calculate the operations to be done.
3429 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
3431 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
3432 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
3434 // Get the current layout size.
3435 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3437 if( NO_OPERATION != ( LAYOUT & operations ) )
3439 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
3441 // Some vectors with data needed to layout and reorder may be void
3442 // after the first time the text has been laid out.
3443 // Fill the vectors again.
3445 // Calculate the number of glyphs to layout.
3446 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
3447 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
3448 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
3449 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
3451 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
3452 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
3454 // Make sure the index is not out of bound
3455 if ( charactersToGlyph.Count() != glyphsPerCharacter.Count() ||
3456 requestedNumberOfCharacters > charactersToGlyph.Count() ||
3457 ( lastIndex >= charactersToGlyph.Count() && charactersToGlyph.Count() > 0u ) )
3459 std::string currentText;
3460 GetText( currentText );
3462 DALI_LOG_ERROR( "Controller::DoRelayout: Attempting to access invalid buffer\n" );
3463 DALI_LOG_ERROR( "Current text is: %s\n", currentText.c_str() );
3464 DALI_LOG_ERROR( "startIndex: %u, lastIndex: %u, requestedNumberOfCharacters: %u, charactersToGlyph.Count = %lu, glyphsPerCharacter.Count = %lu\n", startIndex, lastIndex, requestedNumberOfCharacters, charactersToGlyph.Count(), glyphsPerCharacter.Count());
3469 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
3470 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
3472 if( 0u == totalNumberOfGlyphs )
3474 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3476 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
3479 // Nothing else to do if there is no glyphs.
3480 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
3484 const Vector<LineBreakInfo>& lineBreakInfo = mImpl->mModel->mLogicalModel->mLineBreakInfo;
3485 const Vector<WordBreakInfo>& wordBreakInfo = mImpl->mModel->mLogicalModel->mWordBreakInfo;
3486 const Vector<CharacterDirection>& characterDirection = mImpl->mModel->mLogicalModel->mCharacterDirections;
3487 const Vector<GlyphInfo>& glyphs = mImpl->mModel->mVisualModel->mGlyphs;
3488 const Vector<CharacterIndex>& glyphsToCharactersMap = mImpl->mModel->mVisualModel->mGlyphsToCharacters;
3489 const Vector<Length>& charactersPerGlyph = mImpl->mModel->mVisualModel->mCharactersPerGlyph;
3490 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
3491 const float outlineWidth = static_cast<float>( mImpl->mModel->GetOutlineWidth() );
3493 // Set the layout parameters.
3494 Layout::Parameters layoutParameters( size,
3496 lineBreakInfo.Begin(),
3497 wordBreakInfo.Begin(),
3498 ( 0u != characterDirection.Count() ) ? characterDirection.Begin() : NULL,
3500 glyphsToCharactersMap.Begin(),
3501 charactersPerGlyph.Begin(),
3502 charactersToGlyphBuffer,
3503 glyphsPerCharacterBuffer,
3504 totalNumberOfGlyphs,
3505 mImpl->mModel->mHorizontalAlignment,
3506 mImpl->mModel->mLineWrapMode,
3509 // Resize the vector of positions to have the same size than the vector of glyphs.
3510 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
3511 glyphPositions.Resize( totalNumberOfGlyphs );
3513 // Whether the last character is a new paragraph character.
3514 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
3515 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
3517 // The initial glyph and the number of glyphs to layout.
3518 layoutParameters.startGlyphIndex = startGlyphIndex;
3519 layoutParameters.numberOfGlyphs = numberOfGlyphs;
3520 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
3521 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
3523 // Update the ellipsis
3524 bool elideTextEnabled = mImpl->mModel->mElideEnabled;
3526 if( NULL != mImpl->mEventData )
3528 if( mImpl->mEventData->mPlaceholderEllipsisFlag && mImpl->IsShowingPlaceholderText() )
3530 elideTextEnabled = mImpl->mEventData->mIsPlaceholderElideEnabled;
3532 else if( EventData::INACTIVE != mImpl->mEventData->mState )
3534 // Disable ellipsis when editing
3535 elideTextEnabled = false;
3538 // Reset the scroll position in inactive state
3539 if( elideTextEnabled && ( mImpl->mEventData->mState == EventData::INACTIVE ) )
3541 ResetScrollPosition();
3545 // Update the visual model.
3547 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
3549 mImpl->mModel->mVisualModel->mLines,
3553 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
3557 layoutSize = newLayoutSize;
3559 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
3561 mImpl->mIsTextDirectionRTL = false;
3564 // Reorder the lines
3565 if( NO_OPERATION != ( REORDER & operations ) )
3567 Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = mImpl->mModel->mLogicalModel->mBidirectionalParagraphInfo;
3568 Vector<BidirectionalLineInfoRun>& bidirectionalLineInfo = mImpl->mModel->mLogicalModel->mBidirectionalLineInfo;
3570 // Check first if there are paragraphs with bidirectional info.
3571 if( 0u != bidirectionalInfo.Count() )
3574 const Length numberOfLines = mImpl->mModel->mVisualModel->mLines.Count();
3576 // Reorder the lines.
3577 bidirectionalLineInfo.Reserve( numberOfLines ); // Reserve because is not known yet how many lines have right to left characters.
3578 ReorderLines( bidirectionalInfo,
3580 requestedNumberOfCharacters,
3581 mImpl->mModel->mVisualModel->mLines,
3582 bidirectionalLineInfo );
3584 // Set the bidirectional info per line into the layout parameters.
3585 layoutParameters.lineBidirectionalInfoRunsBuffer = bidirectionalLineInfo.Begin();
3586 layoutParameters.numberOfBidirectionalInfoRuns = bidirectionalLineInfo.Count();
3588 // Re-layout the text. Reorder those lines with right to left characters.
3589 mImpl->mLayoutEngine.ReLayoutRightToLeftLines( layoutParameters,
3591 requestedNumberOfCharacters,
3594 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && ( numberOfLines > 0 ) )
3596 const LineRun* const firstline = mImpl->mModel->mVisualModel->mLines.Begin();
3599 mImpl->mIsTextDirectionRTL = firstline->direction;
3605 // Sets the layout size.
3606 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3608 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
3613 if( NO_OPERATION != ( ALIGN & operations ) )
3615 // The laid-out lines.
3616 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
3618 // Need to align with the control's size as the text may contain lines
3619 // starting either with left to right text or right to left.
3620 mImpl->mLayoutEngine.Align( size,
3622 requestedNumberOfCharacters,
3623 mImpl->mModel->mHorizontalAlignment,
3625 mImpl->mModel->mAlignmentOffset );
3629 #if defined(DEBUG_ENABLED)
3630 std::string currentText;
3631 GetText( currentText );
3632 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mIsTextDirectionRTL[%s] [%s]\n", this, (mImpl->mIsTextDirectionRTL)?"true":"false", currentText.c_str() );
3634 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
3638 void Controller::CalculateVerticalOffset( const Size& controlSize )
3640 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3642 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
3644 // Get the line height of the default font.
3645 layoutSize.height = mImpl->GetDefaultFontLineHeight();
3648 switch( mImpl->mModel->mVerticalAlignment )
3650 case VerticalAlignment::TOP:
3652 mImpl->mModel->mScrollPosition.y = 0.f;
3655 case VerticalAlignment::CENTER:
3657 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
3660 case VerticalAlignment::BOTTOM:
3662 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
3668 // private : Events.
3670 void Controller::ProcessModifyEvents()
3672 Vector<ModifyEvent>& events = mImpl->mModifyEvents;
3674 if( 0u == events.Count() )
3680 for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
3681 endIt = events.End();
3685 const ModifyEvent& event = *it;
3687 if( ModifyEvent::TEXT_REPLACED == event.type )
3689 // A (single) replace event should come first, otherwise we wasted time processing NOOP events
3690 DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
3692 TextReplacedEvent();
3694 else if( ModifyEvent::TEXT_INSERTED == event.type )
3696 TextInsertedEvent();
3698 else if( ModifyEvent::TEXT_DELETED == event.type )
3700 // Placeholder-text cannot be deleted
3701 if( !mImpl->IsShowingPlaceholderText() )
3708 if( NULL != mImpl->mEventData )
3710 // When the text is being modified, delay cursor blinking
3711 mImpl->mEventData->mDecorator->DelayCursorBlink();
3713 // Update selection position after modifying the text
3714 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
3715 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
3718 // Discard temporary text
3722 void Controller::TextReplacedEvent()
3724 // The natural size needs to be re-calculated.
3725 mImpl->mRecalculateNaturalSize = true;
3727 // The text direction needs to be updated.
3728 mImpl->mUpdateTextDirection = true;
3730 // Apply modifications to the model
3731 mImpl->mOperationsPending = ALL_OPERATIONS;
3734 void Controller::TextInsertedEvent()
3736 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
3738 if( NULL == mImpl->mEventData )
3743 mImpl->mEventData->mCheckScrollAmount = true;
3745 // The natural size needs to be re-calculated.
3746 mImpl->mRecalculateNaturalSize = true;
3748 // The text direction needs to be updated.
3749 mImpl->mUpdateTextDirection = true;
3751 // Apply modifications to the model; TODO - Optimize this
3752 mImpl->mOperationsPending = ALL_OPERATIONS;
3755 void Controller::TextDeletedEvent()
3757 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
3759 if( NULL == mImpl->mEventData )
3764 mImpl->mEventData->mCheckScrollAmount = true;
3766 // The natural size needs to be re-calculated.
3767 mImpl->mRecalculateNaturalSize = true;
3769 // The text direction needs to be updated.
3770 mImpl->mUpdateTextDirection = true;
3772 // Apply modifications to the model; TODO - Optimize this
3773 mImpl->mOperationsPending = ALL_OPERATIONS;
3776 void Controller::SelectEvent( float x, float y, bool selectAll )
3778 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
3780 if( NULL != mImpl->mEventData )
3784 Event event( Event::SELECT_ALL );
3785 mImpl->mEventData->mEventQueue.push_back( event );
3789 Event event( Event::SELECT );
3790 event.p2.mFloat = x;
3791 event.p3.mFloat = y;
3792 mImpl->mEventData->mEventQueue.push_back( event );
3795 mImpl->mEventData->mCheckScrollAmount = true;
3796 mImpl->mEventData->mIsLeftHandleSelected = true;
3797 mImpl->mEventData->mIsRightHandleSelected = true;
3798 mImpl->RequestRelayout();
3802 bool Controller::DeleteEvent( int keyCode )
3804 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p KeyCode : %d \n", this, keyCode );
3806 bool removed = false;
3808 if( NULL == mImpl->mEventData )
3813 // IMF manager is no longer handling key-events
3814 mImpl->ClearPreEditFlag();
3816 if( EventData::SELECTING == mImpl->mEventData->mState )
3818 removed = RemoveSelectedText();
3820 else if( ( mImpl->mEventData->mPrimaryCursorPosition > 0 ) && ( keyCode == Dali::DALI_KEY_BACKSPACE) )
3822 // Remove the character before the current cursor position
3823 removed = RemoveText( -1,
3825 UPDATE_INPUT_STYLE );
3827 else if( keyCode == Dali::DevelKey::DALI_KEY_DELETE )
3829 // Remove the character after the current cursor position
3830 removed = RemoveText( 0,
3832 UPDATE_INPUT_STYLE );
3837 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3838 !mImpl->IsPlaceholderAvailable() )
3840 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3844 ShowPlaceholderText();
3846 mImpl->mEventData->mUpdateCursorPosition = true;
3847 mImpl->mEventData->mScrollAfterDelete = true;
3853 // private : Helpers.
3855 void Controller::ResetText()
3858 mImpl->mModel->mLogicalModel->mText.Clear();
3860 // We have cleared everything including the placeholder-text
3861 mImpl->PlaceholderCleared();
3863 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3864 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3865 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
3867 // Clear any previous text.
3868 mImpl->mTextUpdateInfo.mClearAll = true;
3870 // The natural size needs to be re-calculated.
3871 mImpl->mRecalculateNaturalSize = true;
3873 // The text direction needs to be updated.
3874 mImpl->mUpdateTextDirection = true;
3876 // Apply modifications to the model
3877 mImpl->mOperationsPending = ALL_OPERATIONS;
3880 void Controller::ShowPlaceholderText()
3882 if( mImpl->IsPlaceholderAvailable() )
3884 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
3886 if( NULL == mImpl->mEventData )
3891 mImpl->mEventData->mIsShowingPlaceholderText = true;
3893 // Disable handles when showing place-holder text
3894 mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
3895 mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
3896 mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
3898 const char* text( NULL );
3901 // TODO - Switch Placeholder text when changing state
3902 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
3903 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
3905 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
3906 size = mImpl->mEventData->mPlaceholderTextActive.size();
3910 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
3911 size = mImpl->mEventData->mPlaceholderTextInactive.size();
3914 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3915 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3917 // Reset model for showing placeholder.
3918 mImpl->mModel->mLogicalModel->mText.Clear();
3919 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
3921 // Convert text into UTF-32
3922 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
3923 utf32Characters.Resize( size );
3925 // This is a bit horrible but std::string returns a (signed) char*
3926 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
3928 // Transform a text array encoded in utf8 into an array encoded in utf32.
3929 // It returns the actual number of characters.
3930 const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
3931 utf32Characters.Resize( characterCount );
3933 // The characters to be added.
3934 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
3936 // Reset the cursor position
3937 mImpl->mEventData->mPrimaryCursorPosition = 0;
3939 // The natural size needs to be re-calculated.
3940 mImpl->mRecalculateNaturalSize = true;
3942 // The text direction needs to be updated.
3943 mImpl->mUpdateTextDirection = true;
3945 // Apply modifications to the model
3946 mImpl->mOperationsPending = ALL_OPERATIONS;
3948 // Update the rest of the model during size negotiation
3949 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
3953 void Controller::ClearFontData()
3955 if( mImpl->mFontDefaults )
3957 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
3960 // Set flags to update the model.
3961 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3962 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3963 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
3965 mImpl->mTextUpdateInfo.mClearAll = true;
3966 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
3967 mImpl->mRecalculateNaturalSize = true;
3969 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
3975 UPDATE_LAYOUT_SIZE |
3980 void Controller::ClearStyleData()
3982 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
3983 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
3986 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
3988 // Reset the cursor position
3989 if( NULL != mImpl->mEventData )
3991 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
3993 // Update the cursor if it's in editing mode.
3994 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
3996 mImpl->mEventData->mUpdateCursorPosition = true;
4001 void Controller::ResetScrollPosition()
4003 if( NULL != mImpl->mEventData )
4005 // Reset the scroll position.
4006 mImpl->mModel->mScrollPosition = Vector2::ZERO;
4007 mImpl->mEventData->mScrollAfterUpdatePosition = true;
4011 void Controller::SetControlInterface( ControlInterface* controlInterface )
4013 mImpl->mControlInterface = controlInterface;
4016 bool Controller::ShouldClearFocusOnEscape() const
4018 return mImpl->mShouldClearFocusOnEscape;
4021 // private : Private contructors & copy operator.
4023 Controller::Controller()
4026 mImpl = new Controller::Impl( NULL, NULL );
4029 Controller::Controller( ControlInterface* controlInterface )
4031 mImpl = new Controller::Impl( controlInterface, NULL );
4034 Controller::Controller( ControlInterface* controlInterface,
4035 EditableControlInterface* editableControlInterface )
4037 mImpl = new Controller::Impl( controlInterface,
4038 editableControlInterface );
4041 // The copy constructor and operator are left unimplemented.
4043 // protected : Destructor.
4045 Controller::~Controller()
4052 } // namespace Toolkit