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 float MAX_FLOAT = std::numeric_limits<float>::max();
50 const std::string EMPTY_STRING("");
52 const std::string KEY_C_NAME = "c";
53 const std::string KEY_V_NAME = "v";
54 const std::string KEY_X_NAME = "x";
56 const char * const PLACEHOLDER_TEXT = "text";
57 const char * const PLACEHOLDER_TEXT_FOCUSED = "textFocused";
58 const char * const PLACEHOLDER_COLOR = "color";
59 const char * const PLACEHOLDER_FONT_FAMILY = "fontFamily";
60 const char * const PLACEHOLDER_FONT_STYLE = "fontStyle";
61 const char * const PLACEHOLDER_POINT_SIZE = "pointSize";
62 const char * const PLACEHOLDER_PIXEL_SIZE = "pixelSize";
63 const char * const PLACEHOLDER_ELLIPSIS = "ellipsis";
65 float ConvertToEven( float value )
67 int intValue(static_cast<int>( value ));
68 return static_cast<float>(intValue % 2 == 0) ? intValue : (intValue + 1);
83 * @brief Adds a new font description run for the selected text.
85 * The new font parameters are added after the call to this method.
87 * @param[in] eventData The event data pointer.
88 * @param[in] logicalModel The logical model where to add the new font description run.
89 * @param[out] startOfSelectedText Index to the first selected character.
90 * @param[out] lengthOfSelectedText Number of selected characters.
92 FontDescriptionRun& UpdateSelectionFontStyleRun( EventData* eventData,
93 LogicalModelPtr logicalModel,
94 CharacterIndex& startOfSelectedText,
95 Length& lengthOfSelectedText )
97 const bool handlesCrossed = eventData->mLeftSelectionPosition > eventData->mRightSelectionPosition;
99 // Get start and end position of selection
100 startOfSelectedText = handlesCrossed ? eventData->mRightSelectionPosition : eventData->mLeftSelectionPosition;
101 lengthOfSelectedText = ( handlesCrossed ? eventData->mLeftSelectionPosition : eventData->mRightSelectionPosition ) - startOfSelectedText;
104 const VectorBase::SizeType numberOfRuns = logicalModel->mFontDescriptionRuns.Count();
105 logicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
107 FontDescriptionRun& fontDescriptionRun = *( logicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
109 fontDescriptionRun.characterRun.characterIndex = startOfSelectedText;
110 fontDescriptionRun.characterRun.numberOfCharacters = lengthOfSelectedText;
112 // Recalculate the selection highlight as the metrics may have changed.
113 eventData->mUpdateLeftSelectionPosition = true;
114 eventData->mUpdateRightSelectionPosition = true;
115 eventData->mUpdateHighlightBox = true;
117 return fontDescriptionRun;
120 // public : Constructor.
122 ControllerPtr Controller::New()
124 return ControllerPtr( new Controller() );
127 ControllerPtr Controller::New( ControlInterface* controlInterface )
129 return ControllerPtr( new Controller( controlInterface ) );
132 ControllerPtr Controller::New( ControlInterface* controlInterface,
133 EditableControlInterface* editableControlInterface )
135 return ControllerPtr( new Controller( controlInterface,
136 editableControlInterface ) );
139 // public : Configure the text controller.
141 void Controller::EnableTextInput( DecoratorPtr decorator )
145 delete mImpl->mEventData;
146 mImpl->mEventData = NULL;
148 // Nothing else to do.
152 if( NULL == mImpl->mEventData )
154 mImpl->mEventData = new EventData( decorator );
158 void Controller::SetGlyphType( TextAbstraction::GlyphType glyphType )
160 // Metrics for bitmap & vector based glyphs are different
161 mImpl->mMetrics->SetGlyphType( glyphType );
163 // Clear the font-specific data
166 mImpl->RequestRelayout();
169 void Controller::SetMarkupProcessorEnabled( bool enable )
171 mImpl->mMarkupProcessorEnabled = enable;
174 bool Controller::IsMarkupProcessorEnabled() const
176 return mImpl->mMarkupProcessorEnabled;
179 void Controller::SetAutoScrollEnabled( bool enable )
181 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 );
183 if( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX )
187 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled for SINGLE_LINE_BOX\n" );
188 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
198 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled Disabling autoscroll\n");
199 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
206 mImpl->mIsAutoScrollEnabled = enable;
207 mImpl->RequestRelayout();
211 DALI_LOG_WARNING( "Attempted AutoScrolling on a non SINGLE_LINE_BOX, request ignored\n" );
212 mImpl->mIsAutoScrollEnabled = false;
216 bool Controller::IsAutoScrollEnabled() const
218 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::IsAutoScrollEnabled[%s]\n", mImpl->mIsAutoScrollEnabled?"true":"false" );
220 return mImpl->mIsAutoScrollEnabled;
223 CharacterDirection Controller::GetAutoScrollDirection() const
225 return mImpl->mAutoScrollDirectionRTL;
228 float Controller::GetAutoScrollLineAlignment() const
232 if( mImpl->mModel->mVisualModel &&
233 ( 0u != mImpl->mModel->mVisualModel->mLines.Count() ) )
235 offset = ( *mImpl->mModel->mVisualModel->mLines.Begin() ).alignmentOffset;
241 void Controller::SetHorizontalScrollEnabled( bool enable )
243 if( ( NULL != mImpl->mEventData ) &&
244 mImpl->mEventData->mDecorator )
246 mImpl->mEventData->mDecorator->SetHorizontalScrollEnabled( enable );
249 bool Controller::IsHorizontalScrollEnabled() const
251 if( ( NULL != mImpl->mEventData ) &&
252 mImpl->mEventData->mDecorator )
254 return mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
260 void Controller::SetVerticalScrollEnabled( bool enable )
262 if( ( NULL != mImpl->mEventData ) &&
263 mImpl->mEventData->mDecorator )
265 if( mImpl->mEventData->mDecorator )
267 mImpl->mEventData->mDecorator->SetVerticalScrollEnabled( enable );
272 bool Controller::IsVerticalScrollEnabled() const
274 if( ( NULL != mImpl->mEventData ) &&
275 mImpl->mEventData->mDecorator )
277 return mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
283 void Controller::SetSmoothHandlePanEnabled( bool enable )
285 if( ( NULL != mImpl->mEventData ) &&
286 mImpl->mEventData->mDecorator )
288 mImpl->mEventData->mDecorator->SetSmoothHandlePanEnabled( enable );
292 bool Controller::IsSmoothHandlePanEnabled() const
294 if( ( NULL != mImpl->mEventData ) &&
295 mImpl->mEventData->mDecorator )
297 return mImpl->mEventData->mDecorator->IsSmoothHandlePanEnabled();
303 void Controller::SetMaximumNumberOfCharacters( Length maxCharacters )
305 mImpl->mMaximumNumberOfCharacters = maxCharacters;
308 int Controller::GetMaximumNumberOfCharacters()
310 return mImpl->mMaximumNumberOfCharacters;
313 void Controller::SetEnableCursorBlink( bool enable )
315 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "TextInput disabled" );
317 if( NULL != mImpl->mEventData )
319 mImpl->mEventData->mCursorBlinkEnabled = enable;
322 mImpl->mEventData->mDecorator )
324 mImpl->mEventData->mDecorator->StopCursorBlink();
329 bool Controller::GetEnableCursorBlink() const
331 if( NULL != mImpl->mEventData )
333 return mImpl->mEventData->mCursorBlinkEnabled;
339 void Controller::SetMultiLineEnabled( bool enable )
341 const Layout::Engine::Type layout = enable ? Layout::Engine::MULTI_LINE_BOX : Layout::Engine::SINGLE_LINE_BOX;
343 if( layout != mImpl->mLayoutEngine.GetLayout() )
345 // Set the layout type.
346 mImpl->mLayoutEngine.SetLayout( layout );
348 // Set the flags to redo the layout operations
349 const OperationsMask layoutOperations = static_cast<OperationsMask>( LAYOUT |
354 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
355 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | layoutOperations );
357 mImpl->RequestRelayout();
361 bool Controller::IsMultiLineEnabled() const
363 return Layout::Engine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
366 void Controller::SetHorizontalAlignment( Text::HorizontalAlignment::Type alignment )
368 if( alignment != mImpl->mModel->mHorizontalAlignment )
370 // Set the alignment.
371 mImpl->mModel->mHorizontalAlignment = alignment;
373 // Set the flag to redo the alignment operation.
374 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
376 mImpl->RequestRelayout();
380 Text::HorizontalAlignment::Type Controller::GetHorizontalAlignment() const
382 return mImpl->mModel->mHorizontalAlignment;
385 void Controller::SetVerticalAlignment( VerticalAlignment::Type alignment )
387 if( alignment != mImpl->mModel->mVerticalAlignment )
389 // Set the alignment.
390 mImpl->mModel->mVerticalAlignment = alignment;
392 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
394 mImpl->RequestRelayout();
398 VerticalAlignment::Type Controller::GetVerticalAlignment() const
400 return mImpl->mModel->mVerticalAlignment;
403 void Controller::SetLineWrapMode( Text::LineWrap::Mode lineWrapMode )
405 if( lineWrapMode != mImpl->mModel->mLineWrapMode )
407 // Set the text wrap mode.
408 mImpl->mModel->mLineWrapMode = lineWrapMode;
411 // Update Text layout for applying wrap mode
412 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
417 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
418 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
419 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
422 mImpl->RequestRelayout();
426 Text::LineWrap::Mode Controller::GetLineWrapMode() const
428 return mImpl->mModel->mLineWrapMode;
431 void Controller::SetTextElideEnabled( bool enabled )
433 mImpl->mModel->mElideEnabled = enabled;
436 bool Controller::IsTextElideEnabled() const
438 return mImpl->mModel->mElideEnabled;
441 void Controller::SetPlaceholderTextElideEnabled( bool enabled )
443 mImpl->mEventData->mIsPlaceholderElideEnabled = enabled;
444 mImpl->mEventData->mPlaceholderEllipsisFlag = true;
446 // Update placeholder if there is no text
447 if( mImpl->IsShowingPlaceholderText() ||
448 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
450 ShowPlaceholderText();
454 bool Controller::IsPlaceholderTextElideEnabled() const
456 return mImpl->mEventData->mIsPlaceholderElideEnabled;
459 void Controller::SetSelectionEnabled( bool enabled )
461 mImpl->mEventData->mSelectionEnabled = enabled;
464 bool Controller::IsSelectionEnabled() const
466 return mImpl->mEventData->mSelectionEnabled;
469 void Controller::SetShiftSelectionEnabled( bool enabled )
471 mImpl->mEventData->mShiftSelectionFlag = enabled;
474 bool Controller::IsShiftSelectionEnabled() const
476 return mImpl->mEventData->mShiftSelectionFlag;
481 void Controller::SetText( const std::string& text )
483 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" );
485 // Reset keyboard as text changed
486 mImpl->ResetImfManager();
488 // Remove the previously set text and style.
494 CharacterIndex lastCursorIndex = 0u;
496 if( NULL != mImpl->mEventData )
498 // If popup shown then hide it by switching to Editing state
499 if( ( EventData::SELECTING == mImpl->mEventData->mState ) ||
500 ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
501 ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) ||
502 ( EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState ) )
504 mImpl->ChangeState( EventData::EDITING );
510 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mTextColor );
512 MarkupProcessData markupProcessData( mImpl->mModel->mLogicalModel->mColorRuns,
513 mImpl->mModel->mLogicalModel->mFontDescriptionRuns );
515 Length textSize = 0u;
516 const uint8_t* utf8 = NULL;
517 if( mImpl->mMarkupProcessorEnabled )
519 ProcessMarkupString( text, markupProcessData );
520 textSize = markupProcessData.markupProcessedText.size();
522 // This is a bit horrible but std::string returns a (signed) char*
523 utf8 = reinterpret_cast<const uint8_t*>( markupProcessData.markupProcessedText.c_str() );
527 textSize = text.size();
529 // This is a bit horrible but std::string returns a (signed) char*
530 utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
533 // Convert text into UTF-32
534 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
535 utf32Characters.Resize( textSize );
537 // Transform a text array encoded in utf8 into an array encoded in utf32.
538 // It returns the actual number of characters.
539 Length characterCount = Utf8ToUtf32( utf8, textSize, utf32Characters.Begin() );
540 utf32Characters.Resize( characterCount );
542 DALI_ASSERT_DEBUG( textSize >= characterCount && "Invalid UTF32 conversion length" );
543 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", this, textSize, mImpl->mModel->mLogicalModel->mText.Count() );
545 // The characters to be added.
546 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
548 // To reset the cursor position
549 lastCursorIndex = characterCount;
551 // Update the rest of the model during size negotiation
552 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
554 // The natural size needs to be re-calculated.
555 mImpl->mRecalculateNaturalSize = true;
557 // Apply modifications to the model
558 mImpl->mOperationsPending = ALL_OPERATIONS;
562 ShowPlaceholderText();
565 // Resets the cursor position.
566 ResetCursorPosition( lastCursorIndex );
568 // Scrolls the text to make the cursor visible.
569 ResetScrollPosition();
571 mImpl->RequestRelayout();
573 if( NULL != mImpl->mEventData )
575 // Cancel previously queued events
576 mImpl->mEventData->mEventQueue.clear();
579 // Do this last since it provides callbacks into application code.
580 if( NULL != mImpl->mEditableControlInterface )
582 mImpl->mEditableControlInterface->TextChanged();
586 void Controller::GetText( std::string& text ) const
588 if( !mImpl->IsShowingPlaceholderText() )
590 // Retrieves the text string.
591 mImpl->GetText( 0u, text );
595 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this );
599 void Controller::SetPlaceholderText( PlaceholderType type, const std::string& text )
601 if( NULL != mImpl->mEventData )
603 if( PLACEHOLDER_TYPE_INACTIVE == type )
605 mImpl->mEventData->mPlaceholderTextInactive = text;
609 mImpl->mEventData->mPlaceholderTextActive = text;
612 // Update placeholder if there is no text
613 if( mImpl->IsShowingPlaceholderText() ||
614 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
616 ShowPlaceholderText();
621 void Controller::GetPlaceholderText( PlaceholderType type, std::string& text ) const
623 if( NULL != mImpl->mEventData )
625 if( PLACEHOLDER_TYPE_INACTIVE == type )
627 text = mImpl->mEventData->mPlaceholderTextInactive;
631 text = mImpl->mEventData->mPlaceholderTextActive;
636 void Controller::UpdateAfterFontChange( const std::string& newDefaultFont )
638 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
640 if( !mImpl->mFontDefaults->familyDefined ) // If user defined font then should not update when system font changes
642 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
643 mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
647 mImpl->RequestRelayout();
651 // public : Default style & Input style
653 void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
655 if( NULL == mImpl->mFontDefaults )
657 mImpl->mFontDefaults = new FontDefaults();
660 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
661 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
662 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
664 // Clear the font-specific data
667 mImpl->RequestRelayout();
670 const std::string& Controller::GetDefaultFontFamily() const
672 if( NULL != mImpl->mFontDefaults )
674 return mImpl->mFontDefaults->mFontDescription.family;
680 void Controller::SetPlaceholderFontFamily( const std::string& placeholderTextFontFamily )
682 if( NULL != mImpl->mEventData )
684 if( NULL == mImpl->mEventData->mPlaceholderFont )
686 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
689 mImpl->mEventData->mPlaceholderFont->mFontDescription.family = placeholderTextFontFamily;
690 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetPlaceholderFontFamily %s\n", placeholderTextFontFamily.c_str());
691 mImpl->mEventData->mPlaceholderFont->familyDefined = !placeholderTextFontFamily.empty();
693 mImpl->RequestRelayout();
697 const std::string& Controller::GetPlaceholderFontFamily() const
699 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
701 return mImpl->mEventData->mPlaceholderFont->mFontDescription.family;
707 void Controller::SetDefaultFontWeight( FontWeight weight )
709 if( NULL == mImpl->mFontDefaults )
711 mImpl->mFontDefaults = new FontDefaults();
714 mImpl->mFontDefaults->mFontDescription.weight = weight;
715 mImpl->mFontDefaults->weightDefined = true;
717 // Clear the font-specific data
720 mImpl->RequestRelayout();
723 bool Controller::IsDefaultFontWeightDefined() const
725 if( NULL != mImpl->mFontDefaults )
727 return mImpl->mFontDefaults->weightDefined;
733 FontWeight Controller::GetDefaultFontWeight() const
735 if( NULL != mImpl->mFontDefaults )
737 return mImpl->mFontDefaults->mFontDescription.weight;
740 return TextAbstraction::FontWeight::NORMAL;
743 void Controller::SetPlaceholderTextFontWeight( FontWeight weight )
745 if( NULL != mImpl->mEventData )
747 if( NULL == mImpl->mEventData->mPlaceholderFont )
749 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
752 mImpl->mEventData->mPlaceholderFont->mFontDescription.weight = weight;
753 mImpl->mEventData->mPlaceholderFont->weightDefined = true;
755 mImpl->RequestRelayout();
759 bool Controller::IsPlaceholderTextFontWeightDefined() const
761 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
763 return mImpl->mEventData->mPlaceholderFont->weightDefined;
768 FontWeight Controller::GetPlaceholderTextFontWeight() const
770 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
772 return mImpl->mEventData->mPlaceholderFont->mFontDescription.weight;
775 return TextAbstraction::FontWeight::NORMAL;
778 void Controller::SetDefaultFontWidth( FontWidth width )
780 if( NULL == mImpl->mFontDefaults )
782 mImpl->mFontDefaults = new FontDefaults();
785 mImpl->mFontDefaults->mFontDescription.width = width;
786 mImpl->mFontDefaults->widthDefined = true;
788 // Clear the font-specific data
791 mImpl->RequestRelayout();
794 bool Controller::IsDefaultFontWidthDefined() const
796 if( NULL != mImpl->mFontDefaults )
798 return mImpl->mFontDefaults->widthDefined;
804 FontWidth Controller::GetDefaultFontWidth() const
806 if( NULL != mImpl->mFontDefaults )
808 return mImpl->mFontDefaults->mFontDescription.width;
811 return TextAbstraction::FontWidth::NORMAL;
814 void Controller::SetPlaceholderTextFontWidth( FontWidth width )
816 if( NULL != mImpl->mEventData )
818 if( NULL == mImpl->mEventData->mPlaceholderFont )
820 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
823 mImpl->mEventData->mPlaceholderFont->mFontDescription.width = width;
824 mImpl->mEventData->mPlaceholderFont->widthDefined = true;
826 mImpl->RequestRelayout();
830 bool Controller::IsPlaceholderTextFontWidthDefined() const
832 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
834 return mImpl->mEventData->mPlaceholderFont->widthDefined;
839 FontWidth Controller::GetPlaceholderTextFontWidth() const
841 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
843 return mImpl->mEventData->mPlaceholderFont->mFontDescription.width;
846 return TextAbstraction::FontWidth::NORMAL;
849 void Controller::SetDefaultFontSlant( FontSlant slant )
851 if( NULL == mImpl->mFontDefaults )
853 mImpl->mFontDefaults = new FontDefaults();
856 mImpl->mFontDefaults->mFontDescription.slant = slant;
857 mImpl->mFontDefaults->slantDefined = true;
859 // Clear the font-specific data
862 mImpl->RequestRelayout();
865 bool Controller::IsDefaultFontSlantDefined() const
867 if( NULL != mImpl->mFontDefaults )
869 return mImpl->mFontDefaults->slantDefined;
874 FontSlant Controller::GetDefaultFontSlant() const
876 if( NULL != mImpl->mFontDefaults )
878 return mImpl->mFontDefaults->mFontDescription.slant;
881 return TextAbstraction::FontSlant::NORMAL;
884 void Controller::SetPlaceholderTextFontSlant( FontSlant slant )
886 if( NULL != mImpl->mEventData )
888 if( NULL == mImpl->mEventData->mPlaceholderFont )
890 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
893 mImpl->mEventData->mPlaceholderFont->mFontDescription.slant = slant;
894 mImpl->mEventData->mPlaceholderFont->slantDefined = true;
896 mImpl->RequestRelayout();
900 bool Controller::IsPlaceholderTextFontSlantDefined() const
902 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
904 return mImpl->mEventData->mPlaceholderFont->slantDefined;
909 FontSlant Controller::GetPlaceholderTextFontSlant() const
911 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
913 return mImpl->mEventData->mPlaceholderFont->mFontDescription.slant;
916 return TextAbstraction::FontSlant::NORMAL;
919 void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
921 if( NULL == mImpl->mFontDefaults )
923 mImpl->mFontDefaults = new FontDefaults();
930 mImpl->mFontDefaults->mDefaultPointSize = fontSize;
931 mImpl->mFontDefaults->sizeDefined = true;
936 // Point size = Pixel size * 72.f / DPI
937 unsigned int horizontalDpi = 0u;
938 unsigned int verticalDpi = 0u;
939 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
940 fontClient.GetDpi( horizontalDpi, verticalDpi );
942 mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
943 mImpl->mFontDefaults->sizeDefined = true;
948 // Clear the font-specific data
951 mImpl->RequestRelayout();
954 float Controller::GetDefaultFontSize( FontSizeType type ) const
957 if( NULL != mImpl->mFontDefaults )
963 value = mImpl->mFontDefaults->mDefaultPointSize;
968 // Pixel size = Point size * DPI / 72.f
969 unsigned int horizontalDpi = 0u;
970 unsigned int verticalDpi = 0u;
971 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
972 fontClient.GetDpi( horizontalDpi, verticalDpi );
974 value = mImpl->mFontDefaults->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
984 void Controller::SetPlaceholderTextFontSize( float fontSize, FontSizeType type )
986 if( NULL != mImpl->mEventData )
988 if( NULL == mImpl->mEventData->mPlaceholderFont )
990 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
997 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = fontSize;
998 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
999 mImpl->mEventData->mIsPlaceholderPixelSize = false; // Font size flag
1004 // Point size = Pixel size * 72.f / DPI
1005 unsigned int horizontalDpi = 0u;
1006 unsigned int verticalDpi = 0u;
1007 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1008 fontClient.GetDpi( horizontalDpi, verticalDpi );
1010 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
1011 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1012 mImpl->mEventData->mIsPlaceholderPixelSize = true; // Font size flag
1017 mImpl->RequestRelayout();
1021 float Controller::GetPlaceholderTextFontSize( FontSizeType type ) const
1024 if( NULL != mImpl->mEventData )
1030 if( NULL != mImpl->mEventData->mPlaceholderFont )
1032 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize;
1036 // If the placeholder text font size is not set, then return the default font size.
1037 value = GetDefaultFontSize( POINT_SIZE );
1043 if( NULL != mImpl->mEventData->mPlaceholderFont )
1045 // Pixel size = Point size * DPI / 72.f
1046 unsigned int horizontalDpi = 0u;
1047 unsigned int verticalDpi = 0u;
1048 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1049 fontClient.GetDpi( horizontalDpi, verticalDpi );
1051 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1055 // If the placeholder text font size is not set, then return the default font size.
1056 value = GetDefaultFontSize( PIXEL_SIZE );
1067 void Controller::SetDefaultColor( const Vector4& color )
1069 mImpl->mTextColor = color;
1071 if( !mImpl->IsShowingPlaceholderText() )
1073 mImpl->mModel->mVisualModel->SetTextColor( color );
1075 mImpl->RequestRelayout();
1079 const Vector4& Controller::GetDefaultColor() const
1081 return mImpl->mTextColor;
1084 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
1086 if( NULL != mImpl->mEventData )
1088 mImpl->mEventData->mPlaceholderTextColor = textColor;
1091 if( mImpl->IsShowingPlaceholderText() )
1093 mImpl->mModel->mVisualModel->SetTextColor( textColor );
1094 mImpl->RequestRelayout();
1098 const Vector4& Controller::GetPlaceholderTextColor() const
1100 if( NULL != mImpl->mEventData )
1102 return mImpl->mEventData->mPlaceholderTextColor;
1105 return Color::BLACK;
1108 void Controller::SetShadowOffset( const Vector2& shadowOffset )
1110 mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
1112 mImpl->RequestRelayout();
1115 const Vector2& Controller::GetShadowOffset() const
1117 return mImpl->mModel->mVisualModel->GetShadowOffset();
1120 void Controller::SetShadowColor( const Vector4& shadowColor )
1122 mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
1124 mImpl->RequestRelayout();
1127 const Vector4& Controller::GetShadowColor() const
1129 return mImpl->mModel->mVisualModel->GetShadowColor();
1132 void Controller::SetShadowBlurRadius( const float& shadowBlurRadius )
1134 if ( fabsf( GetShadowBlurRadius() - shadowBlurRadius ) > Math::MACHINE_EPSILON_1 )
1136 mImpl->mModel->mVisualModel->SetShadowBlurRadius( shadowBlurRadius );
1138 mImpl->RequestRelayout();
1142 const float& Controller::GetShadowBlurRadius() const
1144 return mImpl->mModel->mVisualModel->GetShadowBlurRadius();
1147 void Controller::SetUnderlineColor( const Vector4& color )
1149 mImpl->mModel->mVisualModel->SetUnderlineColor( color );
1151 mImpl->RequestRelayout();
1154 const Vector4& Controller::GetUnderlineColor() const
1156 return mImpl->mModel->mVisualModel->GetUnderlineColor();
1159 void Controller::SetUnderlineEnabled( bool enabled )
1161 mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
1163 mImpl->RequestRelayout();
1166 bool Controller::IsUnderlineEnabled() const
1168 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
1171 void Controller::SetUnderlineHeight( float height )
1173 mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
1175 mImpl->RequestRelayout();
1178 float Controller::GetUnderlineHeight() const
1180 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
1183 void Controller::SetOutlineColor( const Vector4& color )
1185 mImpl->mModel->mVisualModel->SetOutlineColor( color );
1187 mImpl->RequestRelayout();
1190 const Vector4& Controller::GetOutlineColor() const
1192 return mImpl->mModel->mVisualModel->GetOutlineColor();
1195 void Controller::SetOutlineWidth( unsigned int width )
1197 mImpl->mModel->mVisualModel->SetOutlineWidth( width );
1199 mImpl->RequestRelayout();
1202 unsigned int Controller::GetOutlineWidth() const
1204 return mImpl->mModel->mVisualModel->GetOutlineWidth();
1207 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
1209 if( NULL == mImpl->mEmbossDefaults )
1211 mImpl->mEmbossDefaults = new EmbossDefaults();
1214 mImpl->mEmbossDefaults->properties = embossProperties;
1217 const std::string& Controller::GetDefaultEmbossProperties() const
1219 if( NULL != mImpl->mEmbossDefaults )
1221 return mImpl->mEmbossDefaults->properties;
1224 return EMPTY_STRING;
1227 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
1229 if( NULL == mImpl->mOutlineDefaults )
1231 mImpl->mOutlineDefaults = new OutlineDefaults();
1234 mImpl->mOutlineDefaults->properties = outlineProperties;
1237 const std::string& Controller::GetDefaultOutlineProperties() const
1239 if( NULL != mImpl->mOutlineDefaults )
1241 return mImpl->mOutlineDefaults->properties;
1244 return EMPTY_STRING;
1247 bool Controller::SetDefaultLineSpacing( float lineSpacing )
1249 if( std::abs(lineSpacing - mImpl->mLayoutEngine.GetDefaultLineSpacing()) > Math::MACHINE_EPSILON_1000 )
1251 mImpl->mLayoutEngine.SetDefaultLineSpacing(lineSpacing);
1252 mImpl->mRecalculateNaturalSize = true;
1258 float Controller::GetDefaultLineSpacing() const
1260 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
1263 void Controller::SetInputColor( const Vector4& color )
1265 if( NULL != mImpl->mEventData )
1267 mImpl->mEventData->mInputStyle.textColor = color;
1268 mImpl->mEventData->mInputStyle.isDefaultColor = false;
1270 if( EventData::SELECTING == mImpl->mEventData->mState )
1272 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
1274 // Get start and end position of selection
1275 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
1276 const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
1278 // Add the color run.
1279 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1280 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
1282 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
1283 colorRun.color = color;
1284 colorRun.characterRun.characterIndex = startOfSelectedText;
1285 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1287 // Request to relayout.
1288 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1289 mImpl->RequestRelayout();
1291 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1292 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1293 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1298 const Vector4& Controller::GetInputColor() const
1300 if( NULL != mImpl->mEventData )
1302 return mImpl->mEventData->mInputStyle.textColor;
1305 // Return the default text's color if there is no EventData.
1306 return mImpl->mTextColor;
1310 void Controller::SetInputFontFamily( const std::string& fontFamily )
1312 if( NULL != mImpl->mEventData )
1314 mImpl->mEventData->mInputStyle.familyName = fontFamily;
1315 mImpl->mEventData->mInputStyle.isFamilyDefined = true;
1317 if( EventData::SELECTING == mImpl->mEventData->mState )
1319 CharacterIndex startOfSelectedText = 0u;
1320 Length lengthOfSelectedText = 0u;
1321 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1322 mImpl->mModel->mLogicalModel,
1323 startOfSelectedText,
1324 lengthOfSelectedText );
1326 fontDescriptionRun.familyLength = fontFamily.size();
1327 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
1328 memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength );
1329 fontDescriptionRun.familyDefined = true;
1331 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
1333 // Request to relayout.
1334 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1339 UPDATE_LAYOUT_SIZE |
1342 mImpl->mRecalculateNaturalSize = true;
1343 mImpl->RequestRelayout();
1345 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1346 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1347 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1349 // As the font changes, recalculate the handle positions is needed.
1350 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1351 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1352 mImpl->mEventData->mUpdateHighlightBox = true;
1353 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1358 const std::string& Controller::GetInputFontFamily() const
1360 if( NULL != mImpl->mEventData )
1362 return mImpl->mEventData->mInputStyle.familyName;
1365 // Return the default font's family if there is no EventData.
1366 return GetDefaultFontFamily();
1369 void Controller::SetInputFontWeight( FontWeight weight )
1371 if( NULL != mImpl->mEventData )
1373 mImpl->mEventData->mInputStyle.weight = weight;
1374 mImpl->mEventData->mInputStyle.isWeightDefined = true;
1376 if( EventData::SELECTING == mImpl->mEventData->mState )
1378 CharacterIndex startOfSelectedText = 0u;
1379 Length lengthOfSelectedText = 0u;
1380 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1381 mImpl->mModel->mLogicalModel,
1382 startOfSelectedText,
1383 lengthOfSelectedText );
1385 fontDescriptionRun.weight = weight;
1386 fontDescriptionRun.weightDefined = true;
1388 // Request to relayout.
1389 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1394 UPDATE_LAYOUT_SIZE |
1397 mImpl->mRecalculateNaturalSize = true;
1398 mImpl->RequestRelayout();
1400 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1401 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1402 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1404 // As the font might change, recalculate the handle positions is needed.
1405 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1406 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1407 mImpl->mEventData->mUpdateHighlightBox = true;
1408 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1413 bool Controller::IsInputFontWeightDefined() const
1415 bool defined = false;
1417 if( NULL != mImpl->mEventData )
1419 defined = mImpl->mEventData->mInputStyle.isWeightDefined;
1425 FontWeight Controller::GetInputFontWeight() const
1427 if( NULL != mImpl->mEventData )
1429 return mImpl->mEventData->mInputStyle.weight;
1432 return GetDefaultFontWeight();
1435 void Controller::SetInputFontWidth( FontWidth width )
1437 if( NULL != mImpl->mEventData )
1439 mImpl->mEventData->mInputStyle.width = width;
1440 mImpl->mEventData->mInputStyle.isWidthDefined = true;
1442 if( EventData::SELECTING == mImpl->mEventData->mState )
1444 CharacterIndex startOfSelectedText = 0u;
1445 Length lengthOfSelectedText = 0u;
1446 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1447 mImpl->mModel->mLogicalModel,
1448 startOfSelectedText,
1449 lengthOfSelectedText );
1451 fontDescriptionRun.width = width;
1452 fontDescriptionRun.widthDefined = true;
1454 // Request to relayout.
1455 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1460 UPDATE_LAYOUT_SIZE |
1463 mImpl->mRecalculateNaturalSize = true;
1464 mImpl->RequestRelayout();
1466 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1467 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1468 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1470 // As the font might change, recalculate the handle positions is needed.
1471 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1472 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1473 mImpl->mEventData->mUpdateHighlightBox = true;
1474 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1479 bool Controller::IsInputFontWidthDefined() const
1481 bool defined = false;
1483 if( NULL != mImpl->mEventData )
1485 defined = mImpl->mEventData->mInputStyle.isWidthDefined;
1491 FontWidth Controller::GetInputFontWidth() const
1493 if( NULL != mImpl->mEventData )
1495 return mImpl->mEventData->mInputStyle.width;
1498 return GetDefaultFontWidth();
1501 void Controller::SetInputFontSlant( FontSlant slant )
1503 if( NULL != mImpl->mEventData )
1505 mImpl->mEventData->mInputStyle.slant = slant;
1506 mImpl->mEventData->mInputStyle.isSlantDefined = true;
1508 if( EventData::SELECTING == mImpl->mEventData->mState )
1510 CharacterIndex startOfSelectedText = 0u;
1511 Length lengthOfSelectedText = 0u;
1512 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1513 mImpl->mModel->mLogicalModel,
1514 startOfSelectedText,
1515 lengthOfSelectedText );
1517 fontDescriptionRun.slant = slant;
1518 fontDescriptionRun.slantDefined = true;
1520 // Request to relayout.
1521 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1526 UPDATE_LAYOUT_SIZE |
1529 mImpl->mRecalculateNaturalSize = true;
1530 mImpl->RequestRelayout();
1532 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1533 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1534 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1536 // As the font might change, recalculate the handle positions is needed.
1537 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1538 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1539 mImpl->mEventData->mUpdateHighlightBox = true;
1540 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1545 bool Controller::IsInputFontSlantDefined() const
1547 bool defined = false;
1549 if( NULL != mImpl->mEventData )
1551 defined = mImpl->mEventData->mInputStyle.isSlantDefined;
1557 FontSlant Controller::GetInputFontSlant() const
1559 if( NULL != mImpl->mEventData )
1561 return mImpl->mEventData->mInputStyle.slant;
1564 return GetDefaultFontSlant();
1567 void Controller::SetInputFontPointSize( float size )
1569 if( NULL != mImpl->mEventData )
1571 mImpl->mEventData->mInputStyle.size = size;
1572 mImpl->mEventData->mInputStyle.isSizeDefined = true;
1574 if( EventData::SELECTING == mImpl->mEventData->mState )
1576 CharacterIndex startOfSelectedText = 0u;
1577 Length lengthOfSelectedText = 0u;
1578 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1579 mImpl->mModel->mLogicalModel,
1580 startOfSelectedText,
1581 lengthOfSelectedText );
1583 fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
1584 fontDescriptionRun.sizeDefined = true;
1586 // Request to relayout.
1587 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1592 UPDATE_LAYOUT_SIZE |
1595 mImpl->mRecalculateNaturalSize = true;
1596 mImpl->RequestRelayout();
1598 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1599 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1600 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1602 // As the font might change, recalculate the handle positions is needed.
1603 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1604 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1605 mImpl->mEventData->mUpdateHighlightBox = true;
1606 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1611 float Controller::GetInputFontPointSize() const
1613 if( NULL != mImpl->mEventData )
1615 return mImpl->mEventData->mInputStyle.size;
1618 // Return the default font's point size if there is no EventData.
1619 return GetDefaultFontSize( Text::Controller::POINT_SIZE );
1622 void Controller::SetInputLineSpacing( float lineSpacing )
1624 if( NULL != mImpl->mEventData )
1626 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1627 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1631 float Controller::GetInputLineSpacing() const
1633 if( NULL != mImpl->mEventData )
1635 return mImpl->mEventData->mInputStyle.lineSpacing;
1641 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1643 if( NULL != mImpl->mEventData )
1645 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1649 const std::string& Controller::GetInputShadowProperties() const
1651 if( NULL != mImpl->mEventData )
1653 return mImpl->mEventData->mInputStyle.shadowProperties;
1656 return EMPTY_STRING;
1659 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1661 if( NULL != mImpl->mEventData )
1663 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1667 const std::string& Controller::GetInputUnderlineProperties() const
1669 if( NULL != mImpl->mEventData )
1671 return mImpl->mEventData->mInputStyle.underlineProperties;
1674 return EMPTY_STRING;
1677 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
1679 if( NULL != mImpl->mEventData )
1681 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1685 const std::string& Controller::GetInputEmbossProperties() const
1687 if( NULL != mImpl->mEventData )
1689 return mImpl->mEventData->mInputStyle.embossProperties;
1692 return GetDefaultEmbossProperties();
1695 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
1697 if( NULL != mImpl->mEventData )
1699 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1703 const std::string& Controller::GetInputOutlineProperties() const
1705 if( NULL != mImpl->mEventData )
1707 return mImpl->mEventData->mInputStyle.outlineProperties;
1710 return GetDefaultOutlineProperties();
1713 void Controller::SetInputModePassword( bool passwordInput )
1715 if( NULL != mImpl->mEventData )
1717 mImpl->mEventData->mPasswordInput = passwordInput;
1721 bool Controller::IsInputModePassword()
1723 if( NULL != mImpl->mEventData )
1725 return mImpl->mEventData->mPasswordInput;
1730 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
1732 if( NULL != mImpl->mEventData )
1734 mImpl->mEventData->mDoubleTapAction = action;
1738 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1740 NoTextTap::Action action = NoTextTap::NO_ACTION;
1742 if( NULL != mImpl->mEventData )
1744 action = mImpl->mEventData->mDoubleTapAction;
1750 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
1752 if( NULL != mImpl->mEventData )
1754 mImpl->mEventData->mLongPressAction = action;
1758 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1760 NoTextTap::Action action = NoTextTap::NO_ACTION;
1762 if( NULL != mImpl->mEventData )
1764 action = mImpl->mEventData->mLongPressAction;
1770 bool Controller::IsUnderlineSetByString()
1772 return mImpl->mUnderlineSetByString;
1775 void Controller::UnderlineSetByString( bool setByString )
1777 mImpl->mUnderlineSetByString = setByString;
1780 bool Controller::IsShadowSetByString()
1782 return mImpl->mShadowSetByString;
1785 void Controller::ShadowSetByString( bool setByString )
1787 mImpl->mShadowSetByString = setByString;
1790 bool Controller::IsOutlineSetByString()
1792 return mImpl->mOutlineSetByString;
1795 void Controller::OutlineSetByString( bool setByString )
1797 mImpl->mOutlineSetByString = setByString;
1800 bool Controller::IsFontStyleSetByString()
1802 return mImpl->mFontStyleSetByString;
1805 void Controller::FontStyleSetByString( bool setByString )
1807 mImpl->mFontStyleSetByString = setByString;
1810 // public : Queries & retrieves.
1812 Layout::Engine& Controller::GetLayoutEngine()
1814 return mImpl->mLayoutEngine;
1817 View& Controller::GetView()
1819 return mImpl->mView;
1822 Vector3 Controller::GetNaturalSize()
1824 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
1825 Vector3 naturalSize;
1827 // Make sure the model is up-to-date before layouting
1828 ProcessModifyEvents();
1830 if( mImpl->mRecalculateNaturalSize )
1832 // Operations that can be done only once until the text changes.
1833 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1840 GET_GLYPH_METRICS );
1842 // Set the update info to relayout the whole text.
1843 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1844 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1846 // Make sure the model is up-to-date before layouting
1847 mImpl->UpdateModel( onlyOnceOperations );
1849 // Layout the text for the new width.
1850 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT | REORDER );
1852 // Store the actual control's size to restore later.
1853 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
1855 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
1856 static_cast<OperationsMask>( onlyOnceOperations |
1858 naturalSize.GetVectorXY() );
1860 // Do not do again the only once operations.
1861 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1863 // Do the size related operations again.
1864 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1867 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1869 // Stores the natural size to avoid recalculate it again
1870 // unless the text/style changes.
1871 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
1873 mImpl->mRecalculateNaturalSize = false;
1875 // Clear the update info. This info will be set the next time the text is updated.
1876 mImpl->mTextUpdateInfo.Clear();
1878 // Restore the actual control's size.
1879 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
1881 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1885 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
1887 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1890 naturalSize.x = ConvertToEven( naturalSize.x );
1891 naturalSize.y = ConvertToEven( naturalSize.y );
1896 float Controller::GetHeightForWidth( float width )
1898 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
1899 // Make sure the model is up-to-date before layouting
1900 ProcessModifyEvents();
1903 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ||
1904 mImpl->mTextUpdateInfo.mFullRelayoutNeeded ||
1905 mImpl->mTextUpdateInfo.mClearAll )
1907 // Operations that can be done only once until the text changes.
1908 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1915 GET_GLYPH_METRICS );
1917 // Set the update info to relayout the whole text.
1918 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1919 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1921 // Make sure the model is up-to-date before layouting
1922 mImpl->UpdateModel( onlyOnceOperations );
1925 // Layout the text for the new width.
1926 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
1928 // Store the actual control's width.
1929 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
1931 DoRelayout( Size( width, MAX_FLOAT ),
1932 static_cast<OperationsMask>( onlyOnceOperations |
1936 // Do not do again the only once operations.
1937 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1939 // Do the size related operations again.
1940 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1944 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1946 // Clear the update info. This info will be set the next time the text is updated.
1947 mImpl->mTextUpdateInfo.Clear();
1949 // Restore the actual control's width.
1950 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
1952 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
1956 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
1957 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
1960 return layoutSize.height;
1963 int Controller::GetLineCount( float width )
1965 GetHeightForWidth( width );
1966 int numberofLines = mImpl->mModel->GetNumberOfLines();
1967 return numberofLines;
1970 const ModelInterface* const Controller::GetTextModel() const
1972 return mImpl->mModel.Get();
1975 float Controller::GetScrollAmountByUserInput()
1977 float scrollAmount = 0.0f;
1979 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
1981 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
1982 mImpl->mEventData->mCheckScrollAmount = false;
1984 return scrollAmount;
1987 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
1989 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
1992 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
1993 layoutHeight = layout.height;
1994 scrollPosition = mImpl->mModel->mScrollPosition.y;
1995 isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
1999 void Controller::SetHiddenInputOption(const Property::Map& options )
2001 if( NULL == mImpl->mHiddenInput )
2003 mImpl->mHiddenInput = new HiddenText( this );
2005 mImpl->mHiddenInput->SetProperties(options);
2008 void Controller::GetHiddenInputOption(Property::Map& options )
2010 if( NULL != mImpl->mHiddenInput )
2012 mImpl->mHiddenInput->GetProperties(options);
2016 void Controller::SetPlaceholderProperty( const Property::Map& map )
2018 const Property::Map::SizeType count = map.Count();
2020 for( Property::Map::SizeType position = 0; position < count; ++position )
2022 KeyValuePair keyValue = map.GetKeyValue( position );
2023 Property::Key& key = keyValue.first;
2024 Property::Value& value = keyValue.second;
2026 if( key == Toolkit::Text::PlaceHolder::Property::TEXT || key == PLACEHOLDER_TEXT )
2028 std::string text = "";
2030 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
2032 else if( key == Toolkit::Text::PlaceHolder::Property::TEXT_FOCUSED || key == PLACEHOLDER_TEXT_FOCUSED )
2034 std::string text = "";
2036 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
2038 else if( key == Toolkit::Text::PlaceHolder::Property::COLOR || key == PLACEHOLDER_COLOR )
2041 value.Get( textColor );
2042 if( GetPlaceholderTextColor() != textColor )
2044 SetPlaceholderTextColor( textColor );
2047 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_FAMILY || key == PLACEHOLDER_FONT_FAMILY )
2049 std::string fontFamily = "";
2050 value.Get( fontFamily );
2051 SetPlaceholderFontFamily( fontFamily );
2053 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_STYLE || key == PLACEHOLDER_FONT_STYLE )
2055 SetFontStyleProperty( this, value, Text::FontStyle::PLACEHOLDER );
2057 else if( key == Toolkit::Text::PlaceHolder::Property::POINT_SIZE || key == PLACEHOLDER_POINT_SIZE )
2060 value.Get( pointSize );
2061 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
2063 SetPlaceholderTextFontSize( pointSize, Text::Controller::POINT_SIZE );
2066 else if( key == Toolkit::Text::PlaceHolder::Property::PIXEL_SIZE || key == PLACEHOLDER_PIXEL_SIZE )
2069 value.Get( pixelSize );
2070 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
2072 SetPlaceholderTextFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
2075 else if( key == Toolkit::Text::PlaceHolder::Property::ELLIPSIS || key == PLACEHOLDER_ELLIPSIS )
2078 value.Get( ellipsis );
2079 SetPlaceholderTextElideEnabled( ellipsis );
2084 void Controller::GetPlaceholderProperty( Property::Map& map )
2086 if( NULL != mImpl->mEventData )
2088 if( !mImpl->mEventData->mPlaceholderTextActive.empty() )
2090 map[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = mImpl->mEventData->mPlaceholderTextActive;
2092 if( !mImpl->mEventData->mPlaceholderTextInactive.empty() )
2094 map[ Text::PlaceHolder::Property::TEXT ] = mImpl->mEventData->mPlaceholderTextInactive;
2097 map[ Text::PlaceHolder::Property::COLOR ] = mImpl->mEventData->mPlaceholderTextColor;
2098 map[ Text::PlaceHolder::Property::FONT_FAMILY ] = GetPlaceholderFontFamily();
2100 Property::Value fontStyleMapGet;
2101 GetFontStyleProperty( this, fontStyleMapGet, Text::FontStyle::PLACEHOLDER );
2102 map[ Text::PlaceHolder::Property::FONT_STYLE ] = fontStyleMapGet;
2104 // Choose font size : POINT_SIZE or PIXEL_SIZE
2105 if( !mImpl->mEventData->mIsPlaceholderPixelSize )
2107 map[ Text::PlaceHolder::Property::POINT_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE );
2111 map[ Text::PlaceHolder::Property::PIXEL_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE );
2114 if( mImpl->mEventData->mPlaceholderEllipsisFlag )
2116 map[ Text::PlaceHolder::Property::ELLIPSIS ] = IsPlaceholderTextElideEnabled();
2121 Toolkit::DevelText::TextDirection::Type Controller::GetTextDirection()
2123 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
2125 return Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT;
2128 const Character character = mImpl->mModel->mLogicalModel->mText[0];
2129 Script script = TextAbstraction::GetCharacterScript( character );
2131 if( TextAbstraction::IsRightToLeftScript( script ) )
2133 return Toolkit::DevelText::TextDirection::RIGHT_TO_LEFT;
2136 return Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT;
2139 Toolkit::DevelText::VerticalLineAlignment::Type Controller::GetVerticalLineAlignment() const
2141 return mImpl->mModel->GetVerticalLineAlignment();
2144 void Controller::SetVerticalLineAlignment( Toolkit::DevelText::VerticalLineAlignment::Type alignment )
2146 mImpl->mModel->mVerticalLineAlignment = alignment;
2149 // public : Relayout.
2151 Controller::UpdateTextType Controller::Relayout( const Size& size )
2153 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
2155 UpdateTextType updateTextType = NONE_UPDATED;
2157 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
2159 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
2161 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
2162 updateTextType = MODEL_UPDATED;
2165 // Clear the update info. This info will be set the next time the text is updated.
2166 mImpl->mTextUpdateInfo.Clear();
2168 // Not worth to relayout if width or height is equal to zero.
2169 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
2171 return updateTextType;
2174 // Whether a new size has been set.
2175 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
2179 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
2181 if( ( 0 == mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd ) &&
2182 ( 0 == mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) &&
2183 ( ( mImpl->mModel->mVisualModel->mControlSize.width < Math::MACHINE_EPSILON_1000 ) || ( mImpl->mModel->mVisualModel->mControlSize.height < Math::MACHINE_EPSILON_1000 ) ) )
2185 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
2188 // Layout operations that need to be done if the size changes.
2189 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2192 UPDATE_LAYOUT_SIZE |
2194 // Set the update info to relayout the whole text.
2195 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2196 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2198 // Store the size used to layout the text.
2199 mImpl->mModel->mVisualModel->mControlSize = size;
2202 // Whether there are modify events.
2203 if( 0u != mImpl->mModifyEvents.Count() )
2205 // Style operations that need to be done if the text is modified.
2206 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2210 // Set the update info to elide the text.
2211 if( mImpl->mModel->mElideEnabled ||
2212 ( ( NULL != mImpl->mEventData ) && mImpl->mEventData->mIsPlaceholderElideEnabled ) )
2214 // Update Text layout for applying elided
2215 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2218 UPDATE_LAYOUT_SIZE |
2220 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2221 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2224 // Make sure the model is up-to-date before layouting.
2225 ProcessModifyEvents();
2226 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
2230 updated = DoRelayout( size,
2231 mImpl->mOperationsPending,
2232 layoutSize ) || updated;
2236 updateTextType = MODEL_UPDATED;
2239 // Do not re-do any operation until something changes.
2240 mImpl->mOperationsPending = NO_OPERATION;
2241 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
2243 // Whether the text control is editable
2244 const bool isEditable = NULL != mImpl->mEventData;
2246 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
2248 if( newSize && isEditable )
2250 offset = mImpl->mModel->mScrollPosition;
2253 if( !isEditable || !IsMultiLineEnabled() )
2255 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
2256 CalculateVerticalOffset( size );
2263 // If there is a new size, the scroll position needs to be clamped.
2264 mImpl->ClampHorizontalScroll( layoutSize );
2266 // Update the decorator's positions is needed if there is a new size.
2267 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
2270 // Move the cursor, grab handle etc.
2271 if( mImpl->ProcessInputEvents() )
2273 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
2277 // Clear the update info. This info will be set the next time the text is updated.
2278 mImpl->mTextUpdateInfo.Clear();
2279 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
2281 return updateTextType;
2284 void Controller::RequestRelayout()
2286 mImpl->RequestRelayout();
2289 // public : Input style change signals.
2291 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
2293 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
2296 void Controller::ProcessInputStyleChangedSignals()
2298 if( NULL == mImpl->mEventData )
2304 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
2305 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
2309 const InputStyle::Mask mask = *it;
2311 if( NULL != mImpl->mEditableControlInterface )
2313 // Emit the input style changed signal.
2314 mImpl->mEditableControlInterface->InputStyleChanged( mask );
2318 mImpl->mEventData->mInputStyleChangedQueue.Clear();
2321 // public : Text-input Event Queuing.
2323 void Controller::KeyboardFocusGainEvent()
2325 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
2327 if( NULL != mImpl->mEventData )
2329 if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
2330 ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
2332 mImpl->ChangeState( EventData::EDITING );
2333 mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
2334 mImpl->mEventData->mUpdateInputStyle = true;
2336 mImpl->NotifyImfMultiLineStatus();
2337 if( mImpl->IsShowingPlaceholderText() )
2339 // Show alternative placeholder-text when editing
2340 ShowPlaceholderText();
2343 mImpl->RequestRelayout();
2347 void Controller::KeyboardFocusLostEvent()
2349 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
2351 if( NULL != mImpl->mEventData )
2353 if( EventData::INTERRUPTED != mImpl->mEventData->mState )
2355 mImpl->ChangeState( EventData::INACTIVE );
2357 if( !mImpl->IsShowingRealText() )
2359 // Revert to regular placeholder-text when not editing
2360 ShowPlaceholderText();
2364 mImpl->RequestRelayout();
2367 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
2369 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
2371 bool textChanged = false;
2372 bool relayoutNeeded = false;
2374 if( ( NULL != mImpl->mEventData ) &&
2375 ( keyEvent.state == KeyEvent::Down ) )
2377 int keyCode = keyEvent.keyCode;
2378 const std::string& keyString = keyEvent.keyPressed;
2379 const std::string keyName = keyEvent.keyPressedName;
2381 const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
2383 // Pre-process to separate modifying events from non-modifying input events.
2386 // In some platforms arrive key events with no key code.
2390 else if( Dali::DALI_KEY_ESCAPE == keyCode || Dali::DALI_KEY_BACK == keyCode || Dali::DALI_KEY_SEARCH == keyCode )
2395 else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) ||
2396 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
2397 ( Dali::DALI_KEY_CURSOR_UP == keyCode ) ||
2398 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) )
2400 // If don't have any text, do nothing.
2401 if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
2406 uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition;
2407 uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2408 uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition );
2409 uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines();
2411 // Logic to determine whether this text control will lose focus or not.
2412 if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition ) ||
2413 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition) ||
2414 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) ||
2415 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) ||
2416 ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) ||
2417 ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) )
2422 mImpl->mEventData->mCheckScrollAmount = true;
2423 Event event( Event::CURSOR_KEY_EVENT );
2424 event.p1.mInt = keyCode;
2425 event.p2.mBool = keyEvent.IsShiftModifier();
2426 mImpl->mEventData->mEventQueue.push_back( event );
2428 // Will request for relayout.
2429 relayoutNeeded = true;
2431 else if ( Dali::DevelKey::DALI_KEY_CONTROL_LEFT == keyCode || Dali::DevelKey::DALI_KEY_CONTROL_RIGHT == keyCode )
2433 // Left or Right Control key event is received before Ctrl-C/V/X key event is received
2434 // If not handle it here, any selected text will be deleted
2439 else if ( keyEvent.IsCtrlModifier() )
2441 bool consumed = false;
2442 if (keyName == KEY_C_NAME)
2444 // Ctrl-C to copy the selected text
2445 TextPopupButtonTouched( Toolkit::TextSelectionPopup::COPY );
2448 else if (keyName == KEY_V_NAME)
2450 // Ctrl-V to paste the copied text
2451 TextPopupButtonTouched( Toolkit::TextSelectionPopup::PASTE );
2454 else if (keyName == KEY_X_NAME)
2456 // Ctrl-X to cut the selected text
2457 TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
2462 else if( ( Dali::DALI_KEY_BACKSPACE == keyCode ) ||
2463 ( Dali::DevelKey::DALI_KEY_DELETE == keyCode ) )
2465 textChanged = DeleteEvent( keyCode );
2467 // Will request for relayout.
2468 relayoutNeeded = true;
2470 else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
2471 IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
2472 IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
2474 // Power key/Menu/Home key behaviour does not allow edit mode to resume.
2475 mImpl->ChangeState( EventData::INACTIVE );
2477 // Will request for relayout.
2478 relayoutNeeded = true;
2480 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2482 else if( Dali::DALI_KEY_SHIFT_LEFT == keyCode )
2484 // DALI_KEY_SHIFT_LEFT is the key code for the Left Shift. It's sent (by the imf?) when the predictive text is enabled
2485 // and a character is typed after the type of a upper case latin character.
2490 else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
2492 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2498 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
2500 // IMF manager is no longer handling key-events
2501 mImpl->ClearPreEditFlag();
2503 InsertText( keyString, COMMIT );
2506 // Will request for relayout.
2507 relayoutNeeded = true;
2510 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
2511 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
2513 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
2514 ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
2515 ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
2517 // Should not change the state if the key is the shift send by the imf manager.
2518 // Otherwise, when the state is SELECTING the text controller can't send the right
2519 // surrounding info to the imf.
2520 mImpl->ChangeState( EventData::EDITING );
2522 // Will request for relayout.
2523 relayoutNeeded = true;
2526 if( relayoutNeeded )
2528 mImpl->RequestRelayout();
2533 ( NULL != mImpl->mEditableControlInterface ) )
2535 // Do this last since it provides callbacks into application code
2536 mImpl->mEditableControlInterface->TextChanged();
2542 void Controller::TapEvent( unsigned int tapCount, float x, float y )
2544 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
2546 if( NULL != mImpl->mEventData )
2548 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
2549 EventData::State state( mImpl->mEventData->mState );
2550 bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
2552 if( mImpl->IsClipboardVisible() )
2554 if( EventData::INACTIVE == state || EventData::EDITING == state)
2556 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2558 relayoutNeeded = true;
2560 else if( 1u == tapCount )
2562 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
2564 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
2567 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
2569 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2570 relayoutNeeded = true;
2574 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
2576 // Hide placeholder text
2580 if( EventData::INACTIVE == state )
2582 mImpl->ChangeState( EventData::EDITING );
2584 else if( !mImpl->IsClipboardEmpty() )
2586 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
2588 relayoutNeeded = true;
2591 else if( 2u == tapCount )
2593 if( mImpl->mEventData->mSelectionEnabled &&
2594 mImpl->IsShowingRealText() )
2596 relayoutNeeded = true;
2597 mImpl->mEventData->mIsLeftHandleSelected = true;
2598 mImpl->mEventData->mIsRightHandleSelected = true;
2602 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
2603 if( relayoutNeeded )
2605 Event event( Event::TAP_EVENT );
2606 event.p1.mUint = tapCount;
2607 event.p2.mFloat = x;
2608 event.p3.mFloat = y;
2609 mImpl->mEventData->mEventQueue.push_back( event );
2611 mImpl->RequestRelayout();
2615 // Reset keyboard as tap event has occurred.
2616 mImpl->ResetImfManager();
2619 void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
2621 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
2623 if( NULL != mImpl->mEventData )
2625 Event event( Event::PAN_EVENT );
2626 event.p1.mInt = state;
2627 event.p2.mFloat = displacement.x;
2628 event.p3.mFloat = displacement.y;
2629 mImpl->mEventData->mEventQueue.push_back( event );
2631 mImpl->RequestRelayout();
2635 void Controller::LongPressEvent( Gesture::State state, float x, float y )
2637 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
2639 if( ( state == Gesture::Started ) &&
2640 ( NULL != mImpl->mEventData ) )
2642 // The 1st long-press on inactive text-field is treated as tap
2643 if( EventData::INACTIVE == mImpl->mEventData->mState )
2645 mImpl->ChangeState( EventData::EDITING );
2647 Event event( Event::TAP_EVENT );
2649 event.p2.mFloat = x;
2650 event.p3.mFloat = y;
2651 mImpl->mEventData->mEventQueue.push_back( event );
2653 mImpl->RequestRelayout();
2655 else if( !mImpl->IsShowingRealText() )
2657 Event event( Event::LONG_PRESS_EVENT );
2658 event.p1.mInt = state;
2659 event.p2.mFloat = x;
2660 event.p3.mFloat = y;
2661 mImpl->mEventData->mEventQueue.push_back( event );
2662 mImpl->RequestRelayout();
2664 else if( !mImpl->IsClipboardVisible() )
2666 // Reset the imf manager to commit the pre-edit before selecting the text.
2667 mImpl->ResetImfManager();
2669 Event event( Event::LONG_PRESS_EVENT );
2670 event.p1.mInt = state;
2671 event.p2.mFloat = x;
2672 event.p3.mFloat = y;
2673 mImpl->mEventData->mEventQueue.push_back( event );
2674 mImpl->RequestRelayout();
2676 mImpl->mEventData->mIsLeftHandleSelected = true;
2677 mImpl->mEventData->mIsRightHandleSelected = true;
2682 ImfManager::ImfCallbackData Controller::OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
2684 // Whether the text needs to be relaid-out.
2685 bool requestRelayout = false;
2687 // Whether to retrieve the text and cursor position to be sent to the IMF manager.
2688 bool retrieveText = false;
2689 bool retrieveCursor = false;
2691 switch( imfEvent.eventName )
2693 case ImfManager::COMMIT:
2695 InsertText( imfEvent.predictiveString, Text::Controller::COMMIT );
2696 requestRelayout = true;
2697 retrieveCursor = true;
2700 case ImfManager::PREEDIT:
2702 InsertText( imfEvent.predictiveString, Text::Controller::PRE_EDIT );
2703 requestRelayout = true;
2704 retrieveCursor = true;
2707 case ImfManager::DELETESURROUNDING:
2709 const bool textDeleted = RemoveText( imfEvent.cursorOffset,
2710 imfEvent.numberOfChars,
2711 DONT_UPDATE_INPUT_STYLE );
2715 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2716 !mImpl->IsPlaceholderAvailable() )
2718 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2722 ShowPlaceholderText();
2724 mImpl->mEventData->mUpdateCursorPosition = true;
2725 mImpl->mEventData->mScrollAfterDelete = true;
2727 requestRelayout = true;
2731 case ImfManager::GETSURROUNDING:
2733 retrieveText = true;
2734 retrieveCursor = true;
2737 case ImfManager::PRIVATECOMMAND:
2739 // PRIVATECOMMAND event is just for getting the private command message
2740 retrieveText = true;
2741 retrieveCursor = true;
2744 case ImfManager::VOID:
2751 if( requestRelayout )
2753 mImpl->mOperationsPending = ALL_OPERATIONS;
2754 mImpl->RequestRelayout();
2758 CharacterIndex cursorPosition = 0u;
2759 Length numberOfWhiteSpaces = 0u;
2761 if( retrieveCursor )
2763 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
2765 cursorPosition = mImpl->GetLogicalCursorPosition();
2767 if( cursorPosition < numberOfWhiteSpaces )
2769 cursorPosition = 0u;
2773 cursorPosition -= numberOfWhiteSpaces;
2779 if( !mImpl->IsShowingPlaceholderText() )
2781 // Retrieves the normal text string.
2782 mImpl->GetText( numberOfWhiteSpaces, text );
2786 // When the current text is Placeholder Text, the surrounding text should be empty string.
2787 // It means DALi should send empty string ("") to IME.
2792 ImfManager::ImfCallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
2794 if( requestRelayout &&
2795 ( NULL != mImpl->mEditableControlInterface ) )
2797 // Do this last since it provides callbacks into application code
2798 mImpl->mEditableControlInterface->TextChanged();
2801 return callbackData;
2804 void Controller::PasteClipboardItemEvent()
2806 // Retrieve the clipboard contents first
2807 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
2808 std::string stringToPaste( notifier.GetContent() );
2810 // Commit the current pre-edit text; the contents of the clipboard should be appended
2811 mImpl->ResetImfManager();
2813 // Temporary disable hiding clipboard
2814 mImpl->SetClipboardHideEnable( false );
2817 PasteText( stringToPaste );
2819 mImpl->SetClipboardHideEnable( true );
2822 // protected : Inherit from Text::Decorator::ControllerInterface.
2824 void Controller::GetTargetSize( Vector2& targetSize )
2826 targetSize = mImpl->mModel->mVisualModel->mControlSize;
2829 void Controller::AddDecoration( Actor& actor, bool needsClipping )
2831 if( NULL != mImpl->mEditableControlInterface )
2833 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
2837 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
2839 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
2841 if( NULL != mImpl->mEventData )
2843 switch( handleType )
2847 Event event( Event::GRAB_HANDLE_EVENT );
2848 event.p1.mUint = state;
2849 event.p2.mFloat = x;
2850 event.p3.mFloat = y;
2852 mImpl->mEventData->mEventQueue.push_back( event );
2855 case LEFT_SELECTION_HANDLE:
2857 Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
2858 event.p1.mUint = state;
2859 event.p2.mFloat = x;
2860 event.p3.mFloat = y;
2862 mImpl->mEventData->mEventQueue.push_back( event );
2865 case RIGHT_SELECTION_HANDLE:
2867 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
2868 event.p1.mUint = state;
2869 event.p2.mFloat = x;
2870 event.p3.mFloat = y;
2872 mImpl->mEventData->mEventQueue.push_back( event );
2875 case LEFT_SELECTION_HANDLE_MARKER:
2876 case RIGHT_SELECTION_HANDLE_MARKER:
2878 // Markers do not move the handles.
2881 case HANDLE_TYPE_COUNT:
2883 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
2887 mImpl->RequestRelayout();
2891 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
2893 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
2895 if( NULL == mImpl->mEventData )
2902 case Toolkit::TextSelectionPopup::CUT:
2904 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
2905 mImpl->mOperationsPending = ALL_OPERATIONS;
2907 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2908 !mImpl->IsPlaceholderAvailable() )
2910 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2914 ShowPlaceholderText();
2917 mImpl->mEventData->mUpdateCursorPosition = true;
2918 mImpl->mEventData->mScrollAfterDelete = true;
2920 mImpl->RequestRelayout();
2922 if( NULL != mImpl->mEditableControlInterface )
2924 mImpl->mEditableControlInterface->TextChanged();
2928 case Toolkit::TextSelectionPopup::COPY:
2930 mImpl->SendSelectionToClipboard( false ); // Text not modified
2932 mImpl->mEventData->mUpdateCursorPosition = true;
2934 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
2937 case Toolkit::TextSelectionPopup::PASTE:
2939 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
2942 case Toolkit::TextSelectionPopup::SELECT:
2944 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
2946 if( mImpl->mEventData->mSelectionEnabled )
2948 // Creates a SELECT event.
2949 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
2953 case Toolkit::TextSelectionPopup::SELECT_ALL:
2955 // Creates a SELECT_ALL event
2956 SelectEvent( 0.f, 0.f, true );
2959 case Toolkit::TextSelectionPopup::CLIPBOARD:
2961 mImpl->ShowClipboard();
2964 case Toolkit::TextSelectionPopup::NONE:
2972 void Controller::DisplayTimeExpired()
2974 mImpl->mEventData->mUpdateCursorPosition = true;
2975 // Apply modifications to the model
2976 mImpl->mOperationsPending = ALL_OPERATIONS;
2978 mImpl->RequestRelayout();
2981 // private : Update.
2983 void Controller::InsertText( const std::string& text, Controller::InsertType type )
2985 bool removedPrevious = false;
2986 bool removedSelected = false;
2987 bool maxLengthReached = false;
2989 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
2991 if( NULL == mImpl->mEventData )
2996 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
2997 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
2998 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3000 // TODO: At the moment the underline runs are only for pre-edit.
3001 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
3003 // Remove the previous IMF pre-edit.
3004 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
3006 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
3007 mImpl->mEventData->mPreEditLength,
3008 DONT_UPDATE_INPUT_STYLE );
3010 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
3011 mImpl->mEventData->mPreEditLength = 0u;
3015 // Remove the previous Selection.
3016 removedSelected = RemoveSelectedText();
3020 Vector<Character> utf32Characters;
3021 Length characterCount = 0u;
3025 // Convert text into UTF-32
3026 utf32Characters.Resize( text.size() );
3028 // This is a bit horrible but std::string returns a (signed) char*
3029 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
3031 // Transform a text array encoded in utf8 into an array encoded in utf32.
3032 // It returns the actual number of characters.
3033 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
3034 utf32Characters.Resize( characterCount );
3036 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
3037 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
3040 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
3042 // The placeholder text is no longer needed
3043 if( mImpl->IsShowingPlaceholderText() )
3048 mImpl->ChangeState( EventData::EDITING );
3050 // Handle the IMF (predicitive text) state changes
3051 if( COMMIT == type )
3053 // IMF manager is no longer handling key-events
3054 mImpl->ClearPreEditFlag();
3058 if( !mImpl->mEventData->mPreEditFlag )
3060 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
3062 // Record the start of the pre-edit text
3063 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
3066 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
3067 mImpl->mEventData->mPreEditFlag = true;
3069 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3072 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
3074 // Restrict new text to fit within Maximum characters setting.
3075 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
3076 maxLengthReached = ( characterCount > maxSizeOfNewText );
3078 // The cursor position.
3079 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3081 // Update the text's style.
3083 // Updates the text style runs by adding characters.
3084 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
3086 // Get the character index from the cursor index.
3087 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
3089 // Retrieve the text's style for the given index.
3091 mImpl->RetrieveDefaultInputStyle( style );
3092 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
3094 // Whether to add a new text color run.
3095 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor );
3097 // Whether to add a new font run.
3098 const bool addFontNameRun = style.familyName != mImpl->mEventData->mInputStyle.familyName;
3099 const bool addFontWeightRun = style.weight != mImpl->mEventData->mInputStyle.weight;
3100 const bool addFontWidthRun = style.width != mImpl->mEventData->mInputStyle.width;
3101 const bool addFontSlantRun = style.slant != mImpl->mEventData->mInputStyle.slant;
3102 const bool addFontSizeRun = style.size != mImpl->mEventData->mInputStyle.size;
3107 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
3108 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
3110 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
3111 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
3112 colorRun.characterRun.characterIndex = cursorIndex;
3113 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3116 if( addFontNameRun ||
3122 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
3123 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
3125 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
3127 if( addFontNameRun )
3129 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
3130 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
3131 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
3132 fontDescriptionRun.familyDefined = true;
3134 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
3137 if( addFontWeightRun )
3139 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
3140 fontDescriptionRun.weightDefined = true;
3143 if( addFontWidthRun )
3145 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
3146 fontDescriptionRun.widthDefined = true;
3149 if( addFontSlantRun )
3151 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
3152 fontDescriptionRun.slantDefined = true;
3155 if( addFontSizeRun )
3157 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
3158 fontDescriptionRun.sizeDefined = true;
3161 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
3162 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3165 // Insert at current cursor position.
3166 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
3168 if( cursorIndex < numberOfCharactersInModel )
3170 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3174 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3177 // Mark the first paragraph to be updated.
3178 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3180 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3181 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3182 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
3183 mImpl->mTextUpdateInfo.mClearAll = true;
3187 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3188 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
3191 // Update the cursor index.
3192 cursorIndex += maxSizeOfNewText;
3194 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 );
3197 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
3198 mImpl->IsPlaceholderAvailable() )
3200 // Show place-holder if empty after removing the pre-edit text
3201 ShowPlaceholderText();
3202 mImpl->mEventData->mUpdateCursorPosition = true;
3203 mImpl->ClearPreEditFlag();
3205 else if( removedPrevious ||
3207 ( 0 != utf32Characters.Count() ) )
3209 // Queue an inserted event
3210 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
3212 mImpl->mEventData->mUpdateCursorPosition = true;
3213 if( removedSelected )
3215 mImpl->mEventData->mScrollAfterDelete = true;
3219 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3223 if( maxLengthReached )
3225 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
3227 mImpl->ResetImfManager();
3229 if( NULL != mImpl->mEditableControlInterface )
3231 // Do this last since it provides callbacks into application code
3232 mImpl->mEditableControlInterface->MaxLengthReached();
3237 void Controller::PasteText( const std::string& stringToPaste )
3239 InsertText( stringToPaste, Text::Controller::COMMIT );
3240 mImpl->ChangeState( EventData::EDITING );
3241 mImpl->RequestRelayout();
3243 if( NULL != mImpl->mEditableControlInterface )
3245 // Do this last since it provides callbacks into application code
3246 mImpl->mEditableControlInterface->TextChanged();
3250 bool Controller::RemoveText( int cursorOffset,
3251 int numberOfCharacters,
3252 UpdateInputStyleType type )
3254 bool removed = false;
3256 if( NULL == mImpl->mEventData )
3261 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
3262 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
3264 if( !mImpl->IsShowingPlaceholderText() )
3266 // Delete at current cursor position
3267 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
3268 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3270 CharacterIndex cursorIndex = 0;
3272 // Validate the cursor position & number of characters
3273 if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
3275 cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
3278 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
3280 numberOfCharacters = currentText.Count() - cursorIndex;
3283 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.
3284 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
3286 // Mark the paragraphs to be updated.
3287 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3289 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3290 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3291 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
3292 mImpl->mTextUpdateInfo.mClearAll = true;
3296 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3297 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
3300 // Update the input style and remove the text's style before removing the text.
3302 if( UPDATE_INPUT_STYLE == type )
3304 // Keep a copy of the current input style.
3305 InputStyle currentInputStyle;
3306 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
3308 // Set first the default input style.
3309 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
3311 // Update the input style.
3312 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
3314 // Compare if the input style has changed.
3315 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
3317 if( hasInputStyleChanged )
3319 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
3320 // Queue the input style changed signal.
3321 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
3325 // Updates the text style runs by removing characters. Runs with no characters are removed.
3326 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
3328 // Remove the characters.
3329 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
3330 Vector<Character>::Iterator last = first + numberOfCharacters;
3332 currentText.Erase( first, last );
3334 // Cursor position retreat
3335 oldCursorIndex = cursorIndex;
3337 mImpl->mEventData->mScrollAfterDelete = true;
3339 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
3347 bool Controller::RemoveSelectedText()
3349 bool textRemoved( false );
3351 if( EventData::SELECTING == mImpl->mEventData->mState )
3353 std::string removedString;
3354 mImpl->RetrieveSelection( removedString, true );
3356 if( !removedString.empty() )
3359 mImpl->ChangeState( EventData::EDITING );
3366 // private : Relayout.
3368 bool Controller::DoRelayout( const Size& size,
3369 OperationsMask operationsRequired,
3372 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
3373 bool viewUpdated( false );
3375 // Calculate the operations to be done.
3376 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
3378 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
3379 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
3381 // Get the current layout size.
3382 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3384 if( NO_OPERATION != ( LAYOUT & operations ) )
3386 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
3388 // Some vectors with data needed to layout and reorder may be void
3389 // after the first time the text has been laid out.
3390 // Fill the vectors again.
3392 // Calculate the number of glyphs to layout.
3393 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
3394 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
3395 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
3396 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
3398 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
3399 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
3400 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
3401 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
3403 if( 0u == totalNumberOfGlyphs )
3405 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3407 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
3410 // Nothing else to do if there is no glyphs.
3411 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
3415 const Vector<LineBreakInfo>& lineBreakInfo = mImpl->mModel->mLogicalModel->mLineBreakInfo;
3416 const Vector<WordBreakInfo>& wordBreakInfo = mImpl->mModel->mLogicalModel->mWordBreakInfo;
3417 const Vector<CharacterDirection>& characterDirection = mImpl->mModel->mLogicalModel->mCharacterDirections;
3418 const Vector<GlyphInfo>& glyphs = mImpl->mModel->mVisualModel->mGlyphs;
3419 const Vector<CharacterIndex>& glyphsToCharactersMap = mImpl->mModel->mVisualModel->mGlyphsToCharacters;
3420 const Vector<Length>& charactersPerGlyph = mImpl->mModel->mVisualModel->mCharactersPerGlyph;
3421 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
3422 const float outlineWidth = static_cast<float>( mImpl->mModel->GetOutlineWidth() );
3424 // Set the layout parameters.
3425 Layout::Parameters layoutParameters( size,
3427 lineBreakInfo.Begin(),
3428 wordBreakInfo.Begin(),
3429 ( 0u != characterDirection.Count() ) ? characterDirection.Begin() : NULL,
3431 glyphsToCharactersMap.Begin(),
3432 charactersPerGlyph.Begin(),
3433 charactersToGlyphBuffer,
3434 glyphsPerCharacterBuffer,
3435 totalNumberOfGlyphs,
3436 mImpl->mModel->mHorizontalAlignment,
3437 mImpl->mModel->mLineWrapMode,
3440 // Resize the vector of positions to have the same size than the vector of glyphs.
3441 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
3442 glyphPositions.Resize( totalNumberOfGlyphs );
3444 // Whether the last character is a new paragraph character.
3445 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
3446 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
3448 // The initial glyph and the number of glyphs to layout.
3449 layoutParameters.startGlyphIndex = startGlyphIndex;
3450 layoutParameters.numberOfGlyphs = numberOfGlyphs;
3451 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
3452 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
3454 // Update the ellipsis
3455 bool elideTextEnabled = mImpl->mModel->mElideEnabled;
3457 if( NULL != mImpl->mEventData )
3459 if( mImpl->mEventData->mPlaceholderEllipsisFlag && mImpl->IsShowingPlaceholderText() )
3461 elideTextEnabled = mImpl->mEventData->mIsPlaceholderElideEnabled;
3463 else if( EventData::INACTIVE != mImpl->mEventData->mState )
3465 // Disable ellipsis when editing
3466 elideTextEnabled = false;
3469 // Reset the scroll position in inactive state
3470 if( elideTextEnabled && ( mImpl->mEventData->mState == EventData::INACTIVE ) )
3472 ResetScrollPosition();
3476 // Update the visual model.
3478 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
3480 mImpl->mModel->mVisualModel->mLines,
3484 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
3488 layoutSize = newLayoutSize;
3490 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
3492 mImpl->mAutoScrollDirectionRTL = false;
3495 // Reorder the lines
3496 if( NO_OPERATION != ( REORDER & operations ) )
3498 Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = mImpl->mModel->mLogicalModel->mBidirectionalParagraphInfo;
3499 Vector<BidirectionalLineInfoRun>& bidirectionalLineInfo = mImpl->mModel->mLogicalModel->mBidirectionalLineInfo;
3501 // Check first if there are paragraphs with bidirectional info.
3502 if( 0u != bidirectionalInfo.Count() )
3505 const Length numberOfLines = mImpl->mModel->mVisualModel->mLines.Count();
3507 // Reorder the lines.
3508 bidirectionalLineInfo.Reserve( numberOfLines ); // Reserve because is not known yet how many lines have right to left characters.
3509 ReorderLines( bidirectionalInfo,
3511 requestedNumberOfCharacters,
3512 mImpl->mModel->mVisualModel->mLines,
3513 bidirectionalLineInfo );
3515 // Set the bidirectional info per line into the layout parameters.
3516 layoutParameters.lineBidirectionalInfoRunsBuffer = bidirectionalLineInfo.Begin();
3517 layoutParameters.numberOfBidirectionalInfoRuns = bidirectionalLineInfo.Count();
3519 // Re-layout the text. Reorder those lines with right to left characters.
3520 mImpl->mLayoutEngine.ReLayoutRightToLeftLines( layoutParameters,
3522 requestedNumberOfCharacters,
3525 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && ( numberOfLines > 0 ) )
3527 const LineRun* const firstline = mImpl->mModel->mVisualModel->mLines.Begin();
3530 mImpl->mAutoScrollDirectionRTL = firstline->direction;
3536 // Sets the layout size.
3537 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3539 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
3544 if( NO_OPERATION != ( ALIGN & operations ) )
3546 // The laid-out lines.
3547 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
3549 // Need to align with the control's size as the text may contain lines
3550 // starting either with left to right text or right to left.
3551 mImpl->mLayoutEngine.Align( size,
3553 requestedNumberOfCharacters,
3554 mImpl->mModel->mHorizontalAlignment,
3556 mImpl->mModel->mAlignmentOffset );
3560 #if defined(DEBUG_ENABLED)
3561 std::string currentText;
3562 GetText( currentText );
3563 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mAutoScrollDirectionRTL[%s] [%s]\n", this, (mImpl->mAutoScrollDirectionRTL)?"true":"false", currentText.c_str() );
3565 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
3569 void Controller::CalculateVerticalOffset( const Size& controlSize )
3571 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3573 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
3575 // Get the line height of the default font.
3576 layoutSize.height = mImpl->GetDefaultFontLineHeight();
3579 switch( mImpl->mModel->mVerticalAlignment )
3581 case VerticalAlignment::TOP:
3583 mImpl->mModel->mScrollPosition.y = 0.f;
3586 case VerticalAlignment::CENTER:
3588 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
3591 case VerticalAlignment::BOTTOM:
3593 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
3599 // private : Events.
3601 void Controller::ProcessModifyEvents()
3603 Vector<ModifyEvent>& events = mImpl->mModifyEvents;
3605 if( 0u == events.Count() )
3611 for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
3612 endIt = events.End();
3616 const ModifyEvent& event = *it;
3618 if( ModifyEvent::TEXT_REPLACED == event.type )
3620 // A (single) replace event should come first, otherwise we wasted time processing NOOP events
3621 DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
3623 TextReplacedEvent();
3625 else if( ModifyEvent::TEXT_INSERTED == event.type )
3627 TextInsertedEvent();
3629 else if( ModifyEvent::TEXT_DELETED == event.type )
3631 // Placeholder-text cannot be deleted
3632 if( !mImpl->IsShowingPlaceholderText() )
3639 if( NULL != mImpl->mEventData )
3641 // When the text is being modified, delay cursor blinking
3642 mImpl->mEventData->mDecorator->DelayCursorBlink();
3644 // Update selection position after modifying the text
3645 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
3646 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
3649 // Discard temporary text
3653 void Controller::TextReplacedEvent()
3655 // The natural size needs to be re-calculated.
3656 mImpl->mRecalculateNaturalSize = true;
3658 // Apply modifications to the model
3659 mImpl->mOperationsPending = ALL_OPERATIONS;
3662 void Controller::TextInsertedEvent()
3664 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
3666 if( NULL == mImpl->mEventData )
3671 mImpl->mEventData->mCheckScrollAmount = true;
3673 // The natural size needs to be re-calculated.
3674 mImpl->mRecalculateNaturalSize = true;
3676 // Apply modifications to the model; TODO - Optimize this
3677 mImpl->mOperationsPending = ALL_OPERATIONS;
3680 void Controller::TextDeletedEvent()
3682 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
3684 if( NULL == mImpl->mEventData )
3689 mImpl->mEventData->mCheckScrollAmount = true;
3691 // The natural size needs to be re-calculated.
3692 mImpl->mRecalculateNaturalSize = true;
3694 // Apply modifications to the model; TODO - Optimize this
3695 mImpl->mOperationsPending = ALL_OPERATIONS;
3698 void Controller::SelectEvent( float x, float y, bool selectAll )
3700 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
3702 if( NULL != mImpl->mEventData )
3706 Event event( Event::SELECT_ALL );
3707 mImpl->mEventData->mEventQueue.push_back( event );
3711 Event event( Event::SELECT );
3712 event.p2.mFloat = x;
3713 event.p3.mFloat = y;
3714 mImpl->mEventData->mEventQueue.push_back( event );
3717 mImpl->mEventData->mCheckScrollAmount = true;
3718 mImpl->mEventData->mIsLeftHandleSelected = true;
3719 mImpl->mEventData->mIsRightHandleSelected = true;
3720 mImpl->RequestRelayout();
3724 bool Controller::DeleteEvent( int keyCode )
3726 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p KeyCode : %d \n", this, keyCode );
3728 bool removed = false;
3730 if( NULL == mImpl->mEventData )
3735 // IMF manager is no longer handling key-events
3736 mImpl->ClearPreEditFlag();
3738 if( EventData::SELECTING == mImpl->mEventData->mState )
3740 removed = RemoveSelectedText();
3742 else if( ( mImpl->mEventData->mPrimaryCursorPosition > 0 ) && ( keyCode == Dali::DALI_KEY_BACKSPACE) )
3744 // Remove the character before the current cursor position
3745 removed = RemoveText( -1,
3747 UPDATE_INPUT_STYLE );
3749 else if( keyCode == Dali::DevelKey::DALI_KEY_DELETE )
3751 // Remove the character after the current cursor position
3752 removed = RemoveText( 0,
3754 UPDATE_INPUT_STYLE );
3759 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3760 !mImpl->IsPlaceholderAvailable() )
3762 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3766 ShowPlaceholderText();
3768 mImpl->mEventData->mUpdateCursorPosition = true;
3769 mImpl->mEventData->mScrollAfterDelete = true;
3775 // private : Helpers.
3777 void Controller::ResetText()
3780 mImpl->mModel->mLogicalModel->mText.Clear();
3782 // We have cleared everything including the placeholder-text
3783 mImpl->PlaceholderCleared();
3785 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3786 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3787 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
3789 // Clear any previous text.
3790 mImpl->mTextUpdateInfo.mClearAll = true;
3792 // The natural size needs to be re-calculated.
3793 mImpl->mRecalculateNaturalSize = true;
3795 // Apply modifications to the model
3796 mImpl->mOperationsPending = ALL_OPERATIONS;
3799 void Controller::ShowPlaceholderText()
3801 if( mImpl->IsPlaceholderAvailable() )
3803 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
3805 if( NULL == mImpl->mEventData )
3810 mImpl->mEventData->mIsShowingPlaceholderText = true;
3812 // Disable handles when showing place-holder text
3813 mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
3814 mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
3815 mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
3817 const char* text( NULL );
3820 // TODO - Switch Placeholder text when changing state
3821 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
3822 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
3824 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
3825 size = mImpl->mEventData->mPlaceholderTextActive.size();
3829 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
3830 size = mImpl->mEventData->mPlaceholderTextInactive.size();
3833 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3834 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3836 // Reset model for showing placeholder.
3837 mImpl->mModel->mLogicalModel->mText.Clear();
3838 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
3840 // Convert text into UTF-32
3841 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
3842 utf32Characters.Resize( size );
3844 // This is a bit horrible but std::string returns a (signed) char*
3845 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
3847 // Transform a text array encoded in utf8 into an array encoded in utf32.
3848 // It returns the actual number of characters.
3849 const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
3850 utf32Characters.Resize( characterCount );
3852 // The characters to be added.
3853 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
3855 // Reset the cursor position
3856 mImpl->mEventData->mPrimaryCursorPosition = 0;
3858 // The natural size needs to be re-calculated.
3859 mImpl->mRecalculateNaturalSize = true;
3861 // Apply modifications to the model
3862 mImpl->mOperationsPending = ALL_OPERATIONS;
3864 // Update the rest of the model during size negotiation
3865 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
3869 void Controller::ClearFontData()
3871 if( mImpl->mFontDefaults )
3873 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
3876 // Set flags to update the model.
3877 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3878 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3879 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
3881 mImpl->mTextUpdateInfo.mClearAll = true;
3882 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
3883 mImpl->mRecalculateNaturalSize = true;
3885 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
3891 UPDATE_LAYOUT_SIZE |
3896 void Controller::ClearStyleData()
3898 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
3899 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
3902 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
3904 // Reset the cursor position
3905 if( NULL != mImpl->mEventData )
3907 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
3909 // Update the cursor if it's in editing mode.
3910 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
3912 mImpl->mEventData->mUpdateCursorPosition = true;
3917 void Controller::ResetScrollPosition()
3919 if( NULL != mImpl->mEventData )
3921 // Reset the scroll position.
3922 mImpl->mModel->mScrollPosition = Vector2::ZERO;
3923 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3927 void Controller::SetControlInterface( ControlInterface* controlInterface )
3929 mImpl->mControlInterface = controlInterface;
3932 bool Controller::ShouldClearFocusOnEscape() const
3934 return mImpl->mShouldClearFocusOnEscape;
3937 // private : Private contructors & copy operator.
3939 Controller::Controller()
3942 mImpl = new Controller::Impl( NULL, NULL );
3945 Controller::Controller( ControlInterface* controlInterface )
3947 mImpl = new Controller::Impl( controlInterface, NULL );
3950 Controller::Controller( ControlInterface* controlInterface,
3951 EditableControlInterface* editableControlInterface )
3953 mImpl = new Controller::Impl( controlInterface,
3954 editableControlInterface );
3957 // The copy constructor and operator are left unimplemented.
3959 // protected : Destructor.
3961 Controller::~Controller()
3968 } // namespace Toolkit