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 char * const PLACEHOLDER_TEXT = "text";
53 const char * const PLACEHOLDER_TEXT_FOCUSED = "textFocused";
54 const char * const PLACEHOLDER_COLOR = "color";
55 const char * const PLACEHOLDER_FONT_FAMILY = "fontFamily";
56 const char * const PLACEHOLDER_FONT_STYLE = "fontStyle";
57 const char * const PLACEHOLDER_POINT_SIZE = "pointSize";
58 const char * const PLACEHOLDER_PIXEL_SIZE = "pixelSize";
59 const char * const PLACEHOLDER_ELLIPSIS = "ellipsis";
61 float ConvertToEven( float value )
63 int intValue(static_cast<int>( value ));
64 return static_cast<float>(intValue % 2 == 0) ? intValue : (intValue + 1);
79 * @brief Adds a new font description run for the selected text.
81 * The new font parameters are added after the call to this method.
83 * @param[in] eventData The event data pointer.
84 * @param[in] logicalModel The logical model where to add the new font description run.
85 * @param[out] startOfSelectedText Index to the first selected character.
86 * @param[out] lengthOfSelectedText Number of selected characters.
88 FontDescriptionRun& UpdateSelectionFontStyleRun( EventData* eventData,
89 LogicalModelPtr logicalModel,
90 CharacterIndex& startOfSelectedText,
91 Length& lengthOfSelectedText )
93 const bool handlesCrossed = eventData->mLeftSelectionPosition > eventData->mRightSelectionPosition;
95 // Get start and end position of selection
96 startOfSelectedText = handlesCrossed ? eventData->mRightSelectionPosition : eventData->mLeftSelectionPosition;
97 lengthOfSelectedText = ( handlesCrossed ? eventData->mLeftSelectionPosition : eventData->mRightSelectionPosition ) - startOfSelectedText;
100 const VectorBase::SizeType numberOfRuns = logicalModel->mFontDescriptionRuns.Count();
101 logicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
103 FontDescriptionRun& fontDescriptionRun = *( logicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
105 fontDescriptionRun.characterRun.characterIndex = startOfSelectedText;
106 fontDescriptionRun.characterRun.numberOfCharacters = lengthOfSelectedText;
108 // Recalculate the selection highlight as the metrics may have changed.
109 eventData->mUpdateLeftSelectionPosition = true;
110 eventData->mUpdateRightSelectionPosition = true;
111 eventData->mUpdateHighlightBox = true;
113 return fontDescriptionRun;
116 // public : Constructor.
118 ControllerPtr Controller::New()
120 return ControllerPtr( new Controller() );
123 ControllerPtr Controller::New( ControlInterface* controlInterface )
125 return ControllerPtr( new Controller( controlInterface ) );
128 ControllerPtr Controller::New( ControlInterface* controlInterface,
129 EditableControlInterface* editableControlInterface )
131 return ControllerPtr( new Controller( controlInterface,
132 editableControlInterface ) );
135 // public : Configure the text controller.
137 void Controller::EnableTextInput( DecoratorPtr decorator )
141 delete mImpl->mEventData;
142 mImpl->mEventData = NULL;
144 // Nothing else to do.
148 if( NULL == mImpl->mEventData )
150 mImpl->mEventData = new EventData( decorator );
154 void Controller::SetGlyphType( TextAbstraction::GlyphType glyphType )
156 // Metrics for bitmap & vector based glyphs are different
157 mImpl->mMetrics->SetGlyphType( glyphType );
159 // Clear the font-specific data
162 mImpl->RequestRelayout();
165 void Controller::SetMarkupProcessorEnabled( bool enable )
167 mImpl->mMarkupProcessorEnabled = enable;
170 //If Text was already set, call the SetText again for enabling markup
177 bool Controller::IsMarkupProcessorEnabled() const
179 return mImpl->mMarkupProcessorEnabled;
182 void Controller::SetAutoScrollEnabled( bool enable )
184 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 );
186 if( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX )
190 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled for SINGLE_LINE_BOX\n" );
191 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
201 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled Disabling autoscroll\n");
202 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
209 mImpl->mIsAutoScrollEnabled = enable;
210 mImpl->RequestRelayout();
214 DALI_LOG_WARNING( "Attempted AutoScrolling on a non SINGLE_LINE_BOX, request ignored\n" );
215 mImpl->mIsAutoScrollEnabled = false;
219 bool Controller::IsAutoScrollEnabled() const
221 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::IsAutoScrollEnabled[%s]\n", mImpl->mIsAutoScrollEnabled?"true":"false" );
223 return mImpl->mIsAutoScrollEnabled;
226 CharacterDirection Controller::GetAutoScrollDirection() const
228 return mImpl->mAutoScrollDirectionRTL;
231 float Controller::GetAutoScrollLineAlignment() const
235 if( mImpl->mModel->mVisualModel &&
236 ( 0u != mImpl->mModel->mVisualModel->mLines.Count() ) )
238 offset = ( *mImpl->mModel->mVisualModel->mLines.Begin() ).alignmentOffset;
244 void Controller::SetHorizontalScrollEnabled( bool enable )
246 if( ( NULL != mImpl->mEventData ) &&
247 mImpl->mEventData->mDecorator )
249 mImpl->mEventData->mDecorator->SetHorizontalScrollEnabled( enable );
252 bool Controller::IsHorizontalScrollEnabled() const
254 if( ( NULL != mImpl->mEventData ) &&
255 mImpl->mEventData->mDecorator )
257 return mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
263 void Controller::SetVerticalScrollEnabled( bool enable )
265 if( ( NULL != mImpl->mEventData ) &&
266 mImpl->mEventData->mDecorator )
268 if( mImpl->mEventData->mDecorator )
270 mImpl->mEventData->mDecorator->SetVerticalScrollEnabled( enable );
275 bool Controller::IsVerticalScrollEnabled() const
277 if( ( NULL != mImpl->mEventData ) &&
278 mImpl->mEventData->mDecorator )
280 return mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
286 void Controller::SetSmoothHandlePanEnabled( bool enable )
288 if( ( NULL != mImpl->mEventData ) &&
289 mImpl->mEventData->mDecorator )
291 mImpl->mEventData->mDecorator->SetSmoothHandlePanEnabled( enable );
295 bool Controller::IsSmoothHandlePanEnabled() const
297 if( ( NULL != mImpl->mEventData ) &&
298 mImpl->mEventData->mDecorator )
300 return mImpl->mEventData->mDecorator->IsSmoothHandlePanEnabled();
306 void Controller::SetMaximumNumberOfCharacters( Length maxCharacters )
308 mImpl->mMaximumNumberOfCharacters = maxCharacters;
311 int Controller::GetMaximumNumberOfCharacters()
313 return mImpl->mMaximumNumberOfCharacters;
316 void Controller::SetEnableCursorBlink( bool enable )
318 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "TextInput disabled" );
320 if( NULL != mImpl->mEventData )
322 mImpl->mEventData->mCursorBlinkEnabled = enable;
325 mImpl->mEventData->mDecorator )
327 mImpl->mEventData->mDecorator->StopCursorBlink();
332 bool Controller::GetEnableCursorBlink() const
334 if( NULL != mImpl->mEventData )
336 return mImpl->mEventData->mCursorBlinkEnabled;
342 void Controller::SetMultiLineEnabled( bool enable )
344 const Layout::Engine::Type layout = enable ? Layout::Engine::MULTI_LINE_BOX : Layout::Engine::SINGLE_LINE_BOX;
346 if( layout != mImpl->mLayoutEngine.GetLayout() )
348 // Set the layout type.
349 mImpl->mLayoutEngine.SetLayout( layout );
351 // Set the flags to redo the layout operations
352 const OperationsMask layoutOperations = static_cast<OperationsMask>( LAYOUT |
357 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | layoutOperations );
359 mImpl->RequestRelayout();
363 bool Controller::IsMultiLineEnabled() const
365 return Layout::Engine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
368 void Controller::SetHorizontalAlignment( Text::HorizontalAlignment::Type alignment )
370 if( alignment != mImpl->mModel->mHorizontalAlignment )
372 // Set the alignment.
373 mImpl->mModel->mHorizontalAlignment = alignment;
375 // Set the flag to redo the alignment operation.
376 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
378 mImpl->RequestRelayout();
382 Text::HorizontalAlignment::Type Controller::GetHorizontalAlignment() const
384 return mImpl->mModel->mHorizontalAlignment;
387 void Controller::SetVerticalAlignment( VerticalAlignment::Type alignment )
389 if( alignment != mImpl->mModel->mVerticalAlignment )
391 // Set the alignment.
392 mImpl->mModel->mVerticalAlignment = alignment;
394 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
396 mImpl->RequestRelayout();
400 VerticalAlignment::Type Controller::GetVerticalAlignment() const
402 return mImpl->mModel->mVerticalAlignment;
405 void Controller::SetLineWrapMode( Text::LineWrap::Mode lineWrapMode )
407 if( lineWrapMode != mImpl->mModel->mLineWrapMode )
409 // Set the text wrap mode.
410 mImpl->mModel->mLineWrapMode = lineWrapMode;
413 // Update Text layout for applying wrap mode
414 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
419 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
420 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
421 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
424 mImpl->RequestRelayout();
428 Text::LineWrap::Mode Controller::GetLineWrapMode() const
430 return mImpl->mModel->mLineWrapMode;
433 void Controller::SetTextElideEnabled( bool enabled )
435 mImpl->mModel->mElideEnabled = enabled;
438 bool Controller::IsTextElideEnabled() const
440 return mImpl->mModel->mElideEnabled;
443 void Controller::SetPlaceholderTextElideEnabled( bool enabled )
445 mImpl->mEventData->mIsPlaceholderElideEnabled = enabled;
446 mImpl->mEventData->mPlaceholderEllipsisFlag = true;
448 // Update placeholder if there is no text
449 if( mImpl->IsShowingPlaceholderText() ||
450 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
452 ShowPlaceholderText();
456 bool Controller::IsPlaceholderTextElideEnabled() const
458 return mImpl->mEventData->mIsPlaceholderElideEnabled;
461 void Controller::SetSelectionEnabled( bool enabled )
463 mImpl->mEventData->mSelectionEnabled = enabled;
466 bool Controller::IsSelectionEnabled() const
468 return mImpl->mEventData->mSelectionEnabled;
473 void Controller::SetText( const std::string& text )
475 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" );
477 // Reset keyboard as text changed
478 mImpl->ResetImfManager();
480 // Remove the previously set text and style.
486 CharacterIndex lastCursorIndex = 0u;
488 if( NULL != mImpl->mEventData )
490 // If popup shown then hide it by switching to Editing state
491 if( ( EventData::SELECTING == mImpl->mEventData->mState ) ||
492 ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
493 ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) ||
494 ( EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState ) )
496 mImpl->ChangeState( EventData::EDITING );
502 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mTextColor );
504 MarkupProcessData markupProcessData( mImpl->mModel->mLogicalModel->mColorRuns,
505 mImpl->mModel->mLogicalModel->mFontDescriptionRuns );
507 Length textSize = 0u;
508 const uint8_t* utf8 = NULL;
509 if( mImpl->mMarkupProcessorEnabled )
511 ProcessMarkupString( text, markupProcessData );
512 textSize = markupProcessData.markupProcessedText.size();
514 // This is a bit horrible but std::string returns a (signed) char*
515 utf8 = reinterpret_cast<const uint8_t*>( markupProcessData.markupProcessedText.c_str() );
519 textSize = text.size();
521 // This is a bit horrible but std::string returns a (signed) char*
522 utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
525 // Convert text into UTF-32
526 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
527 utf32Characters.Resize( textSize );
529 // Transform a text array encoded in utf8 into an array encoded in utf32.
530 // It returns the actual number of characters.
531 Length characterCount = Utf8ToUtf32( utf8, textSize, utf32Characters.Begin() );
532 utf32Characters.Resize( characterCount );
534 DALI_ASSERT_DEBUG( textSize >= characterCount && "Invalid UTF32 conversion length" );
535 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", this, textSize, mImpl->mModel->mLogicalModel->mText.Count() );
537 // The characters to be added.
538 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
540 // To reset the cursor position
541 lastCursorIndex = characterCount;
543 // Update the rest of the model during size negotiation
544 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
546 // The natural size needs to be re-calculated.
547 mImpl->mRecalculateNaturalSize = true;
549 // Apply modifications to the model
550 mImpl->mOperationsPending = ALL_OPERATIONS;
554 ShowPlaceholderText();
557 // Resets the cursor position.
558 ResetCursorPosition( lastCursorIndex );
560 // Scrolls the text to make the cursor visible.
561 ResetScrollPosition();
563 mImpl->RequestRelayout();
565 if( NULL != mImpl->mEventData )
567 // Cancel previously queued events
568 mImpl->mEventData->mEventQueue.clear();
571 // Do this last since it provides callbacks into application code.
572 if( NULL != mImpl->mEditableControlInterface )
574 mImpl->mEditableControlInterface->TextChanged();
578 void Controller::GetText( std::string& text ) const
580 if( !mImpl->IsShowingPlaceholderText() )
582 // Retrieves the text string.
583 mImpl->GetText( 0u, text );
587 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this );
591 void Controller::SetPlaceholderText( PlaceholderType type, const std::string& text )
593 if( NULL != mImpl->mEventData )
595 if( PLACEHOLDER_TYPE_INACTIVE == type )
597 mImpl->mEventData->mPlaceholderTextInactive = text;
601 mImpl->mEventData->mPlaceholderTextActive = text;
604 // Update placeholder if there is no text
605 if( mImpl->IsShowingPlaceholderText() ||
606 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
608 ShowPlaceholderText();
613 void Controller::GetPlaceholderText( PlaceholderType type, std::string& text ) const
615 if( NULL != mImpl->mEventData )
617 if( PLACEHOLDER_TYPE_INACTIVE == type )
619 text = mImpl->mEventData->mPlaceholderTextInactive;
623 text = mImpl->mEventData->mPlaceholderTextActive;
628 void Controller::UpdateAfterFontChange( const std::string& newDefaultFont )
630 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
632 if( !mImpl->mFontDefaults->familyDefined ) // If user defined font then should not update when system font changes
634 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
635 mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
639 mImpl->RequestRelayout();
643 // public : Default style & Input style
645 void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
647 if( NULL == mImpl->mFontDefaults )
649 mImpl->mFontDefaults = new FontDefaults();
652 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
653 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
654 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
656 // Clear the font-specific data
659 mImpl->RequestRelayout();
662 const std::string& Controller::GetDefaultFontFamily() const
664 if( NULL != mImpl->mFontDefaults )
666 return mImpl->mFontDefaults->mFontDescription.family;
672 void Controller::SetPlaceholderFontFamily( const std::string& placeholderTextFontFamily )
674 if( NULL != mImpl->mEventData )
676 if( NULL == mImpl->mEventData->mPlaceholderFont )
678 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
681 mImpl->mEventData->mPlaceholderFont->mFontDescription.family = placeholderTextFontFamily;
682 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetPlaceholderFontFamily %s\n", placeholderTextFontFamily.c_str());
683 mImpl->mEventData->mPlaceholderFont->familyDefined = !placeholderTextFontFamily.empty();
685 mImpl->RequestRelayout();
689 const std::string& Controller::GetPlaceholderFontFamily() const
691 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
693 return mImpl->mEventData->mPlaceholderFont->mFontDescription.family;
699 void Controller::SetDefaultFontWeight( FontWeight weight )
701 if( NULL == mImpl->mFontDefaults )
703 mImpl->mFontDefaults = new FontDefaults();
706 mImpl->mFontDefaults->mFontDescription.weight = weight;
707 mImpl->mFontDefaults->weightDefined = true;
709 // Clear the font-specific data
712 mImpl->RequestRelayout();
715 bool Controller::IsDefaultFontWeightDefined() const
717 if( NULL != mImpl->mFontDefaults )
719 return mImpl->mFontDefaults->weightDefined;
725 FontWeight Controller::GetDefaultFontWeight() const
727 if( NULL != mImpl->mFontDefaults )
729 return mImpl->mFontDefaults->mFontDescription.weight;
732 return TextAbstraction::FontWeight::NORMAL;
735 void Controller::SetPlaceholderTextFontWeight( FontWeight weight )
737 if( NULL != mImpl->mEventData )
739 if( NULL == mImpl->mEventData->mPlaceholderFont )
741 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
744 mImpl->mEventData->mPlaceholderFont->mFontDescription.weight = weight;
745 mImpl->mEventData->mPlaceholderFont->weightDefined = true;
747 mImpl->RequestRelayout();
751 bool Controller::IsPlaceholderTextFontWeightDefined() const
753 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
755 return mImpl->mEventData->mPlaceholderFont->weightDefined;
760 FontWeight Controller::GetPlaceholderTextFontWeight() const
762 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
764 return mImpl->mEventData->mPlaceholderFont->mFontDescription.weight;
767 return TextAbstraction::FontWeight::NORMAL;
770 void Controller::SetDefaultFontWidth( FontWidth width )
772 if( NULL == mImpl->mFontDefaults )
774 mImpl->mFontDefaults = new FontDefaults();
777 mImpl->mFontDefaults->mFontDescription.width = width;
778 mImpl->mFontDefaults->widthDefined = true;
780 // Clear the font-specific data
783 mImpl->RequestRelayout();
786 bool Controller::IsDefaultFontWidthDefined() const
788 if( NULL != mImpl->mFontDefaults )
790 return mImpl->mFontDefaults->widthDefined;
796 FontWidth Controller::GetDefaultFontWidth() const
798 if( NULL != mImpl->mFontDefaults )
800 return mImpl->mFontDefaults->mFontDescription.width;
803 return TextAbstraction::FontWidth::NORMAL;
806 void Controller::SetPlaceholderTextFontWidth( FontWidth width )
808 if( NULL != mImpl->mEventData )
810 if( NULL == mImpl->mEventData->mPlaceholderFont )
812 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
815 mImpl->mEventData->mPlaceholderFont->mFontDescription.width = width;
816 mImpl->mEventData->mPlaceholderFont->widthDefined = true;
818 mImpl->RequestRelayout();
822 bool Controller::IsPlaceholderTextFontWidthDefined() const
824 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
826 return mImpl->mEventData->mPlaceholderFont->widthDefined;
831 FontWidth Controller::GetPlaceholderTextFontWidth() const
833 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
835 return mImpl->mEventData->mPlaceholderFont->mFontDescription.width;
838 return TextAbstraction::FontWidth::NORMAL;
841 void Controller::SetDefaultFontSlant( FontSlant slant )
843 if( NULL == mImpl->mFontDefaults )
845 mImpl->mFontDefaults = new FontDefaults();
848 mImpl->mFontDefaults->mFontDescription.slant = slant;
849 mImpl->mFontDefaults->slantDefined = true;
851 // Clear the font-specific data
854 mImpl->RequestRelayout();
857 bool Controller::IsDefaultFontSlantDefined() const
859 if( NULL != mImpl->mFontDefaults )
861 return mImpl->mFontDefaults->slantDefined;
866 FontSlant Controller::GetDefaultFontSlant() const
868 if( NULL != mImpl->mFontDefaults )
870 return mImpl->mFontDefaults->mFontDescription.slant;
873 return TextAbstraction::FontSlant::NORMAL;
876 void Controller::SetPlaceholderTextFontSlant( FontSlant slant )
878 if( NULL != mImpl->mEventData )
880 if( NULL == mImpl->mEventData->mPlaceholderFont )
882 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
885 mImpl->mEventData->mPlaceholderFont->mFontDescription.slant = slant;
886 mImpl->mEventData->mPlaceholderFont->slantDefined = true;
888 mImpl->RequestRelayout();
892 bool Controller::IsPlaceholderTextFontSlantDefined() const
894 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
896 return mImpl->mEventData->mPlaceholderFont->slantDefined;
901 FontSlant Controller::GetPlaceholderTextFontSlant() const
903 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
905 return mImpl->mEventData->mPlaceholderFont->mFontDescription.slant;
908 return TextAbstraction::FontSlant::NORMAL;
911 void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
913 if( NULL == mImpl->mFontDefaults )
915 mImpl->mFontDefaults = new FontDefaults();
922 mImpl->mFontDefaults->mDefaultPointSize = fontSize;
923 mImpl->mFontDefaults->sizeDefined = true;
928 // Point size = Pixel size * 72.f / DPI
929 unsigned int horizontalDpi = 0u;
930 unsigned int verticalDpi = 0u;
931 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
932 fontClient.GetDpi( horizontalDpi, verticalDpi );
934 mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
935 mImpl->mFontDefaults->sizeDefined = true;
940 // Clear the font-specific data
943 mImpl->RequestRelayout();
946 float Controller::GetDefaultFontSize( FontSizeType type ) const
949 if( NULL != mImpl->mFontDefaults )
955 value = mImpl->mFontDefaults->mDefaultPointSize;
960 // Pixel size = Point size * DPI / 72.f
961 unsigned int horizontalDpi = 0u;
962 unsigned int verticalDpi = 0u;
963 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
964 fontClient.GetDpi( horizontalDpi, verticalDpi );
966 value = mImpl->mFontDefaults->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
976 void Controller::SetPlaceholderTextFontSize( float fontSize, FontSizeType type )
978 if( NULL != mImpl->mEventData )
980 if( NULL == mImpl->mEventData->mPlaceholderFont )
982 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
989 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = fontSize;
990 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
991 mImpl->mEventData->mIsPlaceholderPixelSize = false; // Font size flag
996 // Point size = Pixel size * 72.f / DPI
997 unsigned int horizontalDpi = 0u;
998 unsigned int verticalDpi = 0u;
999 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1000 fontClient.GetDpi( horizontalDpi, verticalDpi );
1002 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
1003 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1004 mImpl->mEventData->mIsPlaceholderPixelSize = true; // Font size flag
1009 mImpl->RequestRelayout();
1013 float Controller::GetPlaceholderTextFontSize( FontSizeType type ) const
1016 if( NULL != mImpl->mEventData )
1022 if( NULL != mImpl->mEventData->mPlaceholderFont )
1024 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize;
1028 // If the placeholder text font size is not set, then return the default font size.
1029 value = GetDefaultFontSize( POINT_SIZE );
1035 if( NULL != mImpl->mEventData->mPlaceholderFont )
1037 // Pixel size = Point size * DPI / 72.f
1038 unsigned int horizontalDpi = 0u;
1039 unsigned int verticalDpi = 0u;
1040 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1041 fontClient.GetDpi( horizontalDpi, verticalDpi );
1043 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1047 // If the placeholder text font size is not set, then return the default font size.
1048 value = GetDefaultFontSize( PIXEL_SIZE );
1059 void Controller::SetDefaultColor( const Vector4& color )
1061 mImpl->mTextColor = color;
1063 if( !mImpl->IsShowingPlaceholderText() )
1065 mImpl->mModel->mVisualModel->SetTextColor( color );
1067 mImpl->RequestRelayout();
1071 const Vector4& Controller::GetDefaultColor() const
1073 return mImpl->mTextColor;
1076 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
1078 if( NULL != mImpl->mEventData )
1080 mImpl->mEventData->mPlaceholderTextColor = textColor;
1083 if( mImpl->IsShowingPlaceholderText() )
1085 mImpl->mModel->mVisualModel->SetTextColor( textColor );
1086 mImpl->RequestRelayout();
1090 const Vector4& Controller::GetPlaceholderTextColor() const
1092 if( NULL != mImpl->mEventData )
1094 return mImpl->mEventData->mPlaceholderTextColor;
1097 return Color::BLACK;
1100 void Controller::SetShadowOffset( const Vector2& shadowOffset )
1102 mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
1104 mImpl->RequestRelayout();
1107 const Vector2& Controller::GetShadowOffset() const
1109 return mImpl->mModel->mVisualModel->GetShadowOffset();
1112 void Controller::SetShadowColor( const Vector4& shadowColor )
1114 mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
1116 mImpl->RequestRelayout();
1119 const Vector4& Controller::GetShadowColor() const
1121 return mImpl->mModel->mVisualModel->GetShadowColor();
1124 void Controller::SetShadowBlurRadius( const float& shadowBlurRadius )
1126 if ( fabsf( GetShadowBlurRadius() - shadowBlurRadius ) > Math::MACHINE_EPSILON_1 )
1128 mImpl->mModel->mVisualModel->SetShadowBlurRadius( shadowBlurRadius );
1130 mImpl->RequestRelayout();
1134 const float& Controller::GetShadowBlurRadius() const
1136 return mImpl->mModel->mVisualModel->GetShadowBlurRadius();
1139 void Controller::SetUnderlineColor( const Vector4& color )
1141 mImpl->mModel->mVisualModel->SetUnderlineColor( color );
1143 mImpl->RequestRelayout();
1146 const Vector4& Controller::GetUnderlineColor() const
1148 return mImpl->mModel->mVisualModel->GetUnderlineColor();
1151 void Controller::SetUnderlineEnabled( bool enabled )
1153 mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
1155 mImpl->RequestRelayout();
1158 bool Controller::IsUnderlineEnabled() const
1160 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
1163 void Controller::SetUnderlineHeight( float height )
1165 mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
1167 mImpl->RequestRelayout();
1170 float Controller::GetUnderlineHeight() const
1172 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
1175 void Controller::SetOutlineColor( const Vector4& color )
1177 mImpl->mModel->mVisualModel->SetOutlineColor( color );
1179 mImpl->RequestRelayout();
1182 const Vector4& Controller::GetOutlineColor() const
1184 return mImpl->mModel->mVisualModel->GetOutlineColor();
1187 void Controller::SetOutlineWidth( float width )
1189 mImpl->mModel->mVisualModel->SetOutlineWidth( width );
1191 mImpl->RequestRelayout();
1194 float Controller::GetOutlineWidth() const
1196 return mImpl->mModel->mVisualModel->GetOutlineWidth();
1199 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
1201 if( NULL == mImpl->mEmbossDefaults )
1203 mImpl->mEmbossDefaults = new EmbossDefaults();
1206 mImpl->mEmbossDefaults->properties = embossProperties;
1209 const std::string& Controller::GetDefaultEmbossProperties() const
1211 if( NULL != mImpl->mEmbossDefaults )
1213 return mImpl->mEmbossDefaults->properties;
1216 return EMPTY_STRING;
1219 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
1221 if( NULL == mImpl->mOutlineDefaults )
1223 mImpl->mOutlineDefaults = new OutlineDefaults();
1226 mImpl->mOutlineDefaults->properties = outlineProperties;
1229 const std::string& Controller::GetDefaultOutlineProperties() const
1231 if( NULL != mImpl->mOutlineDefaults )
1233 return mImpl->mOutlineDefaults->properties;
1236 return EMPTY_STRING;
1239 void Controller::SetDefaultLineSpacing( float lineSpacing )
1241 //TODO finish implementation
1242 mImpl->mLayoutEngine.SetDefaultLineSpacing( lineSpacing );
1245 float Controller::GetDefaultLineSpacing() const
1247 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
1250 void Controller::SetInputColor( const Vector4& color )
1252 if( NULL != mImpl->mEventData )
1254 mImpl->mEventData->mInputStyle.textColor = color;
1255 mImpl->mEventData->mInputStyle.isDefaultColor = false;
1257 if( EventData::SELECTING == mImpl->mEventData->mState )
1259 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
1261 // Get start and end position of selection
1262 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
1263 const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
1265 // Add the color run.
1266 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1267 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
1269 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
1270 colorRun.color = color;
1271 colorRun.characterRun.characterIndex = startOfSelectedText;
1272 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1274 // Request to relayout.
1275 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1276 mImpl->RequestRelayout();
1278 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1279 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1280 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1285 const Vector4& Controller::GetInputColor() const
1287 if( NULL != mImpl->mEventData )
1289 return mImpl->mEventData->mInputStyle.textColor;
1292 // Return the default text's color if there is no EventData.
1293 return mImpl->mTextColor;
1297 void Controller::SetInputFontFamily( const std::string& fontFamily )
1299 if( NULL != mImpl->mEventData )
1301 mImpl->mEventData->mInputStyle.familyName = fontFamily;
1302 mImpl->mEventData->mInputStyle.isFamilyDefined = true;
1304 if( EventData::SELECTING == mImpl->mEventData->mState )
1306 CharacterIndex startOfSelectedText = 0u;
1307 Length lengthOfSelectedText = 0u;
1308 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1309 mImpl->mModel->mLogicalModel,
1310 startOfSelectedText,
1311 lengthOfSelectedText );
1313 fontDescriptionRun.familyLength = fontFamily.size();
1314 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
1315 memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength );
1316 fontDescriptionRun.familyDefined = true;
1318 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
1320 // Request to relayout.
1321 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1326 UPDATE_LAYOUT_SIZE |
1329 mImpl->mRecalculateNaturalSize = true;
1330 mImpl->RequestRelayout();
1332 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1333 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1334 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1336 // As the font changes, recalculate the handle positions is needed.
1337 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1338 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1339 mImpl->mEventData->mUpdateHighlightBox = true;
1340 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1345 const std::string& Controller::GetInputFontFamily() const
1347 if( NULL != mImpl->mEventData )
1349 return mImpl->mEventData->mInputStyle.familyName;
1352 // Return the default font's family if there is no EventData.
1353 return GetDefaultFontFamily();
1356 void Controller::SetInputFontWeight( FontWeight weight )
1358 if( NULL != mImpl->mEventData )
1360 mImpl->mEventData->mInputStyle.weight = weight;
1361 mImpl->mEventData->mInputStyle.isWeightDefined = true;
1363 if( EventData::SELECTING == mImpl->mEventData->mState )
1365 CharacterIndex startOfSelectedText = 0u;
1366 Length lengthOfSelectedText = 0u;
1367 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1368 mImpl->mModel->mLogicalModel,
1369 startOfSelectedText,
1370 lengthOfSelectedText );
1372 fontDescriptionRun.weight = weight;
1373 fontDescriptionRun.weightDefined = true;
1375 // Request to relayout.
1376 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1381 UPDATE_LAYOUT_SIZE |
1384 mImpl->mRecalculateNaturalSize = true;
1385 mImpl->RequestRelayout();
1387 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1388 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1389 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1391 // As the font might change, recalculate the handle positions is needed.
1392 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1393 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1394 mImpl->mEventData->mUpdateHighlightBox = true;
1395 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1400 bool Controller::IsInputFontWeightDefined() const
1402 bool defined = false;
1404 if( NULL != mImpl->mEventData )
1406 defined = mImpl->mEventData->mInputStyle.isWeightDefined;
1412 FontWeight Controller::GetInputFontWeight() const
1414 if( NULL != mImpl->mEventData )
1416 return mImpl->mEventData->mInputStyle.weight;
1419 return GetDefaultFontWeight();
1422 void Controller::SetInputFontWidth( FontWidth width )
1424 if( NULL != mImpl->mEventData )
1426 mImpl->mEventData->mInputStyle.width = width;
1427 mImpl->mEventData->mInputStyle.isWidthDefined = true;
1429 if( EventData::SELECTING == mImpl->mEventData->mState )
1431 CharacterIndex startOfSelectedText = 0u;
1432 Length lengthOfSelectedText = 0u;
1433 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1434 mImpl->mModel->mLogicalModel,
1435 startOfSelectedText,
1436 lengthOfSelectedText );
1438 fontDescriptionRun.width = width;
1439 fontDescriptionRun.widthDefined = true;
1441 // Request to relayout.
1442 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1447 UPDATE_LAYOUT_SIZE |
1450 mImpl->mRecalculateNaturalSize = true;
1451 mImpl->RequestRelayout();
1453 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1454 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1455 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1457 // As the font might change, recalculate the handle positions is needed.
1458 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1459 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1460 mImpl->mEventData->mUpdateHighlightBox = true;
1461 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1466 bool Controller::IsInputFontWidthDefined() const
1468 bool defined = false;
1470 if( NULL != mImpl->mEventData )
1472 defined = mImpl->mEventData->mInputStyle.isWidthDefined;
1478 FontWidth Controller::GetInputFontWidth() const
1480 if( NULL != mImpl->mEventData )
1482 return mImpl->mEventData->mInputStyle.width;
1485 return GetDefaultFontWidth();
1488 void Controller::SetInputFontSlant( FontSlant slant )
1490 if( NULL != mImpl->mEventData )
1492 mImpl->mEventData->mInputStyle.slant = slant;
1493 mImpl->mEventData->mInputStyle.isSlantDefined = true;
1495 if( EventData::SELECTING == mImpl->mEventData->mState )
1497 CharacterIndex startOfSelectedText = 0u;
1498 Length lengthOfSelectedText = 0u;
1499 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1500 mImpl->mModel->mLogicalModel,
1501 startOfSelectedText,
1502 lengthOfSelectedText );
1504 fontDescriptionRun.slant = slant;
1505 fontDescriptionRun.slantDefined = true;
1507 // Request to relayout.
1508 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1513 UPDATE_LAYOUT_SIZE |
1516 mImpl->mRecalculateNaturalSize = true;
1517 mImpl->RequestRelayout();
1519 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1520 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1521 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1523 // As the font might change, recalculate the handle positions is needed.
1524 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1525 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1526 mImpl->mEventData->mUpdateHighlightBox = true;
1527 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1532 bool Controller::IsInputFontSlantDefined() const
1534 bool defined = false;
1536 if( NULL != mImpl->mEventData )
1538 defined = mImpl->mEventData->mInputStyle.isSlantDefined;
1544 FontSlant Controller::GetInputFontSlant() const
1546 if( NULL != mImpl->mEventData )
1548 return mImpl->mEventData->mInputStyle.slant;
1551 return GetDefaultFontSlant();
1554 void Controller::SetInputFontPointSize( float size )
1556 if( NULL != mImpl->mEventData )
1558 mImpl->mEventData->mInputStyle.size = size;
1559 mImpl->mEventData->mInputStyle.isSizeDefined = true;
1561 if( EventData::SELECTING == mImpl->mEventData->mState )
1563 CharacterIndex startOfSelectedText = 0u;
1564 Length lengthOfSelectedText = 0u;
1565 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1566 mImpl->mModel->mLogicalModel,
1567 startOfSelectedText,
1568 lengthOfSelectedText );
1570 fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
1571 fontDescriptionRun.sizeDefined = true;
1573 // Request to relayout.
1574 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1579 UPDATE_LAYOUT_SIZE |
1582 mImpl->mRecalculateNaturalSize = true;
1583 mImpl->RequestRelayout();
1585 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1586 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1587 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1589 // As the font might change, recalculate the handle positions is needed.
1590 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1591 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1592 mImpl->mEventData->mUpdateHighlightBox = true;
1593 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1598 float Controller::GetInputFontPointSize() const
1600 if( NULL != mImpl->mEventData )
1602 return mImpl->mEventData->mInputStyle.size;
1605 // Return the default font's point size if there is no EventData.
1606 return GetDefaultFontSize( Text::Controller::POINT_SIZE );
1609 void Controller::SetInputLineSpacing( float lineSpacing )
1611 if( NULL != mImpl->mEventData )
1613 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1614 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1618 float Controller::GetInputLineSpacing() const
1620 if( NULL != mImpl->mEventData )
1622 return mImpl->mEventData->mInputStyle.lineSpacing;
1628 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1630 if( NULL != mImpl->mEventData )
1632 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1636 const std::string& Controller::GetInputShadowProperties() const
1638 if( NULL != mImpl->mEventData )
1640 return mImpl->mEventData->mInputStyle.shadowProperties;
1643 return EMPTY_STRING;
1646 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1648 if( NULL != mImpl->mEventData )
1650 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1654 const std::string& Controller::GetInputUnderlineProperties() const
1656 if( NULL != mImpl->mEventData )
1658 return mImpl->mEventData->mInputStyle.underlineProperties;
1661 return EMPTY_STRING;
1664 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
1666 if( NULL != mImpl->mEventData )
1668 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1672 const std::string& Controller::GetInputEmbossProperties() const
1674 if( NULL != mImpl->mEventData )
1676 return mImpl->mEventData->mInputStyle.embossProperties;
1679 return GetDefaultEmbossProperties();
1682 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
1684 if( NULL != mImpl->mEventData )
1686 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1690 const std::string& Controller::GetInputOutlineProperties() const
1692 if( NULL != mImpl->mEventData )
1694 return mImpl->mEventData->mInputStyle.outlineProperties;
1697 return GetDefaultOutlineProperties();
1700 void Controller::SetInputModePassword( bool passwordInput )
1702 if( NULL != mImpl->mEventData )
1704 mImpl->mEventData->mPasswordInput = passwordInput;
1708 bool Controller::IsInputModePassword()
1710 if( NULL != mImpl->mEventData )
1712 return mImpl->mEventData->mPasswordInput;
1717 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
1719 if( NULL != mImpl->mEventData )
1721 mImpl->mEventData->mDoubleTapAction = action;
1725 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1727 NoTextTap::Action action = NoTextTap::NO_ACTION;
1729 if( NULL != mImpl->mEventData )
1731 action = mImpl->mEventData->mDoubleTapAction;
1737 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
1739 if( NULL != mImpl->mEventData )
1741 mImpl->mEventData->mLongPressAction = action;
1745 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1747 NoTextTap::Action action = NoTextTap::NO_ACTION;
1749 if( NULL != mImpl->mEventData )
1751 action = mImpl->mEventData->mLongPressAction;
1757 bool Controller::IsUnderlineSetByString()
1759 return mImpl->mUnderlineSetByString;
1762 void Controller::UnderlineSetByString( bool setByString )
1764 mImpl->mUnderlineSetByString = setByString;
1767 bool Controller::IsShadowSetByString()
1769 return mImpl->mShadowSetByString;
1772 void Controller::ShadowSetByString( bool setByString )
1774 mImpl->mShadowSetByString = setByString;
1777 bool Controller::IsOutlineSetByString()
1779 return mImpl->mOutlineSetByString;
1782 void Controller::OutlineSetByString( bool setByString )
1784 mImpl->mOutlineSetByString = setByString;
1787 bool Controller::IsFontStyleSetByString()
1789 return mImpl->mFontStyleSetByString;
1792 void Controller::FontStyleSetByString( bool setByString )
1794 mImpl->mFontStyleSetByString = setByString;
1797 // public : Queries & retrieves.
1799 Layout::Engine& Controller::GetLayoutEngine()
1801 return mImpl->mLayoutEngine;
1804 View& Controller::GetView()
1806 return mImpl->mView;
1809 Vector3 Controller::GetNaturalSize()
1811 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
1812 Vector3 naturalSize;
1814 // Make sure the model is up-to-date before layouting
1815 ProcessModifyEvents();
1817 if( mImpl->mRecalculateNaturalSize )
1819 // Operations that can be done only once until the text changes.
1820 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1827 GET_GLYPH_METRICS );
1829 // Set the update info to relayout the whole text.
1830 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1831 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1833 // Make sure the model is up-to-date before layouting
1834 mImpl->UpdateModel( onlyOnceOperations );
1836 // Layout the text for the new width.
1837 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT | REORDER );
1839 // Store the actual control's size to restore later.
1840 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
1842 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
1843 static_cast<OperationsMask>( onlyOnceOperations |
1845 naturalSize.GetVectorXY() );
1847 // Do not do again the only once operations.
1848 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1850 // Do the size related operations again.
1851 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1854 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1856 // Stores the natural size to avoid recalculate it again
1857 // unless the text/style changes.
1858 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
1860 mImpl->mRecalculateNaturalSize = false;
1862 // Clear the update info. This info will be set the next time the text is updated.
1863 mImpl->mTextUpdateInfo.Clear();
1865 // Restore the actual control's size.
1866 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
1868 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1872 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
1874 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1877 naturalSize.x = ConvertToEven( naturalSize.x );
1878 naturalSize.y = ConvertToEven( naturalSize.y );
1883 float Controller::GetHeightForWidth( float width )
1885 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
1886 // Make sure the model is up-to-date before layouting
1887 ProcessModifyEvents();
1890 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ||
1891 mImpl->mTextUpdateInfo.mFullRelayoutNeeded ||
1892 mImpl->mTextUpdateInfo.mClearAll )
1894 // Operations that can be done only once until the text changes.
1895 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1902 GET_GLYPH_METRICS );
1904 // Set the update info to relayout the whole text.
1905 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1906 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1908 // Make sure the model is up-to-date before layouting
1909 mImpl->UpdateModel( onlyOnceOperations );
1912 // Layout the text for the new width.
1913 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
1915 // Store the actual control's width.
1916 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
1918 DoRelayout( Size( width, MAX_FLOAT ),
1919 static_cast<OperationsMask>( onlyOnceOperations |
1923 // Do not do again the only once operations.
1924 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1926 // Do the size related operations again.
1927 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1931 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1933 // Clear the update info. This info will be set the next time the text is updated.
1934 mImpl->mTextUpdateInfo.Clear();
1936 // Restore the actual control's width.
1937 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
1939 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
1943 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
1944 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
1947 return layoutSize.height;
1950 int Controller::GetLineCount( float width )
1952 GetHeightForWidth( width );
1953 int numberofLines = mImpl->mModel->GetNumberOfLines();
1954 return numberofLines;
1957 const ModelInterface* const Controller::GetTextModel() const
1959 return mImpl->mModel.Get();
1962 float Controller::GetScrollAmountByUserInput()
1964 float scrollAmount = 0.0f;
1966 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
1968 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
1969 mImpl->mEventData->mCheckScrollAmount = false;
1971 return scrollAmount;
1974 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
1976 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
1979 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
1980 layoutHeight = layout.height;
1981 scrollPosition = mImpl->mModel->mScrollPosition.y;
1982 isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
1986 void Controller::SetHiddenInputOption(const Property::Map& options )
1988 if( NULL == mImpl->mHiddenInput )
1990 mImpl->mHiddenInput = new HiddenText( this );
1992 mImpl->mHiddenInput->SetProperties(options);
1995 void Controller::GetHiddenInputOption(Property::Map& options )
1997 if( NULL != mImpl->mHiddenInput )
1999 mImpl->mHiddenInput->GetProperties(options);
2003 void Controller::SetPlaceholderProperty( const Property::Map& map )
2005 const Property::Map::SizeType count = map.Count();
2007 for( Property::Map::SizeType position = 0; position < count; ++position )
2009 KeyValuePair keyValue = map.GetKeyValue( position );
2010 Property::Key& key = keyValue.first;
2011 Property::Value& value = keyValue.second;
2013 if( key == Toolkit::Text::PlaceHolder::Property::TEXT || key == PLACEHOLDER_TEXT )
2015 std::string text = "";
2017 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
2019 else if( key == Toolkit::Text::PlaceHolder::Property::TEXT_FOCUSED || key == PLACEHOLDER_TEXT_FOCUSED )
2021 std::string text = "";
2023 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
2025 else if( key == Toolkit::Text::PlaceHolder::Property::COLOR || key == PLACEHOLDER_COLOR )
2028 value.Get( textColor );
2029 if( GetPlaceholderTextColor() != textColor )
2031 SetPlaceholderTextColor( textColor );
2034 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_FAMILY || key == PLACEHOLDER_FONT_FAMILY )
2036 std::string fontFamily = "";
2037 value.Get( fontFamily );
2038 SetPlaceholderFontFamily( fontFamily );
2040 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_STYLE || key == PLACEHOLDER_FONT_STYLE )
2042 SetFontStyleProperty( this, value, Text::FontStyle::PLACEHOLDER );
2044 else if( key == Toolkit::Text::PlaceHolder::Property::POINT_SIZE || key == PLACEHOLDER_POINT_SIZE )
2047 value.Get( pointSize );
2048 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
2050 SetPlaceholderTextFontSize( pointSize, Text::Controller::POINT_SIZE );
2053 else if( key == Toolkit::Text::PlaceHolder::Property::PIXEL_SIZE || key == PLACEHOLDER_PIXEL_SIZE )
2056 value.Get( pixelSize );
2057 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
2059 SetPlaceholderTextFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
2062 else if( key == Toolkit::Text::PlaceHolder::Property::ELLIPSIS || key == PLACEHOLDER_ELLIPSIS )
2065 value.Get( ellipsis );
2066 SetPlaceholderTextElideEnabled( ellipsis );
2071 void Controller::GetPlaceholderProperty( Property::Map& map )
2073 if( NULL != mImpl->mEventData )
2075 if( !mImpl->mEventData->mPlaceholderTextActive.empty() )
2077 map[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = mImpl->mEventData->mPlaceholderTextActive;
2079 if( !mImpl->mEventData->mPlaceholderTextInactive.empty() )
2081 map[ Text::PlaceHolder::Property::TEXT ] = mImpl->mEventData->mPlaceholderTextInactive;
2084 map[ Text::PlaceHolder::Property::COLOR ] = mImpl->mEventData->mPlaceholderTextColor;
2085 map[ Text::PlaceHolder::Property::FONT_FAMILY ] = GetPlaceholderFontFamily();
2087 Property::Value fontStyleMapGet;
2088 GetFontStyleProperty( this, fontStyleMapGet, Text::FontStyle::PLACEHOLDER );
2089 map[ Text::PlaceHolder::Property::FONT_STYLE ] = fontStyleMapGet;
2091 // Choose font size : POINT_SIZE or PIXEL_SIZE
2092 if( !mImpl->mEventData->mIsPlaceholderPixelSize )
2094 map[ Text::PlaceHolder::Property::POINT_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE );
2098 map[ Text::PlaceHolder::Property::PIXEL_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE );
2101 if( mImpl->mEventData->mPlaceholderEllipsisFlag )
2103 map[ Text::PlaceHolder::Property::ELLIPSIS ] = IsPlaceholderTextElideEnabled();
2108 // public : Relayout.
2110 Controller::UpdateTextType Controller::Relayout( const Size& size )
2112 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
2114 UpdateTextType updateTextType = NONE_UPDATED;
2116 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
2118 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
2120 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
2121 updateTextType = MODEL_UPDATED;
2124 // Clear the update info. This info will be set the next time the text is updated.
2125 mImpl->mTextUpdateInfo.Clear();
2127 // Not worth to relayout if width or height is equal to zero.
2128 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
2130 return updateTextType;
2133 // Whether a new size has been set.
2134 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
2138 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
2140 // Layout operations that need to be done if the size changes.
2141 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2144 UPDATE_LAYOUT_SIZE |
2146 // Set the update info to relayout the whole text.
2147 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2148 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2150 // Store the size used to layout the text.
2151 mImpl->mModel->mVisualModel->mControlSize = size;
2154 // Whether there are modify events.
2155 if( 0u != mImpl->mModifyEvents.Count() )
2157 // Style operations that need to be done if the text is modified.
2158 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2162 // Set the update info to elide the text.
2163 if( mImpl->mModel->mElideEnabled ||
2164 ( ( NULL != mImpl->mEventData ) && mImpl->mEventData->mIsPlaceholderElideEnabled ) )
2166 // Update Text layout for applying elided
2167 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2170 UPDATE_LAYOUT_SIZE |
2172 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2173 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2176 // Make sure the model is up-to-date before layouting.
2177 ProcessModifyEvents();
2178 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
2182 updated = DoRelayout( size,
2183 mImpl->mOperationsPending,
2184 layoutSize ) || updated;
2188 updateTextType = MODEL_UPDATED;
2191 // Do not re-do any operation until something changes.
2192 mImpl->mOperationsPending = NO_OPERATION;
2193 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
2195 // Whether the text control is editable
2196 const bool isEditable = NULL != mImpl->mEventData;
2198 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
2200 if( newSize && isEditable )
2202 offset = mImpl->mModel->mScrollPosition;
2205 if( !isEditable || !IsMultiLineEnabled() )
2207 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
2208 CalculateVerticalOffset( size );
2215 // If there is a new size, the scroll position needs to be clamped.
2216 mImpl->ClampHorizontalScroll( layoutSize );
2218 // Update the decorator's positions is needed if there is a new size.
2219 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
2222 // Move the cursor, grab handle etc.
2223 if( mImpl->ProcessInputEvents() )
2225 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
2229 // Clear the update info. This info will be set the next time the text is updated.
2230 mImpl->mTextUpdateInfo.Clear();
2231 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
2233 return updateTextType;
2236 void Controller::RequestRelayout()
2238 mImpl->RequestRelayout();
2241 // public : Input style change signals.
2243 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
2245 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
2248 void Controller::ProcessInputStyleChangedSignals()
2250 if( NULL == mImpl->mEventData )
2256 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
2257 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
2261 const InputStyle::Mask mask = *it;
2263 if( NULL != mImpl->mEditableControlInterface )
2265 // Emit the input style changed signal.
2266 mImpl->mEditableControlInterface->InputStyleChanged( mask );
2270 mImpl->mEventData->mInputStyleChangedQueue.Clear();
2273 // public : Text-input Event Queuing.
2275 void Controller::KeyboardFocusGainEvent()
2277 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
2279 if( NULL != mImpl->mEventData )
2281 if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
2282 ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
2284 mImpl->ChangeState( EventData::EDITING );
2285 mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
2286 mImpl->mEventData->mUpdateInputStyle = true;
2288 mImpl->NotifyImfMultiLineStatus();
2289 if( mImpl->IsShowingPlaceholderText() )
2291 // Show alternative placeholder-text when editing
2292 ShowPlaceholderText();
2295 mImpl->RequestRelayout();
2299 void Controller::KeyboardFocusLostEvent()
2301 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
2303 if( NULL != mImpl->mEventData )
2305 if( EventData::INTERRUPTED != mImpl->mEventData->mState )
2307 mImpl->ChangeState( EventData::INACTIVE );
2309 if( !mImpl->IsShowingRealText() )
2311 // Revert to regular placeholder-text when not editing
2312 ShowPlaceholderText();
2316 mImpl->RequestRelayout();
2319 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
2321 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
2323 bool textChanged = false;
2324 bool relayoutNeeded = false;
2326 if( ( NULL != mImpl->mEventData ) &&
2327 ( keyEvent.state == KeyEvent::Down ) )
2329 int keyCode = keyEvent.keyCode;
2330 const std::string& keyString = keyEvent.keyPressed;
2332 const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
2334 // Pre-process to separate modifying events from non-modifying input events.
2337 // In some platforms arrive key events with no key code.
2341 else if( Dali::DALI_KEY_ESCAPE == keyCode || Dali::DALI_KEY_BACK == keyCode || Dali::DALI_KEY_SEARCH == keyCode )
2346 else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) ||
2347 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
2348 ( Dali::DALI_KEY_CURSOR_UP == keyCode ) ||
2349 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) )
2351 // If don't have any text, do nothing.
2352 if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
2357 uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition;
2358 uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2359 uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition );
2360 uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines();
2362 // Logic to determine whether this text control will lose focus or not.
2363 if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition ) ||
2364 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition) ||
2365 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) ||
2366 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) ||
2367 ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) ||
2368 ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) )
2373 mImpl->mEventData->mCheckScrollAmount = true;
2374 Event event( Event::CURSOR_KEY_EVENT );
2375 event.p1.mInt = keyCode;
2376 mImpl->mEventData->mEventQueue.push_back( event );
2378 // Will request for relayout.
2379 relayoutNeeded = true;
2381 else if( ( Dali::DALI_KEY_BACKSPACE == keyCode ) ||
2382 ( Dali::DevelKey::DALI_KEY_DELETE == keyCode ) )
2384 textChanged = DeleteEvent( keyCode );
2386 // Will request for relayout.
2387 relayoutNeeded = true;
2389 else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
2390 IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
2391 IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
2393 // Power key/Menu/Home key behaviour does not allow edit mode to resume.
2394 mImpl->ChangeState( EventData::INACTIVE );
2396 // Will request for relayout.
2397 relayoutNeeded = true;
2399 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2401 else if( Dali::DALI_KEY_SHIFT_LEFT == keyCode )
2403 // DALI_KEY_SHIFT_LEFT is the key code for the Left Shift. It's sent (by the imf?) when the predictive text is enabled
2404 // and a character is typed after the type of a upper case latin character.
2409 else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
2411 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2417 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
2419 // IMF manager is no longer handling key-events
2420 mImpl->ClearPreEditFlag();
2422 InsertText( keyString, COMMIT );
2425 // Will request for relayout.
2426 relayoutNeeded = true;
2429 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
2430 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
2432 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
2433 ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
2434 ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
2436 // Should not change the state if the key is the shift send by the imf manager.
2437 // Otherwise, when the state is SELECTING the text controller can't send the right
2438 // surrounding info to the imf.
2439 mImpl->ChangeState( EventData::EDITING );
2441 // Will request for relayout.
2442 relayoutNeeded = true;
2445 if( relayoutNeeded )
2447 mImpl->RequestRelayout();
2452 ( NULL != mImpl->mEditableControlInterface ) )
2454 // Do this last since it provides callbacks into application code
2455 mImpl->mEditableControlInterface->TextChanged();
2461 void Controller::TapEvent( unsigned int tapCount, float x, float y )
2463 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
2465 if( NULL != mImpl->mEventData )
2467 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
2468 EventData::State state( mImpl->mEventData->mState );
2469 bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
2471 if( mImpl->IsClipboardVisible() )
2473 if( EventData::INACTIVE == state || EventData::EDITING == state)
2475 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2477 relayoutNeeded = true;
2479 else if( 1u == tapCount )
2481 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
2483 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
2486 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
2488 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2489 relayoutNeeded = true;
2493 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
2495 // Hide placeholder text
2499 if( EventData::INACTIVE == state )
2501 mImpl->ChangeState( EventData::EDITING );
2503 else if( !mImpl->IsClipboardEmpty() )
2505 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
2507 relayoutNeeded = true;
2510 else if( 2u == tapCount )
2512 if( mImpl->mEventData->mSelectionEnabled &&
2513 mImpl->IsShowingRealText() )
2515 relayoutNeeded = true;
2516 mImpl->mEventData->mIsLeftHandleSelected = true;
2517 mImpl->mEventData->mIsRightHandleSelected = true;
2521 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
2522 if( relayoutNeeded )
2524 Event event( Event::TAP_EVENT );
2525 event.p1.mUint = tapCount;
2526 event.p2.mFloat = x;
2527 event.p3.mFloat = y;
2528 mImpl->mEventData->mEventQueue.push_back( event );
2530 mImpl->RequestRelayout();
2534 // Reset keyboard as tap event has occurred.
2535 mImpl->ResetImfManager();
2538 void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
2540 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
2542 if( NULL != mImpl->mEventData )
2544 Event event( Event::PAN_EVENT );
2545 event.p1.mInt = state;
2546 event.p2.mFloat = displacement.x;
2547 event.p3.mFloat = displacement.y;
2548 mImpl->mEventData->mEventQueue.push_back( event );
2550 mImpl->RequestRelayout();
2554 void Controller::LongPressEvent( Gesture::State state, float x, float y )
2556 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
2558 if( ( state == Gesture::Started ) &&
2559 ( NULL != mImpl->mEventData ) )
2561 // The 1st long-press on inactive text-field is treated as tap
2562 if( EventData::INACTIVE == mImpl->mEventData->mState )
2564 mImpl->ChangeState( EventData::EDITING );
2566 Event event( Event::TAP_EVENT );
2568 event.p2.mFloat = x;
2569 event.p3.mFloat = y;
2570 mImpl->mEventData->mEventQueue.push_back( event );
2572 mImpl->RequestRelayout();
2574 else if( !mImpl->IsShowingRealText() )
2576 Event event( Event::LONG_PRESS_EVENT );
2577 event.p1.mInt = state;
2578 event.p2.mFloat = x;
2579 event.p3.mFloat = y;
2580 mImpl->mEventData->mEventQueue.push_back( event );
2581 mImpl->RequestRelayout();
2583 else if( !mImpl->IsClipboardVisible() )
2585 // Reset the imf manager to commit the pre-edit before selecting the text.
2586 mImpl->ResetImfManager();
2588 Event event( Event::LONG_PRESS_EVENT );
2589 event.p1.mInt = state;
2590 event.p2.mFloat = x;
2591 event.p3.mFloat = y;
2592 mImpl->mEventData->mEventQueue.push_back( event );
2593 mImpl->RequestRelayout();
2595 mImpl->mEventData->mIsLeftHandleSelected = true;
2596 mImpl->mEventData->mIsRightHandleSelected = true;
2601 ImfManager::ImfCallbackData Controller::OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
2603 // Whether the text needs to be relaid-out.
2604 bool requestRelayout = false;
2606 // Whether to retrieve the text and cursor position to be sent to the IMF manager.
2607 bool retrieveText = false;
2608 bool retrieveCursor = false;
2610 switch( imfEvent.eventName )
2612 case ImfManager::COMMIT:
2614 InsertText( imfEvent.predictiveString, Text::Controller::COMMIT );
2615 requestRelayout = true;
2616 retrieveCursor = true;
2619 case ImfManager::PREEDIT:
2621 InsertText( imfEvent.predictiveString, Text::Controller::PRE_EDIT );
2622 requestRelayout = true;
2623 retrieveCursor = true;
2626 case ImfManager::DELETESURROUNDING:
2628 const bool textDeleted = RemoveText( imfEvent.cursorOffset,
2629 imfEvent.numberOfChars,
2630 DONT_UPDATE_INPUT_STYLE );
2634 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2635 !mImpl->IsPlaceholderAvailable() )
2637 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2641 ShowPlaceholderText();
2643 mImpl->mEventData->mUpdateCursorPosition = true;
2644 mImpl->mEventData->mScrollAfterDelete = true;
2646 requestRelayout = true;
2650 case ImfManager::GETSURROUNDING:
2652 retrieveText = true;
2653 retrieveCursor = true;
2656 case ImfManager::PRIVATECOMMAND:
2658 // PRIVATECOMMAND event is just for getting the private command message
2659 retrieveText = true;
2660 retrieveCursor = true;
2663 case ImfManager::VOID:
2670 if( requestRelayout )
2672 mImpl->mOperationsPending = ALL_OPERATIONS;
2673 mImpl->RequestRelayout();
2677 CharacterIndex cursorPosition = 0u;
2678 Length numberOfWhiteSpaces = 0u;
2680 if( retrieveCursor )
2682 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
2684 cursorPosition = mImpl->GetLogicalCursorPosition();
2686 if( cursorPosition < numberOfWhiteSpaces )
2688 cursorPosition = 0u;
2692 cursorPosition -= numberOfWhiteSpaces;
2698 mImpl->GetText( numberOfWhiteSpaces, text );
2701 ImfManager::ImfCallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
2703 if( requestRelayout &&
2704 ( NULL != mImpl->mEditableControlInterface ) )
2706 // Do this last since it provides callbacks into application code
2707 mImpl->mEditableControlInterface->TextChanged();
2710 return callbackData;
2713 void Controller::PasteClipboardItemEvent()
2715 // Retrieve the clipboard contents first
2716 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
2717 std::string stringToPaste( notifier.GetContent() );
2719 // Commit the current pre-edit text; the contents of the clipboard should be appended
2720 mImpl->ResetImfManager();
2722 // Temporary disable hiding clipboard
2723 mImpl->SetClipboardHideEnable( false );
2726 PasteText( stringToPaste );
2728 mImpl->SetClipboardHideEnable( true );
2731 // protected : Inherit from Text::Decorator::ControllerInterface.
2733 void Controller::GetTargetSize( Vector2& targetSize )
2735 targetSize = mImpl->mModel->mVisualModel->mControlSize;
2738 void Controller::AddDecoration( Actor& actor, bool needsClipping )
2740 if( NULL != mImpl->mEditableControlInterface )
2742 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
2746 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
2748 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
2750 if( NULL != mImpl->mEventData )
2752 switch( handleType )
2756 Event event( Event::GRAB_HANDLE_EVENT );
2757 event.p1.mUint = state;
2758 event.p2.mFloat = x;
2759 event.p3.mFloat = y;
2761 mImpl->mEventData->mEventQueue.push_back( event );
2764 case LEFT_SELECTION_HANDLE:
2766 Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
2767 event.p1.mUint = state;
2768 event.p2.mFloat = x;
2769 event.p3.mFloat = y;
2771 mImpl->mEventData->mEventQueue.push_back( event );
2774 case RIGHT_SELECTION_HANDLE:
2776 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
2777 event.p1.mUint = state;
2778 event.p2.mFloat = x;
2779 event.p3.mFloat = y;
2781 mImpl->mEventData->mEventQueue.push_back( event );
2784 case LEFT_SELECTION_HANDLE_MARKER:
2785 case RIGHT_SELECTION_HANDLE_MARKER:
2787 // Markers do not move the handles.
2790 case HANDLE_TYPE_COUNT:
2792 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
2796 mImpl->RequestRelayout();
2800 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
2802 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
2804 if( NULL == mImpl->mEventData )
2811 case Toolkit::TextSelectionPopup::CUT:
2813 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
2814 mImpl->mOperationsPending = ALL_OPERATIONS;
2816 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2817 !mImpl->IsPlaceholderAvailable() )
2819 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2823 ShowPlaceholderText();
2826 mImpl->mEventData->mUpdateCursorPosition = true;
2827 mImpl->mEventData->mScrollAfterDelete = true;
2829 mImpl->RequestRelayout();
2831 if( NULL != mImpl->mEditableControlInterface )
2833 mImpl->mEditableControlInterface->TextChanged();
2837 case Toolkit::TextSelectionPopup::COPY:
2839 mImpl->SendSelectionToClipboard( false ); // Text not modified
2841 mImpl->mEventData->mUpdateCursorPosition = true;
2843 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
2846 case Toolkit::TextSelectionPopup::PASTE:
2848 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
2851 case Toolkit::TextSelectionPopup::SELECT:
2853 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
2855 if( mImpl->mEventData->mSelectionEnabled )
2857 // Creates a SELECT event.
2858 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
2862 case Toolkit::TextSelectionPopup::SELECT_ALL:
2864 // Creates a SELECT_ALL event
2865 SelectEvent( 0.f, 0.f, true );
2868 case Toolkit::TextSelectionPopup::CLIPBOARD:
2870 mImpl->ShowClipboard();
2873 case Toolkit::TextSelectionPopup::NONE:
2881 void Controller::DisplayTimeExpired()
2883 mImpl->mEventData->mUpdateCursorPosition = true;
2884 // Apply modifications to the model
2885 mImpl->mOperationsPending = ALL_OPERATIONS;
2887 mImpl->RequestRelayout();
2890 // private : Update.
2892 void Controller::InsertText( const std::string& text, Controller::InsertType type )
2894 bool removedPrevious = false;
2895 bool removedSelected = false;
2896 bool maxLengthReached = false;
2898 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
2900 if( NULL == mImpl->mEventData )
2905 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
2906 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
2907 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
2909 // TODO: At the moment the underline runs are only for pre-edit.
2910 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
2912 // Remove the previous IMF pre-edit.
2913 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
2915 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
2916 mImpl->mEventData->mPreEditLength,
2917 DONT_UPDATE_INPUT_STYLE );
2919 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
2920 mImpl->mEventData->mPreEditLength = 0u;
2924 // Remove the previous Selection.
2925 removedSelected = RemoveSelectedText();
2929 Vector<Character> utf32Characters;
2930 Length characterCount = 0u;
2934 // Convert text into UTF-32
2935 utf32Characters.Resize( text.size() );
2937 // This is a bit horrible but std::string returns a (signed) char*
2938 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
2940 // Transform a text array encoded in utf8 into an array encoded in utf32.
2941 // It returns the actual number of characters.
2942 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
2943 utf32Characters.Resize( characterCount );
2945 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
2946 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
2949 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
2951 // The placeholder text is no longer needed
2952 if( mImpl->IsShowingPlaceholderText() )
2957 mImpl->ChangeState( EventData::EDITING );
2959 // Handle the IMF (predicitive text) state changes
2960 if( COMMIT == type )
2962 // IMF manager is no longer handling key-events
2963 mImpl->ClearPreEditFlag();
2967 if( !mImpl->mEventData->mPreEditFlag )
2969 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
2971 // Record the start of the pre-edit text
2972 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
2975 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
2976 mImpl->mEventData->mPreEditFlag = true;
2978 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
2981 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
2983 // Restrict new text to fit within Maximum characters setting.
2984 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
2985 maxLengthReached = ( characterCount > maxSizeOfNewText );
2987 // The cursor position.
2988 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
2990 // Update the text's style.
2992 // Updates the text style runs by adding characters.
2993 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
2995 // Get the character index from the cursor index.
2996 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
2998 // Retrieve the text's style for the given index.
3000 mImpl->RetrieveDefaultInputStyle( style );
3001 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
3003 // Whether to add a new text color run.
3004 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor );
3006 // Whether to add a new font run.
3007 const bool addFontNameRun = style.familyName != mImpl->mEventData->mInputStyle.familyName;
3008 const bool addFontWeightRun = style.weight != mImpl->mEventData->mInputStyle.weight;
3009 const bool addFontWidthRun = style.width != mImpl->mEventData->mInputStyle.width;
3010 const bool addFontSlantRun = style.slant != mImpl->mEventData->mInputStyle.slant;
3011 const bool addFontSizeRun = style.size != mImpl->mEventData->mInputStyle.size;
3016 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
3017 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
3019 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
3020 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
3021 colorRun.characterRun.characterIndex = cursorIndex;
3022 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3025 if( addFontNameRun ||
3031 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
3032 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
3034 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
3036 if( addFontNameRun )
3038 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
3039 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
3040 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
3041 fontDescriptionRun.familyDefined = true;
3043 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
3046 if( addFontWeightRun )
3048 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
3049 fontDescriptionRun.weightDefined = true;
3052 if( addFontWidthRun )
3054 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
3055 fontDescriptionRun.widthDefined = true;
3058 if( addFontSlantRun )
3060 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
3061 fontDescriptionRun.slantDefined = true;
3064 if( addFontSizeRun )
3066 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
3067 fontDescriptionRun.sizeDefined = true;
3070 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
3071 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3074 // Insert at current cursor position.
3075 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
3077 if( cursorIndex < numberOfCharactersInModel )
3079 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3083 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3086 // Mark the first paragraph to be updated.
3087 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3089 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3090 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3091 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
3092 mImpl->mTextUpdateInfo.mClearAll = true;
3096 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3097 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
3100 // Update the cursor index.
3101 cursorIndex += maxSizeOfNewText;
3103 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 );
3106 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
3107 mImpl->IsPlaceholderAvailable() )
3109 // Show place-holder if empty after removing the pre-edit text
3110 ShowPlaceholderText();
3111 mImpl->mEventData->mUpdateCursorPosition = true;
3112 mImpl->ClearPreEditFlag();
3114 else if( removedPrevious ||
3116 ( 0 != utf32Characters.Count() ) )
3118 // Queue an inserted event
3119 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
3121 mImpl->mEventData->mUpdateCursorPosition = true;
3122 if( removedSelected )
3124 mImpl->mEventData->mScrollAfterDelete = true;
3128 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3132 if( maxLengthReached )
3134 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
3136 mImpl->ResetImfManager();
3138 if( NULL != mImpl->mEditableControlInterface )
3140 // Do this last since it provides callbacks into application code
3141 mImpl->mEditableControlInterface->MaxLengthReached();
3146 void Controller::PasteText( const std::string& stringToPaste )
3148 InsertText( stringToPaste, Text::Controller::COMMIT );
3149 mImpl->ChangeState( EventData::EDITING );
3150 mImpl->RequestRelayout();
3152 if( NULL != mImpl->mEditableControlInterface )
3154 // Do this last since it provides callbacks into application code
3155 mImpl->mEditableControlInterface->TextChanged();
3159 bool Controller::RemoveText( int cursorOffset,
3160 int numberOfCharacters,
3161 UpdateInputStyleType type )
3163 bool removed = false;
3165 if( NULL == mImpl->mEventData )
3170 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
3171 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
3173 if( !mImpl->IsShowingPlaceholderText() )
3175 // Delete at current cursor position
3176 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
3177 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3179 CharacterIndex cursorIndex = 0;
3181 // Validate the cursor position & number of characters
3182 if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
3184 cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
3187 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
3189 numberOfCharacters = currentText.Count() - cursorIndex;
3192 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.
3193 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
3195 // Mark the paragraphs to be updated.
3196 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3198 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3199 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3200 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
3201 mImpl->mTextUpdateInfo.mClearAll = true;
3205 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3206 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
3209 // Update the input style and remove the text's style before removing the text.
3211 if( UPDATE_INPUT_STYLE == type )
3213 // Keep a copy of the current input style.
3214 InputStyle currentInputStyle;
3215 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
3217 // Set first the default input style.
3218 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
3220 // Update the input style.
3221 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
3223 // Compare if the input style has changed.
3224 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
3226 if( hasInputStyleChanged )
3228 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
3229 // Queue the input style changed signal.
3230 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
3234 // Updates the text style runs by removing characters. Runs with no characters are removed.
3235 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
3237 // Remove the characters.
3238 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
3239 Vector<Character>::Iterator last = first + numberOfCharacters;
3241 currentText.Erase( first, last );
3243 // Cursor position retreat
3244 oldCursorIndex = cursorIndex;
3246 mImpl->mEventData->mScrollAfterDelete = true;
3248 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
3256 bool Controller::RemoveSelectedText()
3258 bool textRemoved( false );
3260 if( EventData::SELECTING == mImpl->mEventData->mState )
3262 std::string removedString;
3263 mImpl->RetrieveSelection( removedString, true );
3265 if( !removedString.empty() )
3268 mImpl->ChangeState( EventData::EDITING );
3275 // private : Relayout.
3277 bool Controller::DoRelayout( const Size& size,
3278 OperationsMask operationsRequired,
3281 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
3282 bool viewUpdated( false );
3284 // Calculate the operations to be done.
3285 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
3287 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
3288 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
3290 // Get the current layout size.
3291 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3293 if( NO_OPERATION != ( LAYOUT & operations ) )
3295 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
3297 // Some vectors with data needed to layout and reorder may be void
3298 // after the first time the text has been laid out.
3299 // Fill the vectors again.
3301 // Calculate the number of glyphs to layout.
3302 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
3303 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
3304 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
3305 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
3307 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
3308 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
3309 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
3310 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
3312 if( 0u == totalNumberOfGlyphs )
3314 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3316 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
3319 // Nothing else to do if there is no glyphs.
3320 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
3324 const Vector<LineBreakInfo>& lineBreakInfo = mImpl->mModel->mLogicalModel->mLineBreakInfo;
3325 const Vector<WordBreakInfo>& wordBreakInfo = mImpl->mModel->mLogicalModel->mWordBreakInfo;
3326 const Vector<CharacterDirection>& characterDirection = mImpl->mModel->mLogicalModel->mCharacterDirections;
3327 const Vector<GlyphInfo>& glyphs = mImpl->mModel->mVisualModel->mGlyphs;
3328 const Vector<CharacterIndex>& glyphsToCharactersMap = mImpl->mModel->mVisualModel->mGlyphsToCharacters;
3329 const Vector<Length>& charactersPerGlyph = mImpl->mModel->mVisualModel->mCharactersPerGlyph;
3330 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
3332 // Set the layout parameters.
3333 Layout::Parameters layoutParameters( size,
3335 lineBreakInfo.Begin(),
3336 wordBreakInfo.Begin(),
3337 ( 0u != characterDirection.Count() ) ? characterDirection.Begin() : NULL,
3339 glyphsToCharactersMap.Begin(),
3340 charactersPerGlyph.Begin(),
3341 charactersToGlyphBuffer,
3342 glyphsPerCharacterBuffer,
3343 totalNumberOfGlyphs,
3344 mImpl->mModel->mHorizontalAlignment,
3345 mImpl->mModel->mLineWrapMode );
3347 // Resize the vector of positions to have the same size than the vector of glyphs.
3348 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
3349 glyphPositions.Resize( totalNumberOfGlyphs );
3351 // Whether the last character is a new paragraph character.
3352 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
3353 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
3355 // The initial glyph and the number of glyphs to layout.
3356 layoutParameters.startGlyphIndex = startGlyphIndex;
3357 layoutParameters.numberOfGlyphs = numberOfGlyphs;
3358 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
3359 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
3361 // Update the ellipsis
3362 bool elideTextEnabled = mImpl->mModel->mElideEnabled;
3364 if( NULL != mImpl->mEventData )
3366 if( mImpl->mEventData->mPlaceholderEllipsisFlag && mImpl->IsShowingPlaceholderText() )
3368 elideTextEnabled = mImpl->mEventData->mIsPlaceholderElideEnabled;
3370 else if( EventData::INACTIVE != mImpl->mEventData->mState )
3372 // Disable ellipsis when editing
3373 elideTextEnabled = false;
3376 // Reset the scroll position in inactive state
3377 if( elideTextEnabled && ( mImpl->mEventData->mState == EventData::INACTIVE ) )
3379 ResetScrollPosition();
3383 // Update the visual model.
3385 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
3387 mImpl->mModel->mVisualModel->mLines,
3391 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
3395 layoutSize = newLayoutSize;
3397 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
3399 mImpl->mAutoScrollDirectionRTL = false;
3402 // Reorder the lines
3403 if( NO_OPERATION != ( REORDER & operations ) )
3405 Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = mImpl->mModel->mLogicalModel->mBidirectionalParagraphInfo;
3406 Vector<BidirectionalLineInfoRun>& bidirectionalLineInfo = mImpl->mModel->mLogicalModel->mBidirectionalLineInfo;
3408 // Check first if there are paragraphs with bidirectional info.
3409 if( 0u != bidirectionalInfo.Count() )
3412 const Length numberOfLines = mImpl->mModel->mVisualModel->mLines.Count();
3414 // Reorder the lines.
3415 bidirectionalLineInfo.Reserve( numberOfLines ); // Reserve because is not known yet how many lines have right to left characters.
3416 ReorderLines( bidirectionalInfo,
3418 requestedNumberOfCharacters,
3419 mImpl->mModel->mVisualModel->mLines,
3420 bidirectionalLineInfo );
3422 // Set the bidirectional info per line into the layout parameters.
3423 layoutParameters.lineBidirectionalInfoRunsBuffer = bidirectionalLineInfo.Begin();
3424 layoutParameters.numberOfBidirectionalInfoRuns = bidirectionalLineInfo.Count();
3426 // Re-layout the text. Reorder those lines with right to left characters.
3427 mImpl->mLayoutEngine.ReLayoutRightToLeftLines( layoutParameters,
3429 requestedNumberOfCharacters,
3432 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && ( numberOfLines > 0 ) )
3434 const LineRun* const firstline = mImpl->mModel->mVisualModel->mLines.Begin();
3437 mImpl->mAutoScrollDirectionRTL = firstline->direction;
3443 // Sets the layout size.
3444 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3446 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
3451 if( NO_OPERATION != ( ALIGN & operations ) )
3453 // The laid-out lines.
3454 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
3456 // Need to align with the control's size as the text may contain lines
3457 // starting either with left to right text or right to left.
3458 mImpl->mLayoutEngine.Align( size,
3460 requestedNumberOfCharacters,
3461 mImpl->mModel->mHorizontalAlignment,
3463 mImpl->mModel->mAlignmentOffset );
3467 #if defined(DEBUG_ENABLED)
3468 std::string currentText;
3469 GetText( currentText );
3470 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mAutoScrollDirectionRTL[%s] [%s]\n", this, (mImpl->mAutoScrollDirectionRTL)?"true":"false", currentText.c_str() );
3472 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
3476 void Controller::CalculateVerticalOffset( const Size& controlSize )
3478 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3480 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
3482 // Get the line height of the default font.
3483 layoutSize.height = mImpl->GetDefaultFontLineHeight();
3486 switch( mImpl->mModel->mVerticalAlignment )
3488 case VerticalAlignment::TOP:
3490 mImpl->mModel->mScrollPosition.y = 0.f;
3493 case VerticalAlignment::CENTER:
3495 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
3498 case VerticalAlignment::BOTTOM:
3500 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
3506 // private : Events.
3508 void Controller::ProcessModifyEvents()
3510 Vector<ModifyEvent>& events = mImpl->mModifyEvents;
3512 if( 0u == events.Count() )
3518 for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
3519 endIt = events.End();
3523 const ModifyEvent& event = *it;
3525 if( ModifyEvent::TEXT_REPLACED == event.type )
3527 // A (single) replace event should come first, otherwise we wasted time processing NOOP events
3528 DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
3530 TextReplacedEvent();
3532 else if( ModifyEvent::TEXT_INSERTED == event.type )
3534 TextInsertedEvent();
3536 else if( ModifyEvent::TEXT_DELETED == event.type )
3538 // Placeholder-text cannot be deleted
3539 if( !mImpl->IsShowingPlaceholderText() )
3546 if( NULL != mImpl->mEventData )
3548 // When the text is being modified, delay cursor blinking
3549 mImpl->mEventData->mDecorator->DelayCursorBlink();
3552 // Discard temporary text
3556 void Controller::TextReplacedEvent()
3558 // The natural size needs to be re-calculated.
3559 mImpl->mRecalculateNaturalSize = true;
3561 // Apply modifications to the model
3562 mImpl->mOperationsPending = ALL_OPERATIONS;
3565 void Controller::TextInsertedEvent()
3567 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
3569 if( NULL == mImpl->mEventData )
3574 mImpl->mEventData->mCheckScrollAmount = true;
3576 // The natural size needs to be re-calculated.
3577 mImpl->mRecalculateNaturalSize = true;
3579 // Apply modifications to the model; TODO - Optimize this
3580 mImpl->mOperationsPending = ALL_OPERATIONS;
3583 void Controller::TextDeletedEvent()
3585 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
3587 if( NULL == mImpl->mEventData )
3592 mImpl->mEventData->mCheckScrollAmount = true;
3594 // The natural size needs to be re-calculated.
3595 mImpl->mRecalculateNaturalSize = true;
3597 // Apply modifications to the model; TODO - Optimize this
3598 mImpl->mOperationsPending = ALL_OPERATIONS;
3601 void Controller::SelectEvent( float x, float y, bool selectAll )
3603 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
3605 if( NULL != mImpl->mEventData )
3609 Event event( Event::SELECT_ALL );
3610 mImpl->mEventData->mEventQueue.push_back( event );
3614 Event event( Event::SELECT );
3615 event.p2.mFloat = x;
3616 event.p3.mFloat = y;
3617 mImpl->mEventData->mEventQueue.push_back( event );
3620 mImpl->mEventData->mCheckScrollAmount = true;
3621 mImpl->mEventData->mIsLeftHandleSelected = true;
3622 mImpl->mEventData->mIsRightHandleSelected = true;
3623 mImpl->RequestRelayout();
3627 bool Controller::DeleteEvent( int keyCode )
3629 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p KeyCode : %d \n", this, keyCode );
3631 bool removed = false;
3633 if( NULL == mImpl->mEventData )
3638 // IMF manager is no longer handling key-events
3639 mImpl->ClearPreEditFlag();
3641 if( EventData::SELECTING == mImpl->mEventData->mState )
3643 removed = RemoveSelectedText();
3645 else if( ( mImpl->mEventData->mPrimaryCursorPosition > 0 ) && ( keyCode == Dali::DALI_KEY_BACKSPACE) )
3647 // Remove the character before the current cursor position
3648 removed = RemoveText( -1,
3650 UPDATE_INPUT_STYLE );
3652 else if( ( mImpl->mEventData->mPrimaryCursorPosition >= 0 ) && ( keyCode == Dali::DevelKey::DALI_KEY_DELETE ) )
3654 // Remove the character after the current cursor position
3655 removed = RemoveText( 0,
3657 UPDATE_INPUT_STYLE );
3662 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3663 !mImpl->IsPlaceholderAvailable() )
3665 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3669 ShowPlaceholderText();
3671 mImpl->mEventData->mUpdateCursorPosition = true;
3672 mImpl->mEventData->mScrollAfterDelete = true;
3678 // private : Helpers.
3680 void Controller::ResetText()
3683 mImpl->mModel->mLogicalModel->mText.Clear();
3685 // We have cleared everything including the placeholder-text
3686 mImpl->PlaceholderCleared();
3688 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3689 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3690 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
3692 // Clear any previous text.
3693 mImpl->mTextUpdateInfo.mClearAll = true;
3695 // The natural size needs to be re-calculated.
3696 mImpl->mRecalculateNaturalSize = true;
3698 // Apply modifications to the model
3699 mImpl->mOperationsPending = ALL_OPERATIONS;
3702 void Controller::ShowPlaceholderText()
3704 if( mImpl->IsPlaceholderAvailable() )
3706 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
3708 if( NULL == mImpl->mEventData )
3713 mImpl->mEventData->mIsShowingPlaceholderText = true;
3715 // Disable handles when showing place-holder text
3716 mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
3717 mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
3718 mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
3720 const char* text( NULL );
3723 // TODO - Switch Placeholder text when changing state
3724 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
3725 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
3727 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
3728 size = mImpl->mEventData->mPlaceholderTextActive.size();
3732 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
3733 size = mImpl->mEventData->mPlaceholderTextInactive.size();
3736 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3737 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3739 // Reset model for showing placeholder.
3740 mImpl->mModel->mLogicalModel->mText.Clear();
3741 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
3743 // Convert text into UTF-32
3744 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
3745 utf32Characters.Resize( size );
3747 // This is a bit horrible but std::string returns a (signed) char*
3748 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
3750 // Transform a text array encoded in utf8 into an array encoded in utf32.
3751 // It returns the actual number of characters.
3752 const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
3753 utf32Characters.Resize( characterCount );
3755 // The characters to be added.
3756 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
3758 // Reset the cursor position
3759 mImpl->mEventData->mPrimaryCursorPosition = 0;
3761 // The natural size needs to be re-calculated.
3762 mImpl->mRecalculateNaturalSize = true;
3764 // Apply modifications to the model
3765 mImpl->mOperationsPending = ALL_OPERATIONS;
3767 // Update the rest of the model during size negotiation
3768 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
3772 void Controller::ClearFontData()
3774 if( mImpl->mFontDefaults )
3776 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
3779 // Set flags to update the model.
3780 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3781 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3782 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
3784 mImpl->mTextUpdateInfo.mClearAll = true;
3785 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
3786 mImpl->mRecalculateNaturalSize = true;
3788 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
3793 UPDATE_LAYOUT_SIZE |
3798 void Controller::ClearStyleData()
3800 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
3801 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
3804 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
3806 // Reset the cursor position
3807 if( NULL != mImpl->mEventData )
3809 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
3811 // Update the cursor if it's in editing mode.
3812 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
3814 mImpl->mEventData->mUpdateCursorPosition = true;
3819 void Controller::ResetScrollPosition()
3821 if( NULL != mImpl->mEventData )
3823 // Reset the scroll position.
3824 mImpl->mModel->mScrollPosition = Vector2::ZERO;
3825 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3829 void Controller::SetControlInterface( ControlInterface* controlInterface )
3831 mImpl->mControlInterface = controlInterface;
3834 bool Controller::ShouldClearFocusOnEscape() const
3836 return mImpl->mShouldClearFocusOnEscape;
3839 // private : Private contructors & copy operator.
3841 Controller::Controller()
3844 mImpl = new Controller::Impl( NULL, NULL );
3847 Controller::Controller( ControlInterface* controlInterface )
3849 mImpl = new Controller::Impl( controlInterface, NULL );
3852 Controller::Controller( ControlInterface* controlInterface,
3853 EditableControlInterface* editableControlInterface )
3855 mImpl = new Controller::Impl( controlInterface,
3856 editableControlInterface );
3859 // The copy constructor and operator are left unimplemented.
3861 // protected : Destructor.
3863 Controller::~Controller()
3870 } // namespace Toolkit