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 bool Controller::IsMarkupProcessorEnabled() const
172 return mImpl->mMarkupProcessorEnabled;
175 void Controller::SetAutoScrollEnabled( bool enable )
177 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 );
179 if( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX )
183 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled for SINGLE_LINE_BOX\n" );
184 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
194 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled Disabling autoscroll\n");
195 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
202 mImpl->mIsAutoScrollEnabled = enable;
203 mImpl->RequestRelayout();
207 DALI_LOG_WARNING( "Attempted AutoScrolling on a non SINGLE_LINE_BOX, request ignored\n" );
208 mImpl->mIsAutoScrollEnabled = false;
212 bool Controller::IsAutoScrollEnabled() const
214 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::IsAutoScrollEnabled[%s]\n", mImpl->mIsAutoScrollEnabled?"true":"false" );
216 return mImpl->mIsAutoScrollEnabled;
219 CharacterDirection Controller::GetAutoScrollDirection() const
221 return mImpl->mAutoScrollDirectionRTL;
224 float Controller::GetAutoScrollLineAlignment() const
228 if( mImpl->mModel->mVisualModel &&
229 ( 0u != mImpl->mModel->mVisualModel->mLines.Count() ) )
231 offset = ( *mImpl->mModel->mVisualModel->mLines.Begin() ).alignmentOffset;
237 void Controller::SetHorizontalScrollEnabled( bool enable )
239 if( ( NULL != mImpl->mEventData ) &&
240 mImpl->mEventData->mDecorator )
242 mImpl->mEventData->mDecorator->SetHorizontalScrollEnabled( enable );
245 bool Controller::IsHorizontalScrollEnabled() const
247 if( ( NULL != mImpl->mEventData ) &&
248 mImpl->mEventData->mDecorator )
250 return mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
256 void Controller::SetVerticalScrollEnabled( bool enable )
258 if( ( NULL != mImpl->mEventData ) &&
259 mImpl->mEventData->mDecorator )
261 if( mImpl->mEventData->mDecorator )
263 mImpl->mEventData->mDecorator->SetVerticalScrollEnabled( enable );
268 bool Controller::IsVerticalScrollEnabled() const
270 if( ( NULL != mImpl->mEventData ) &&
271 mImpl->mEventData->mDecorator )
273 return mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
279 void Controller::SetSmoothHandlePanEnabled( bool enable )
281 if( ( NULL != mImpl->mEventData ) &&
282 mImpl->mEventData->mDecorator )
284 mImpl->mEventData->mDecorator->SetSmoothHandlePanEnabled( enable );
288 bool Controller::IsSmoothHandlePanEnabled() const
290 if( ( NULL != mImpl->mEventData ) &&
291 mImpl->mEventData->mDecorator )
293 return mImpl->mEventData->mDecorator->IsSmoothHandlePanEnabled();
299 void Controller::SetMaximumNumberOfCharacters( Length maxCharacters )
301 mImpl->mMaximumNumberOfCharacters = maxCharacters;
304 int Controller::GetMaximumNumberOfCharacters()
306 return mImpl->mMaximumNumberOfCharacters;
309 void Controller::SetEnableCursorBlink( bool enable )
311 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "TextInput disabled" );
313 if( NULL != mImpl->mEventData )
315 mImpl->mEventData->mCursorBlinkEnabled = enable;
318 mImpl->mEventData->mDecorator )
320 mImpl->mEventData->mDecorator->StopCursorBlink();
325 bool Controller::GetEnableCursorBlink() const
327 if( NULL != mImpl->mEventData )
329 return mImpl->mEventData->mCursorBlinkEnabled;
335 void Controller::SetMultiLineEnabled( bool enable )
337 const Layout::Engine::Type layout = enable ? Layout::Engine::MULTI_LINE_BOX : Layout::Engine::SINGLE_LINE_BOX;
339 if( layout != mImpl->mLayoutEngine.GetLayout() )
341 // Set the layout type.
342 mImpl->mLayoutEngine.SetLayout( layout );
344 // Set the flags to redo the layout operations
345 const OperationsMask layoutOperations = static_cast<OperationsMask>( LAYOUT |
350 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
351 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | layoutOperations );
353 mImpl->RequestRelayout();
357 bool Controller::IsMultiLineEnabled() const
359 return Layout::Engine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
362 void Controller::SetHorizontalAlignment( Text::HorizontalAlignment::Type alignment )
364 if( alignment != mImpl->mModel->mHorizontalAlignment )
366 // Set the alignment.
367 mImpl->mModel->mHorizontalAlignment = alignment;
369 // Set the flag to redo the alignment operation.
370 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
372 mImpl->RequestRelayout();
376 Text::HorizontalAlignment::Type Controller::GetHorizontalAlignment() const
378 return mImpl->mModel->mHorizontalAlignment;
381 void Controller::SetVerticalAlignment( VerticalAlignment::Type alignment )
383 if( alignment != mImpl->mModel->mVerticalAlignment )
385 // Set the alignment.
386 mImpl->mModel->mVerticalAlignment = alignment;
388 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
390 mImpl->RequestRelayout();
394 VerticalAlignment::Type Controller::GetVerticalAlignment() const
396 return mImpl->mModel->mVerticalAlignment;
399 void Controller::SetLineWrapMode( Text::LineWrap::Mode lineWrapMode )
401 if( lineWrapMode != mImpl->mModel->mLineWrapMode )
403 // Set the text wrap mode.
404 mImpl->mModel->mLineWrapMode = lineWrapMode;
407 // Update Text layout for applying wrap mode
408 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
413 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
414 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
415 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
418 mImpl->RequestRelayout();
422 Text::LineWrap::Mode Controller::GetLineWrapMode() const
424 return mImpl->mModel->mLineWrapMode;
427 void Controller::SetTextElideEnabled( bool enabled )
429 mImpl->mModel->mElideEnabled = enabled;
432 bool Controller::IsTextElideEnabled() const
434 return mImpl->mModel->mElideEnabled;
437 void Controller::SetPlaceholderTextElideEnabled( bool enabled )
439 mImpl->mEventData->mIsPlaceholderElideEnabled = enabled;
440 mImpl->mEventData->mPlaceholderEllipsisFlag = true;
442 // Update placeholder if there is no text
443 if( mImpl->IsShowingPlaceholderText() ||
444 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
446 ShowPlaceholderText();
450 bool Controller::IsPlaceholderTextElideEnabled() const
452 return mImpl->mEventData->mIsPlaceholderElideEnabled;
455 void Controller::SetSelectionEnabled( bool enabled )
457 mImpl->mEventData->mSelectionEnabled = enabled;
460 bool Controller::IsSelectionEnabled() const
462 return mImpl->mEventData->mSelectionEnabled;
467 void Controller::SetText( const std::string& text )
469 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" );
471 // Reset keyboard as text changed
472 mImpl->ResetImfManager();
474 // Remove the previously set text and style.
480 CharacterIndex lastCursorIndex = 0u;
482 if( NULL != mImpl->mEventData )
484 // If popup shown then hide it by switching to Editing state
485 if( ( EventData::SELECTING == mImpl->mEventData->mState ) ||
486 ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
487 ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) ||
488 ( EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState ) )
490 mImpl->ChangeState( EventData::EDITING );
496 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mTextColor );
498 MarkupProcessData markupProcessData( mImpl->mModel->mLogicalModel->mColorRuns,
499 mImpl->mModel->mLogicalModel->mFontDescriptionRuns );
501 Length textSize = 0u;
502 const uint8_t* utf8 = NULL;
503 if( mImpl->mMarkupProcessorEnabled )
505 ProcessMarkupString( text, markupProcessData );
506 textSize = markupProcessData.markupProcessedText.size();
508 // This is a bit horrible but std::string returns a (signed) char*
509 utf8 = reinterpret_cast<const uint8_t*>( markupProcessData.markupProcessedText.c_str() );
513 textSize = text.size();
515 // This is a bit horrible but std::string returns a (signed) char*
516 utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
519 // Convert text into UTF-32
520 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
521 utf32Characters.Resize( textSize );
523 // Transform a text array encoded in utf8 into an array encoded in utf32.
524 // It returns the actual number of characters.
525 Length characterCount = Utf8ToUtf32( utf8, textSize, utf32Characters.Begin() );
526 utf32Characters.Resize( characterCount );
528 DALI_ASSERT_DEBUG( textSize >= characterCount && "Invalid UTF32 conversion length" );
529 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", this, textSize, mImpl->mModel->mLogicalModel->mText.Count() );
531 // The characters to be added.
532 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
534 // To reset the cursor position
535 lastCursorIndex = characterCount;
537 // Update the rest of the model during size negotiation
538 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
540 // The natural size needs to be re-calculated.
541 mImpl->mRecalculateNaturalSize = true;
543 // Apply modifications to the model
544 mImpl->mOperationsPending = ALL_OPERATIONS;
548 ShowPlaceholderText();
551 // Resets the cursor position.
552 ResetCursorPosition( lastCursorIndex );
554 // Scrolls the text to make the cursor visible.
555 ResetScrollPosition();
557 mImpl->RequestRelayout();
559 if( NULL != mImpl->mEventData )
561 // Cancel previously queued events
562 mImpl->mEventData->mEventQueue.clear();
565 // Do this last since it provides callbacks into application code.
566 if( NULL != mImpl->mEditableControlInterface )
568 mImpl->mEditableControlInterface->TextChanged();
572 void Controller::GetText( std::string& text ) const
574 if( !mImpl->IsShowingPlaceholderText() )
576 // Retrieves the text string.
577 mImpl->GetText( 0u, text );
581 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this );
585 void Controller::SetPlaceholderText( PlaceholderType type, const std::string& text )
587 if( NULL != mImpl->mEventData )
589 if( PLACEHOLDER_TYPE_INACTIVE == type )
591 mImpl->mEventData->mPlaceholderTextInactive = text;
595 mImpl->mEventData->mPlaceholderTextActive = text;
598 // Update placeholder if there is no text
599 if( mImpl->IsShowingPlaceholderText() ||
600 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
602 ShowPlaceholderText();
607 void Controller::GetPlaceholderText( PlaceholderType type, std::string& text ) const
609 if( NULL != mImpl->mEventData )
611 if( PLACEHOLDER_TYPE_INACTIVE == type )
613 text = mImpl->mEventData->mPlaceholderTextInactive;
617 text = mImpl->mEventData->mPlaceholderTextActive;
622 void Controller::UpdateAfterFontChange( const std::string& newDefaultFont )
624 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
626 if( !mImpl->mFontDefaults->familyDefined ) // If user defined font then should not update when system font changes
628 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
629 mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
633 mImpl->RequestRelayout();
637 // public : Default style & Input style
639 void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
641 if( NULL == mImpl->mFontDefaults )
643 mImpl->mFontDefaults = new FontDefaults();
646 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
647 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
648 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
650 // Clear the font-specific data
653 mImpl->RequestRelayout();
656 const std::string& Controller::GetDefaultFontFamily() const
658 if( NULL != mImpl->mFontDefaults )
660 return mImpl->mFontDefaults->mFontDescription.family;
666 void Controller::SetPlaceholderFontFamily( const std::string& placeholderTextFontFamily )
668 if( NULL != mImpl->mEventData )
670 if( NULL == mImpl->mEventData->mPlaceholderFont )
672 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
675 mImpl->mEventData->mPlaceholderFont->mFontDescription.family = placeholderTextFontFamily;
676 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetPlaceholderFontFamily %s\n", placeholderTextFontFamily.c_str());
677 mImpl->mEventData->mPlaceholderFont->familyDefined = !placeholderTextFontFamily.empty();
679 mImpl->RequestRelayout();
683 const std::string& Controller::GetPlaceholderFontFamily() const
685 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
687 return mImpl->mEventData->mPlaceholderFont->mFontDescription.family;
693 void Controller::SetDefaultFontWeight( FontWeight weight )
695 if( NULL == mImpl->mFontDefaults )
697 mImpl->mFontDefaults = new FontDefaults();
700 mImpl->mFontDefaults->mFontDescription.weight = weight;
701 mImpl->mFontDefaults->weightDefined = true;
703 // Clear the font-specific data
706 mImpl->RequestRelayout();
709 bool Controller::IsDefaultFontWeightDefined() const
711 if( NULL != mImpl->mFontDefaults )
713 return mImpl->mFontDefaults->weightDefined;
719 FontWeight Controller::GetDefaultFontWeight() const
721 if( NULL != mImpl->mFontDefaults )
723 return mImpl->mFontDefaults->mFontDescription.weight;
726 return TextAbstraction::FontWeight::NORMAL;
729 void Controller::SetPlaceholderTextFontWeight( FontWeight weight )
731 if( NULL != mImpl->mEventData )
733 if( NULL == mImpl->mEventData->mPlaceholderFont )
735 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
738 mImpl->mEventData->mPlaceholderFont->mFontDescription.weight = weight;
739 mImpl->mEventData->mPlaceholderFont->weightDefined = true;
741 mImpl->RequestRelayout();
745 bool Controller::IsPlaceholderTextFontWeightDefined() const
747 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
749 return mImpl->mEventData->mPlaceholderFont->weightDefined;
754 FontWeight Controller::GetPlaceholderTextFontWeight() const
756 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
758 return mImpl->mEventData->mPlaceholderFont->mFontDescription.weight;
761 return TextAbstraction::FontWeight::NORMAL;
764 void Controller::SetDefaultFontWidth( FontWidth width )
766 if( NULL == mImpl->mFontDefaults )
768 mImpl->mFontDefaults = new FontDefaults();
771 mImpl->mFontDefaults->mFontDescription.width = width;
772 mImpl->mFontDefaults->widthDefined = true;
774 // Clear the font-specific data
777 mImpl->RequestRelayout();
780 bool Controller::IsDefaultFontWidthDefined() const
782 if( NULL != mImpl->mFontDefaults )
784 return mImpl->mFontDefaults->widthDefined;
790 FontWidth Controller::GetDefaultFontWidth() const
792 if( NULL != mImpl->mFontDefaults )
794 return mImpl->mFontDefaults->mFontDescription.width;
797 return TextAbstraction::FontWidth::NORMAL;
800 void Controller::SetPlaceholderTextFontWidth( FontWidth width )
802 if( NULL != mImpl->mEventData )
804 if( NULL == mImpl->mEventData->mPlaceholderFont )
806 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
809 mImpl->mEventData->mPlaceholderFont->mFontDescription.width = width;
810 mImpl->mEventData->mPlaceholderFont->widthDefined = true;
812 mImpl->RequestRelayout();
816 bool Controller::IsPlaceholderTextFontWidthDefined() const
818 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
820 return mImpl->mEventData->mPlaceholderFont->widthDefined;
825 FontWidth Controller::GetPlaceholderTextFontWidth() const
827 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
829 return mImpl->mEventData->mPlaceholderFont->mFontDescription.width;
832 return TextAbstraction::FontWidth::NORMAL;
835 void Controller::SetDefaultFontSlant( FontSlant slant )
837 if( NULL == mImpl->mFontDefaults )
839 mImpl->mFontDefaults = new FontDefaults();
842 mImpl->mFontDefaults->mFontDescription.slant = slant;
843 mImpl->mFontDefaults->slantDefined = true;
845 // Clear the font-specific data
848 mImpl->RequestRelayout();
851 bool Controller::IsDefaultFontSlantDefined() const
853 if( NULL != mImpl->mFontDefaults )
855 return mImpl->mFontDefaults->slantDefined;
860 FontSlant Controller::GetDefaultFontSlant() const
862 if( NULL != mImpl->mFontDefaults )
864 return mImpl->mFontDefaults->mFontDescription.slant;
867 return TextAbstraction::FontSlant::NORMAL;
870 void Controller::SetPlaceholderTextFontSlant( FontSlant slant )
872 if( NULL != mImpl->mEventData )
874 if( NULL == mImpl->mEventData->mPlaceholderFont )
876 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
879 mImpl->mEventData->mPlaceholderFont->mFontDescription.slant = slant;
880 mImpl->mEventData->mPlaceholderFont->slantDefined = true;
882 mImpl->RequestRelayout();
886 bool Controller::IsPlaceholderTextFontSlantDefined() const
888 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
890 return mImpl->mEventData->mPlaceholderFont->slantDefined;
895 FontSlant Controller::GetPlaceholderTextFontSlant() const
897 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
899 return mImpl->mEventData->mPlaceholderFont->mFontDescription.slant;
902 return TextAbstraction::FontSlant::NORMAL;
905 void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
907 if( NULL == mImpl->mFontDefaults )
909 mImpl->mFontDefaults = new FontDefaults();
916 mImpl->mFontDefaults->mDefaultPointSize = fontSize;
917 mImpl->mFontDefaults->sizeDefined = true;
922 // Point size = Pixel size * 72.f / DPI
923 unsigned int horizontalDpi = 0u;
924 unsigned int verticalDpi = 0u;
925 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
926 fontClient.GetDpi( horizontalDpi, verticalDpi );
928 mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
929 mImpl->mFontDefaults->sizeDefined = true;
934 // Clear the font-specific data
937 mImpl->RequestRelayout();
940 float Controller::GetDefaultFontSize( FontSizeType type ) const
943 if( NULL != mImpl->mFontDefaults )
949 value = mImpl->mFontDefaults->mDefaultPointSize;
954 // Pixel size = Point size * DPI / 72.f
955 unsigned int horizontalDpi = 0u;
956 unsigned int verticalDpi = 0u;
957 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
958 fontClient.GetDpi( horizontalDpi, verticalDpi );
960 value = mImpl->mFontDefaults->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
970 void Controller::SetPlaceholderTextFontSize( float fontSize, FontSizeType type )
972 if( NULL != mImpl->mEventData )
974 if( NULL == mImpl->mEventData->mPlaceholderFont )
976 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
983 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = fontSize;
984 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
985 mImpl->mEventData->mIsPlaceholderPixelSize = false; // Font size flag
990 // Point size = Pixel size * 72.f / DPI
991 unsigned int horizontalDpi = 0u;
992 unsigned int verticalDpi = 0u;
993 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
994 fontClient.GetDpi( horizontalDpi, verticalDpi );
996 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
997 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
998 mImpl->mEventData->mIsPlaceholderPixelSize = true; // Font size flag
1003 mImpl->RequestRelayout();
1007 float Controller::GetPlaceholderTextFontSize( FontSizeType type ) const
1010 if( NULL != mImpl->mEventData )
1016 if( NULL != mImpl->mEventData->mPlaceholderFont )
1018 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize;
1022 // If the placeholder text font size is not set, then return the default font size.
1023 value = GetDefaultFontSize( POINT_SIZE );
1029 if( NULL != mImpl->mEventData->mPlaceholderFont )
1031 // Pixel size = Point size * DPI / 72.f
1032 unsigned int horizontalDpi = 0u;
1033 unsigned int verticalDpi = 0u;
1034 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1035 fontClient.GetDpi( horizontalDpi, verticalDpi );
1037 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1041 // If the placeholder text font size is not set, then return the default font size.
1042 value = GetDefaultFontSize( PIXEL_SIZE );
1053 void Controller::SetDefaultColor( const Vector4& color )
1055 mImpl->mTextColor = color;
1057 if( !mImpl->IsShowingPlaceholderText() )
1059 mImpl->mModel->mVisualModel->SetTextColor( color );
1061 mImpl->RequestRelayout();
1065 const Vector4& Controller::GetDefaultColor() const
1067 return mImpl->mTextColor;
1070 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
1072 if( NULL != mImpl->mEventData )
1074 mImpl->mEventData->mPlaceholderTextColor = textColor;
1077 if( mImpl->IsShowingPlaceholderText() )
1079 mImpl->mModel->mVisualModel->SetTextColor( textColor );
1080 mImpl->RequestRelayout();
1084 const Vector4& Controller::GetPlaceholderTextColor() const
1086 if( NULL != mImpl->mEventData )
1088 return mImpl->mEventData->mPlaceholderTextColor;
1091 return Color::BLACK;
1094 void Controller::SetShadowOffset( const Vector2& shadowOffset )
1096 mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
1098 mImpl->RequestRelayout();
1101 const Vector2& Controller::GetShadowOffset() const
1103 return mImpl->mModel->mVisualModel->GetShadowOffset();
1106 void Controller::SetShadowColor( const Vector4& shadowColor )
1108 mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
1110 mImpl->RequestRelayout();
1113 const Vector4& Controller::GetShadowColor() const
1115 return mImpl->mModel->mVisualModel->GetShadowColor();
1118 void Controller::SetShadowBlurRadius( const float& shadowBlurRadius )
1120 if ( fabsf( GetShadowBlurRadius() - shadowBlurRadius ) > Math::MACHINE_EPSILON_1 )
1122 mImpl->mModel->mVisualModel->SetShadowBlurRadius( shadowBlurRadius );
1124 mImpl->RequestRelayout();
1128 const float& Controller::GetShadowBlurRadius() const
1130 return mImpl->mModel->mVisualModel->GetShadowBlurRadius();
1133 void Controller::SetUnderlineColor( const Vector4& color )
1135 mImpl->mModel->mVisualModel->SetUnderlineColor( color );
1137 mImpl->RequestRelayout();
1140 const Vector4& Controller::GetUnderlineColor() const
1142 return mImpl->mModel->mVisualModel->GetUnderlineColor();
1145 void Controller::SetUnderlineEnabled( bool enabled )
1147 mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
1149 mImpl->RequestRelayout();
1152 bool Controller::IsUnderlineEnabled() const
1154 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
1157 void Controller::SetUnderlineHeight( float height )
1159 mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
1161 mImpl->RequestRelayout();
1164 float Controller::GetUnderlineHeight() const
1166 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
1169 void Controller::SetOutlineColor( const Vector4& color )
1171 mImpl->mModel->mVisualModel->SetOutlineColor( color );
1173 mImpl->RequestRelayout();
1176 const Vector4& Controller::GetOutlineColor() const
1178 return mImpl->mModel->mVisualModel->GetOutlineColor();
1181 void Controller::SetOutlineWidth( float width )
1183 mImpl->mModel->mVisualModel->SetOutlineWidth( width );
1185 mImpl->RequestRelayout();
1188 float Controller::GetOutlineWidth() const
1190 return mImpl->mModel->mVisualModel->GetOutlineWidth();
1193 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
1195 if( NULL == mImpl->mEmbossDefaults )
1197 mImpl->mEmbossDefaults = new EmbossDefaults();
1200 mImpl->mEmbossDefaults->properties = embossProperties;
1203 const std::string& Controller::GetDefaultEmbossProperties() const
1205 if( NULL != mImpl->mEmbossDefaults )
1207 return mImpl->mEmbossDefaults->properties;
1210 return EMPTY_STRING;
1213 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
1215 if( NULL == mImpl->mOutlineDefaults )
1217 mImpl->mOutlineDefaults = new OutlineDefaults();
1220 mImpl->mOutlineDefaults->properties = outlineProperties;
1223 const std::string& Controller::GetDefaultOutlineProperties() const
1225 if( NULL != mImpl->mOutlineDefaults )
1227 return mImpl->mOutlineDefaults->properties;
1230 return EMPTY_STRING;
1233 void Controller::SetDefaultLineSpacing( float lineSpacing )
1235 //TODO finish implementation
1236 mImpl->mLayoutEngine.SetDefaultLineSpacing( lineSpacing );
1239 float Controller::GetDefaultLineSpacing() const
1241 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
1244 void Controller::SetInputColor( const Vector4& color )
1246 if( NULL != mImpl->mEventData )
1248 mImpl->mEventData->mInputStyle.textColor = color;
1249 mImpl->mEventData->mInputStyle.isDefaultColor = false;
1251 if( EventData::SELECTING == mImpl->mEventData->mState )
1253 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
1255 // Get start and end position of selection
1256 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
1257 const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
1259 // Add the color run.
1260 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1261 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
1263 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
1264 colorRun.color = color;
1265 colorRun.characterRun.characterIndex = startOfSelectedText;
1266 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1268 // Request to relayout.
1269 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1270 mImpl->RequestRelayout();
1272 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1273 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1274 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1279 const Vector4& Controller::GetInputColor() const
1281 if( NULL != mImpl->mEventData )
1283 return mImpl->mEventData->mInputStyle.textColor;
1286 // Return the default text's color if there is no EventData.
1287 return mImpl->mTextColor;
1291 void Controller::SetInputFontFamily( const std::string& fontFamily )
1293 if( NULL != mImpl->mEventData )
1295 mImpl->mEventData->mInputStyle.familyName = fontFamily;
1296 mImpl->mEventData->mInputStyle.isFamilyDefined = true;
1298 if( EventData::SELECTING == mImpl->mEventData->mState )
1300 CharacterIndex startOfSelectedText = 0u;
1301 Length lengthOfSelectedText = 0u;
1302 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1303 mImpl->mModel->mLogicalModel,
1304 startOfSelectedText,
1305 lengthOfSelectedText );
1307 fontDescriptionRun.familyLength = fontFamily.size();
1308 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
1309 memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength );
1310 fontDescriptionRun.familyDefined = true;
1312 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
1314 // Request to relayout.
1315 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1320 UPDATE_LAYOUT_SIZE |
1323 mImpl->mRecalculateNaturalSize = true;
1324 mImpl->RequestRelayout();
1326 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1327 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1328 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1330 // As the font changes, recalculate the handle positions is needed.
1331 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1332 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1333 mImpl->mEventData->mUpdateHighlightBox = true;
1334 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1339 const std::string& Controller::GetInputFontFamily() const
1341 if( NULL != mImpl->mEventData )
1343 return mImpl->mEventData->mInputStyle.familyName;
1346 // Return the default font's family if there is no EventData.
1347 return GetDefaultFontFamily();
1350 void Controller::SetInputFontWeight( FontWeight weight )
1352 if( NULL != mImpl->mEventData )
1354 mImpl->mEventData->mInputStyle.weight = weight;
1355 mImpl->mEventData->mInputStyle.isWeightDefined = true;
1357 if( EventData::SELECTING == mImpl->mEventData->mState )
1359 CharacterIndex startOfSelectedText = 0u;
1360 Length lengthOfSelectedText = 0u;
1361 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1362 mImpl->mModel->mLogicalModel,
1363 startOfSelectedText,
1364 lengthOfSelectedText );
1366 fontDescriptionRun.weight = weight;
1367 fontDescriptionRun.weightDefined = true;
1369 // Request to relayout.
1370 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1375 UPDATE_LAYOUT_SIZE |
1378 mImpl->mRecalculateNaturalSize = true;
1379 mImpl->RequestRelayout();
1381 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1382 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1383 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1385 // As the font might change, recalculate the handle positions is needed.
1386 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1387 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1388 mImpl->mEventData->mUpdateHighlightBox = true;
1389 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1394 bool Controller::IsInputFontWeightDefined() const
1396 bool defined = false;
1398 if( NULL != mImpl->mEventData )
1400 defined = mImpl->mEventData->mInputStyle.isWeightDefined;
1406 FontWeight Controller::GetInputFontWeight() const
1408 if( NULL != mImpl->mEventData )
1410 return mImpl->mEventData->mInputStyle.weight;
1413 return GetDefaultFontWeight();
1416 void Controller::SetInputFontWidth( FontWidth width )
1418 if( NULL != mImpl->mEventData )
1420 mImpl->mEventData->mInputStyle.width = width;
1421 mImpl->mEventData->mInputStyle.isWidthDefined = true;
1423 if( EventData::SELECTING == mImpl->mEventData->mState )
1425 CharacterIndex startOfSelectedText = 0u;
1426 Length lengthOfSelectedText = 0u;
1427 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1428 mImpl->mModel->mLogicalModel,
1429 startOfSelectedText,
1430 lengthOfSelectedText );
1432 fontDescriptionRun.width = width;
1433 fontDescriptionRun.widthDefined = true;
1435 // Request to relayout.
1436 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1441 UPDATE_LAYOUT_SIZE |
1444 mImpl->mRecalculateNaturalSize = true;
1445 mImpl->RequestRelayout();
1447 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1448 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1449 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1451 // As the font might change, recalculate the handle positions is needed.
1452 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1453 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1454 mImpl->mEventData->mUpdateHighlightBox = true;
1455 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1460 bool Controller::IsInputFontWidthDefined() const
1462 bool defined = false;
1464 if( NULL != mImpl->mEventData )
1466 defined = mImpl->mEventData->mInputStyle.isWidthDefined;
1472 FontWidth Controller::GetInputFontWidth() const
1474 if( NULL != mImpl->mEventData )
1476 return mImpl->mEventData->mInputStyle.width;
1479 return GetDefaultFontWidth();
1482 void Controller::SetInputFontSlant( FontSlant slant )
1484 if( NULL != mImpl->mEventData )
1486 mImpl->mEventData->mInputStyle.slant = slant;
1487 mImpl->mEventData->mInputStyle.isSlantDefined = true;
1489 if( EventData::SELECTING == mImpl->mEventData->mState )
1491 CharacterIndex startOfSelectedText = 0u;
1492 Length lengthOfSelectedText = 0u;
1493 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1494 mImpl->mModel->mLogicalModel,
1495 startOfSelectedText,
1496 lengthOfSelectedText );
1498 fontDescriptionRun.slant = slant;
1499 fontDescriptionRun.slantDefined = true;
1501 // Request to relayout.
1502 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1507 UPDATE_LAYOUT_SIZE |
1510 mImpl->mRecalculateNaturalSize = true;
1511 mImpl->RequestRelayout();
1513 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1514 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1515 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1517 // As the font might change, recalculate the handle positions is needed.
1518 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1519 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1520 mImpl->mEventData->mUpdateHighlightBox = true;
1521 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1526 bool Controller::IsInputFontSlantDefined() const
1528 bool defined = false;
1530 if( NULL != mImpl->mEventData )
1532 defined = mImpl->mEventData->mInputStyle.isSlantDefined;
1538 FontSlant Controller::GetInputFontSlant() const
1540 if( NULL != mImpl->mEventData )
1542 return mImpl->mEventData->mInputStyle.slant;
1545 return GetDefaultFontSlant();
1548 void Controller::SetInputFontPointSize( float size )
1550 if( NULL != mImpl->mEventData )
1552 mImpl->mEventData->mInputStyle.size = size;
1553 mImpl->mEventData->mInputStyle.isSizeDefined = true;
1555 if( EventData::SELECTING == mImpl->mEventData->mState )
1557 CharacterIndex startOfSelectedText = 0u;
1558 Length lengthOfSelectedText = 0u;
1559 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1560 mImpl->mModel->mLogicalModel,
1561 startOfSelectedText,
1562 lengthOfSelectedText );
1564 fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
1565 fontDescriptionRun.sizeDefined = true;
1567 // Request to relayout.
1568 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1573 UPDATE_LAYOUT_SIZE |
1576 mImpl->mRecalculateNaturalSize = true;
1577 mImpl->RequestRelayout();
1579 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1580 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1581 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1583 // As the font might change, recalculate the handle positions is needed.
1584 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1585 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1586 mImpl->mEventData->mUpdateHighlightBox = true;
1587 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1592 float Controller::GetInputFontPointSize() const
1594 if( NULL != mImpl->mEventData )
1596 return mImpl->mEventData->mInputStyle.size;
1599 // Return the default font's point size if there is no EventData.
1600 return GetDefaultFontSize( Text::Controller::POINT_SIZE );
1603 void Controller::SetInputLineSpacing( float lineSpacing )
1605 if( NULL != mImpl->mEventData )
1607 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1608 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1612 float Controller::GetInputLineSpacing() const
1614 if( NULL != mImpl->mEventData )
1616 return mImpl->mEventData->mInputStyle.lineSpacing;
1622 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1624 if( NULL != mImpl->mEventData )
1626 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1630 const std::string& Controller::GetInputShadowProperties() const
1632 if( NULL != mImpl->mEventData )
1634 return mImpl->mEventData->mInputStyle.shadowProperties;
1637 return EMPTY_STRING;
1640 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1642 if( NULL != mImpl->mEventData )
1644 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1648 const std::string& Controller::GetInputUnderlineProperties() const
1650 if( NULL != mImpl->mEventData )
1652 return mImpl->mEventData->mInputStyle.underlineProperties;
1655 return EMPTY_STRING;
1658 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
1660 if( NULL != mImpl->mEventData )
1662 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1666 const std::string& Controller::GetInputEmbossProperties() const
1668 if( NULL != mImpl->mEventData )
1670 return mImpl->mEventData->mInputStyle.embossProperties;
1673 return GetDefaultEmbossProperties();
1676 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
1678 if( NULL != mImpl->mEventData )
1680 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1684 const std::string& Controller::GetInputOutlineProperties() const
1686 if( NULL != mImpl->mEventData )
1688 return mImpl->mEventData->mInputStyle.outlineProperties;
1691 return GetDefaultOutlineProperties();
1694 void Controller::SetInputModePassword( bool passwordInput )
1696 if( NULL != mImpl->mEventData )
1698 mImpl->mEventData->mPasswordInput = passwordInput;
1702 bool Controller::IsInputModePassword()
1704 if( NULL != mImpl->mEventData )
1706 return mImpl->mEventData->mPasswordInput;
1711 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
1713 if( NULL != mImpl->mEventData )
1715 mImpl->mEventData->mDoubleTapAction = action;
1719 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1721 NoTextTap::Action action = NoTextTap::NO_ACTION;
1723 if( NULL != mImpl->mEventData )
1725 action = mImpl->mEventData->mDoubleTapAction;
1731 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
1733 if( NULL != mImpl->mEventData )
1735 mImpl->mEventData->mLongPressAction = action;
1739 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1741 NoTextTap::Action action = NoTextTap::NO_ACTION;
1743 if( NULL != mImpl->mEventData )
1745 action = mImpl->mEventData->mLongPressAction;
1751 bool Controller::IsUnderlineSetByString()
1753 return mImpl->mUnderlineSetByString;
1756 void Controller::UnderlineSetByString( bool setByString )
1758 mImpl->mUnderlineSetByString = setByString;
1761 bool Controller::IsShadowSetByString()
1763 return mImpl->mShadowSetByString;
1766 void Controller::ShadowSetByString( bool setByString )
1768 mImpl->mShadowSetByString = setByString;
1771 bool Controller::IsOutlineSetByString()
1773 return mImpl->mOutlineSetByString;
1776 void Controller::OutlineSetByString( bool setByString )
1778 mImpl->mOutlineSetByString = setByString;
1781 bool Controller::IsFontStyleSetByString()
1783 return mImpl->mFontStyleSetByString;
1786 void Controller::FontStyleSetByString( bool setByString )
1788 mImpl->mFontStyleSetByString = setByString;
1791 // public : Queries & retrieves.
1793 Layout::Engine& Controller::GetLayoutEngine()
1795 return mImpl->mLayoutEngine;
1798 View& Controller::GetView()
1800 return mImpl->mView;
1803 Vector3 Controller::GetNaturalSize()
1805 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
1806 Vector3 naturalSize;
1808 // Make sure the model is up-to-date before layouting
1809 ProcessModifyEvents();
1811 if( mImpl->mRecalculateNaturalSize )
1813 // Operations that can be done only once until the text changes.
1814 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1821 GET_GLYPH_METRICS );
1823 // Set the update info to relayout the whole text.
1824 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1825 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1827 // Make sure the model is up-to-date before layouting
1828 mImpl->UpdateModel( onlyOnceOperations );
1830 // Layout the text for the new width.
1831 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT | REORDER );
1833 // Store the actual control's size to restore later.
1834 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
1836 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
1837 static_cast<OperationsMask>( onlyOnceOperations |
1839 naturalSize.GetVectorXY() );
1841 // Do not do again the only once operations.
1842 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1844 // Do the size related operations again.
1845 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1848 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1850 // Stores the natural size to avoid recalculate it again
1851 // unless the text/style changes.
1852 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
1854 mImpl->mRecalculateNaturalSize = false;
1856 // Clear the update info. This info will be set the next time the text is updated.
1857 mImpl->mTextUpdateInfo.Clear();
1859 // Restore the actual control's size.
1860 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
1862 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1866 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
1868 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1871 naturalSize.x = ConvertToEven( naturalSize.x );
1872 naturalSize.y = ConvertToEven( naturalSize.y );
1877 float Controller::GetHeightForWidth( float width )
1879 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
1880 // Make sure the model is up-to-date before layouting
1881 ProcessModifyEvents();
1884 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ||
1885 mImpl->mTextUpdateInfo.mFullRelayoutNeeded ||
1886 mImpl->mTextUpdateInfo.mClearAll )
1888 // Operations that can be done only once until the text changes.
1889 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1896 GET_GLYPH_METRICS );
1898 // Set the update info to relayout the whole text.
1899 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1900 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1902 // Make sure the model is up-to-date before layouting
1903 mImpl->UpdateModel( onlyOnceOperations );
1906 // Layout the text for the new width.
1907 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
1909 // Store the actual control's width.
1910 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
1912 DoRelayout( Size( width, MAX_FLOAT ),
1913 static_cast<OperationsMask>( onlyOnceOperations |
1917 // Do not do again the only once operations.
1918 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1920 // Do the size related operations again.
1921 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1925 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1927 // Clear the update info. This info will be set the next time the text is updated.
1928 mImpl->mTextUpdateInfo.Clear();
1930 // Restore the actual control's width.
1931 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
1933 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
1937 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
1938 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
1941 return layoutSize.height;
1944 int Controller::GetLineCount( float width )
1946 GetHeightForWidth( width );
1947 int numberofLines = mImpl->mModel->GetNumberOfLines();
1948 return numberofLines;
1951 const ModelInterface* const Controller::GetTextModel() const
1953 return mImpl->mModel.Get();
1956 float Controller::GetScrollAmountByUserInput()
1958 float scrollAmount = 0.0f;
1960 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
1962 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
1963 mImpl->mEventData->mCheckScrollAmount = false;
1965 return scrollAmount;
1968 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
1970 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
1973 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
1974 layoutHeight = layout.height;
1975 scrollPosition = mImpl->mModel->mScrollPosition.y;
1976 isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
1980 void Controller::SetHiddenInputOption(const Property::Map& options )
1982 if( NULL == mImpl->mHiddenInput )
1984 mImpl->mHiddenInput = new HiddenText( this );
1986 mImpl->mHiddenInput->SetProperties(options);
1989 void Controller::GetHiddenInputOption(Property::Map& options )
1991 if( NULL != mImpl->mHiddenInput )
1993 mImpl->mHiddenInput->GetProperties(options);
1997 void Controller::SetPlaceholderProperty( const Property::Map& map )
1999 const Property::Map::SizeType count = map.Count();
2001 for( Property::Map::SizeType position = 0; position < count; ++position )
2003 KeyValuePair keyValue = map.GetKeyValue( position );
2004 Property::Key& key = keyValue.first;
2005 Property::Value& value = keyValue.second;
2007 if( key == Toolkit::Text::PlaceHolder::Property::TEXT || key == PLACEHOLDER_TEXT )
2009 std::string text = "";
2011 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
2013 else if( key == Toolkit::Text::PlaceHolder::Property::TEXT_FOCUSED || key == PLACEHOLDER_TEXT_FOCUSED )
2015 std::string text = "";
2017 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
2019 else if( key == Toolkit::Text::PlaceHolder::Property::COLOR || key == PLACEHOLDER_COLOR )
2022 value.Get( textColor );
2023 if( GetPlaceholderTextColor() != textColor )
2025 SetPlaceholderTextColor( textColor );
2028 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_FAMILY || key == PLACEHOLDER_FONT_FAMILY )
2030 std::string fontFamily = "";
2031 value.Get( fontFamily );
2032 SetPlaceholderFontFamily( fontFamily );
2034 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_STYLE || key == PLACEHOLDER_FONT_STYLE )
2036 SetFontStyleProperty( this, value, Text::FontStyle::PLACEHOLDER );
2038 else if( key == Toolkit::Text::PlaceHolder::Property::POINT_SIZE || key == PLACEHOLDER_POINT_SIZE )
2041 value.Get( pointSize );
2042 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
2044 SetPlaceholderTextFontSize( pointSize, Text::Controller::POINT_SIZE );
2047 else if( key == Toolkit::Text::PlaceHolder::Property::PIXEL_SIZE || key == PLACEHOLDER_PIXEL_SIZE )
2050 value.Get( pixelSize );
2051 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
2053 SetPlaceholderTextFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
2056 else if( key == Toolkit::Text::PlaceHolder::Property::ELLIPSIS || key == PLACEHOLDER_ELLIPSIS )
2059 value.Get( ellipsis );
2060 SetPlaceholderTextElideEnabled( ellipsis );
2065 void Controller::GetPlaceholderProperty( Property::Map& map )
2067 if( NULL != mImpl->mEventData )
2069 if( !mImpl->mEventData->mPlaceholderTextActive.empty() )
2071 map[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = mImpl->mEventData->mPlaceholderTextActive;
2073 if( !mImpl->mEventData->mPlaceholderTextInactive.empty() )
2075 map[ Text::PlaceHolder::Property::TEXT ] = mImpl->mEventData->mPlaceholderTextInactive;
2078 map[ Text::PlaceHolder::Property::COLOR ] = mImpl->mEventData->mPlaceholderTextColor;
2079 map[ Text::PlaceHolder::Property::FONT_FAMILY ] = GetPlaceholderFontFamily();
2081 Property::Value fontStyleMapGet;
2082 GetFontStyleProperty( this, fontStyleMapGet, Text::FontStyle::PLACEHOLDER );
2083 map[ Text::PlaceHolder::Property::FONT_STYLE ] = fontStyleMapGet;
2085 // Choose font size : POINT_SIZE or PIXEL_SIZE
2086 if( !mImpl->mEventData->mIsPlaceholderPixelSize )
2088 map[ Text::PlaceHolder::Property::POINT_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE );
2092 map[ Text::PlaceHolder::Property::PIXEL_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE );
2095 if( mImpl->mEventData->mPlaceholderEllipsisFlag )
2097 map[ Text::PlaceHolder::Property::ELLIPSIS ] = IsPlaceholderTextElideEnabled();
2102 // public : Relayout.
2104 Controller::UpdateTextType Controller::Relayout( const Size& size )
2106 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
2108 UpdateTextType updateTextType = NONE_UPDATED;
2110 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
2112 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
2114 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
2115 updateTextType = MODEL_UPDATED;
2118 // Clear the update info. This info will be set the next time the text is updated.
2119 mImpl->mTextUpdateInfo.Clear();
2121 // Not worth to relayout if width or height is equal to zero.
2122 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
2124 return updateTextType;
2127 // Whether a new size has been set.
2128 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
2132 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
2134 // Layout operations that need to be done if the size changes.
2135 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2138 UPDATE_LAYOUT_SIZE |
2140 // Set the update info to relayout the whole text.
2141 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2142 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2144 // Store the size used to layout the text.
2145 mImpl->mModel->mVisualModel->mControlSize = size;
2148 // Whether there are modify events.
2149 if( 0u != mImpl->mModifyEvents.Count() )
2151 // Style operations that need to be done if the text is modified.
2152 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2156 // Set the update info to elide the text.
2157 if( mImpl->mModel->mElideEnabled ||
2158 ( ( NULL != mImpl->mEventData ) && mImpl->mEventData->mIsPlaceholderElideEnabled ) )
2160 // Update Text layout for applying elided
2161 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2164 UPDATE_LAYOUT_SIZE |
2166 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2167 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2170 // Make sure the model is up-to-date before layouting.
2171 ProcessModifyEvents();
2172 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
2176 updated = DoRelayout( size,
2177 mImpl->mOperationsPending,
2178 layoutSize ) || updated;
2182 updateTextType = MODEL_UPDATED;
2185 // Do not re-do any operation until something changes.
2186 mImpl->mOperationsPending = NO_OPERATION;
2187 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
2189 // Whether the text control is editable
2190 const bool isEditable = NULL != mImpl->mEventData;
2192 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
2194 if( newSize && isEditable )
2196 offset = mImpl->mModel->mScrollPosition;
2199 if( !isEditable || !IsMultiLineEnabled() )
2201 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
2202 CalculateVerticalOffset( size );
2209 // If there is a new size, the scroll position needs to be clamped.
2210 mImpl->ClampHorizontalScroll( layoutSize );
2212 // Update the decorator's positions is needed if there is a new size.
2213 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
2216 // Move the cursor, grab handle etc.
2217 if( mImpl->ProcessInputEvents() )
2219 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
2223 // Clear the update info. This info will be set the next time the text is updated.
2224 mImpl->mTextUpdateInfo.Clear();
2225 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
2227 return updateTextType;
2230 void Controller::RequestRelayout()
2232 mImpl->RequestRelayout();
2235 // public : Input style change signals.
2237 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
2239 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
2242 void Controller::ProcessInputStyleChangedSignals()
2244 if( NULL == mImpl->mEventData )
2250 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
2251 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
2255 const InputStyle::Mask mask = *it;
2257 if( NULL != mImpl->mEditableControlInterface )
2259 // Emit the input style changed signal.
2260 mImpl->mEditableControlInterface->InputStyleChanged( mask );
2264 mImpl->mEventData->mInputStyleChangedQueue.Clear();
2267 // public : Text-input Event Queuing.
2269 void Controller::KeyboardFocusGainEvent()
2271 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
2273 if( NULL != mImpl->mEventData )
2275 if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
2276 ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
2278 mImpl->ChangeState( EventData::EDITING );
2279 mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
2280 mImpl->mEventData->mUpdateInputStyle = true;
2282 mImpl->NotifyImfMultiLineStatus();
2283 if( mImpl->IsShowingPlaceholderText() )
2285 // Show alternative placeholder-text when editing
2286 ShowPlaceholderText();
2289 mImpl->RequestRelayout();
2293 void Controller::KeyboardFocusLostEvent()
2295 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
2297 if( NULL != mImpl->mEventData )
2299 if( EventData::INTERRUPTED != mImpl->mEventData->mState )
2301 mImpl->ChangeState( EventData::INACTIVE );
2303 if( !mImpl->IsShowingRealText() )
2305 // Revert to regular placeholder-text when not editing
2306 ShowPlaceholderText();
2310 mImpl->RequestRelayout();
2313 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
2315 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
2317 bool textChanged = false;
2318 bool relayoutNeeded = false;
2320 if( ( NULL != mImpl->mEventData ) &&
2321 ( keyEvent.state == KeyEvent::Down ) )
2323 int keyCode = keyEvent.keyCode;
2324 const std::string& keyString = keyEvent.keyPressed;
2326 const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
2328 // Pre-process to separate modifying events from non-modifying input events.
2331 // In some platforms arrive key events with no key code.
2335 else if( Dali::DALI_KEY_ESCAPE == keyCode || Dali::DALI_KEY_BACK == keyCode || Dali::DALI_KEY_SEARCH == keyCode )
2340 else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) ||
2341 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
2342 ( Dali::DALI_KEY_CURSOR_UP == keyCode ) ||
2343 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) )
2345 // If don't have any text, do nothing.
2346 if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
2351 uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition;
2352 uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2353 uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition );
2354 uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines();
2356 // Logic to determine whether this text control will lose focus or not.
2357 if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition ) ||
2358 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition) ||
2359 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) ||
2360 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) ||
2361 ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) ||
2362 ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) )
2367 mImpl->mEventData->mCheckScrollAmount = true;
2368 Event event( Event::CURSOR_KEY_EVENT );
2369 event.p1.mInt = keyCode;
2370 mImpl->mEventData->mEventQueue.push_back( event );
2372 // Will request for relayout.
2373 relayoutNeeded = true;
2375 else if( ( Dali::DALI_KEY_BACKSPACE == keyCode ) ||
2376 ( Dali::DevelKey::DALI_KEY_DELETE == keyCode ) )
2378 textChanged = DeleteEvent( keyCode );
2380 // Will request for relayout.
2381 relayoutNeeded = true;
2383 else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
2384 IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
2385 IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
2387 // Power key/Menu/Home key behaviour does not allow edit mode to resume.
2388 mImpl->ChangeState( EventData::INACTIVE );
2390 // Will request for relayout.
2391 relayoutNeeded = true;
2393 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2395 else if( Dali::DALI_KEY_SHIFT_LEFT == keyCode )
2397 // DALI_KEY_SHIFT_LEFT is the key code for the Left Shift. It's sent (by the imf?) when the predictive text is enabled
2398 // and a character is typed after the type of a upper case latin character.
2403 else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
2405 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2411 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
2413 // IMF manager is no longer handling key-events
2414 mImpl->ClearPreEditFlag();
2416 InsertText( keyString, COMMIT );
2419 // Will request for relayout.
2420 relayoutNeeded = true;
2423 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
2424 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
2426 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
2427 ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
2428 ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
2430 // Should not change the state if the key is the shift send by the imf manager.
2431 // Otherwise, when the state is SELECTING the text controller can't send the right
2432 // surrounding info to the imf.
2433 mImpl->ChangeState( EventData::EDITING );
2435 // Will request for relayout.
2436 relayoutNeeded = true;
2439 if( relayoutNeeded )
2441 mImpl->RequestRelayout();
2446 ( NULL != mImpl->mEditableControlInterface ) )
2448 // Do this last since it provides callbacks into application code
2449 mImpl->mEditableControlInterface->TextChanged();
2455 void Controller::TapEvent( unsigned int tapCount, float x, float y )
2457 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
2459 if( NULL != mImpl->mEventData )
2461 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
2462 EventData::State state( mImpl->mEventData->mState );
2463 bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
2465 if( mImpl->IsClipboardVisible() )
2467 if( EventData::INACTIVE == state || EventData::EDITING == state)
2469 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2471 relayoutNeeded = true;
2473 else if( 1u == tapCount )
2475 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
2477 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
2480 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
2482 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2483 relayoutNeeded = true;
2487 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
2489 // Hide placeholder text
2493 if( EventData::INACTIVE == state )
2495 mImpl->ChangeState( EventData::EDITING );
2497 else if( !mImpl->IsClipboardEmpty() )
2499 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
2501 relayoutNeeded = true;
2504 else if( 2u == tapCount )
2506 if( mImpl->mEventData->mSelectionEnabled &&
2507 mImpl->IsShowingRealText() )
2509 relayoutNeeded = true;
2510 mImpl->mEventData->mIsLeftHandleSelected = true;
2511 mImpl->mEventData->mIsRightHandleSelected = true;
2515 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
2516 if( relayoutNeeded )
2518 Event event( Event::TAP_EVENT );
2519 event.p1.mUint = tapCount;
2520 event.p2.mFloat = x;
2521 event.p3.mFloat = y;
2522 mImpl->mEventData->mEventQueue.push_back( event );
2524 mImpl->RequestRelayout();
2528 // Reset keyboard as tap event has occurred.
2529 mImpl->ResetImfManager();
2532 void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
2534 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
2536 if( NULL != mImpl->mEventData )
2538 Event event( Event::PAN_EVENT );
2539 event.p1.mInt = state;
2540 event.p2.mFloat = displacement.x;
2541 event.p3.mFloat = displacement.y;
2542 mImpl->mEventData->mEventQueue.push_back( event );
2544 mImpl->RequestRelayout();
2548 void Controller::LongPressEvent( Gesture::State state, float x, float y )
2550 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
2552 if( ( state == Gesture::Started ) &&
2553 ( NULL != mImpl->mEventData ) )
2555 // The 1st long-press on inactive text-field is treated as tap
2556 if( EventData::INACTIVE == mImpl->mEventData->mState )
2558 mImpl->ChangeState( EventData::EDITING );
2560 Event event( Event::TAP_EVENT );
2562 event.p2.mFloat = x;
2563 event.p3.mFloat = y;
2564 mImpl->mEventData->mEventQueue.push_back( event );
2566 mImpl->RequestRelayout();
2568 else if( !mImpl->IsShowingRealText() )
2570 Event event( Event::LONG_PRESS_EVENT );
2571 event.p1.mInt = state;
2572 event.p2.mFloat = x;
2573 event.p3.mFloat = y;
2574 mImpl->mEventData->mEventQueue.push_back( event );
2575 mImpl->RequestRelayout();
2577 else if( !mImpl->IsClipboardVisible() )
2579 // Reset the imf manager to commit the pre-edit before selecting the text.
2580 mImpl->ResetImfManager();
2582 Event event( Event::LONG_PRESS_EVENT );
2583 event.p1.mInt = state;
2584 event.p2.mFloat = x;
2585 event.p3.mFloat = y;
2586 mImpl->mEventData->mEventQueue.push_back( event );
2587 mImpl->RequestRelayout();
2589 mImpl->mEventData->mIsLeftHandleSelected = true;
2590 mImpl->mEventData->mIsRightHandleSelected = true;
2595 ImfManager::ImfCallbackData Controller::OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
2597 // Whether the text needs to be relaid-out.
2598 bool requestRelayout = false;
2600 // Whether to retrieve the text and cursor position to be sent to the IMF manager.
2601 bool retrieveText = false;
2602 bool retrieveCursor = false;
2604 switch( imfEvent.eventName )
2606 case ImfManager::COMMIT:
2608 InsertText( imfEvent.predictiveString, Text::Controller::COMMIT );
2609 requestRelayout = true;
2610 retrieveCursor = true;
2613 case ImfManager::PREEDIT:
2615 InsertText( imfEvent.predictiveString, Text::Controller::PRE_EDIT );
2616 requestRelayout = true;
2617 retrieveCursor = true;
2620 case ImfManager::DELETESURROUNDING:
2622 const bool textDeleted = RemoveText( imfEvent.cursorOffset,
2623 imfEvent.numberOfChars,
2624 DONT_UPDATE_INPUT_STYLE );
2628 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2629 !mImpl->IsPlaceholderAvailable() )
2631 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2635 ShowPlaceholderText();
2637 mImpl->mEventData->mUpdateCursorPosition = true;
2638 mImpl->mEventData->mScrollAfterDelete = true;
2640 requestRelayout = true;
2644 case ImfManager::GETSURROUNDING:
2646 retrieveText = true;
2647 retrieveCursor = true;
2650 case ImfManager::PRIVATECOMMAND:
2652 // PRIVATECOMMAND event is just for getting the private command message
2653 retrieveText = true;
2654 retrieveCursor = true;
2657 case ImfManager::VOID:
2664 if( requestRelayout )
2666 mImpl->mOperationsPending = ALL_OPERATIONS;
2667 mImpl->RequestRelayout();
2671 CharacterIndex cursorPosition = 0u;
2672 Length numberOfWhiteSpaces = 0u;
2674 if( retrieveCursor )
2676 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
2678 cursorPosition = mImpl->GetLogicalCursorPosition();
2680 if( cursorPosition < numberOfWhiteSpaces )
2682 cursorPosition = 0u;
2686 cursorPosition -= numberOfWhiteSpaces;
2692 mImpl->GetText( numberOfWhiteSpaces, text );
2695 ImfManager::ImfCallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
2697 if( requestRelayout &&
2698 ( NULL != mImpl->mEditableControlInterface ) )
2700 // Do this last since it provides callbacks into application code
2701 mImpl->mEditableControlInterface->TextChanged();
2704 return callbackData;
2707 void Controller::PasteClipboardItemEvent()
2709 // Retrieve the clipboard contents first
2710 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
2711 std::string stringToPaste( notifier.GetContent() );
2713 // Commit the current pre-edit text; the contents of the clipboard should be appended
2714 mImpl->ResetImfManager();
2716 // Temporary disable hiding clipboard
2717 mImpl->SetClipboardHideEnable( false );
2720 PasteText( stringToPaste );
2722 mImpl->SetClipboardHideEnable( true );
2725 // protected : Inherit from Text::Decorator::ControllerInterface.
2727 void Controller::GetTargetSize( Vector2& targetSize )
2729 targetSize = mImpl->mModel->mVisualModel->mControlSize;
2732 void Controller::AddDecoration( Actor& actor, bool needsClipping )
2734 if( NULL != mImpl->mEditableControlInterface )
2736 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
2740 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
2742 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
2744 if( NULL != mImpl->mEventData )
2746 switch( handleType )
2750 Event event( Event::GRAB_HANDLE_EVENT );
2751 event.p1.mUint = state;
2752 event.p2.mFloat = x;
2753 event.p3.mFloat = y;
2755 mImpl->mEventData->mEventQueue.push_back( event );
2758 case LEFT_SELECTION_HANDLE:
2760 Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
2761 event.p1.mUint = state;
2762 event.p2.mFloat = x;
2763 event.p3.mFloat = y;
2765 mImpl->mEventData->mEventQueue.push_back( event );
2768 case RIGHT_SELECTION_HANDLE:
2770 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
2771 event.p1.mUint = state;
2772 event.p2.mFloat = x;
2773 event.p3.mFloat = y;
2775 mImpl->mEventData->mEventQueue.push_back( event );
2778 case LEFT_SELECTION_HANDLE_MARKER:
2779 case RIGHT_SELECTION_HANDLE_MARKER:
2781 // Markers do not move the handles.
2784 case HANDLE_TYPE_COUNT:
2786 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
2790 mImpl->RequestRelayout();
2794 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
2796 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
2798 if( NULL == mImpl->mEventData )
2805 case Toolkit::TextSelectionPopup::CUT:
2807 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
2808 mImpl->mOperationsPending = ALL_OPERATIONS;
2810 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2811 !mImpl->IsPlaceholderAvailable() )
2813 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2817 ShowPlaceholderText();
2820 mImpl->mEventData->mUpdateCursorPosition = true;
2821 mImpl->mEventData->mScrollAfterDelete = true;
2823 mImpl->RequestRelayout();
2825 if( NULL != mImpl->mEditableControlInterface )
2827 mImpl->mEditableControlInterface->TextChanged();
2831 case Toolkit::TextSelectionPopup::COPY:
2833 mImpl->SendSelectionToClipboard( false ); // Text not modified
2835 mImpl->mEventData->mUpdateCursorPosition = true;
2837 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
2840 case Toolkit::TextSelectionPopup::PASTE:
2842 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
2845 case Toolkit::TextSelectionPopup::SELECT:
2847 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
2849 if( mImpl->mEventData->mSelectionEnabled )
2851 // Creates a SELECT event.
2852 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
2856 case Toolkit::TextSelectionPopup::SELECT_ALL:
2858 // Creates a SELECT_ALL event
2859 SelectEvent( 0.f, 0.f, true );
2862 case Toolkit::TextSelectionPopup::CLIPBOARD:
2864 mImpl->ShowClipboard();
2867 case Toolkit::TextSelectionPopup::NONE:
2875 void Controller::DisplayTimeExpired()
2877 mImpl->mEventData->mUpdateCursorPosition = true;
2878 // Apply modifications to the model
2879 mImpl->mOperationsPending = ALL_OPERATIONS;
2881 mImpl->RequestRelayout();
2884 // private : Update.
2886 void Controller::InsertText( const std::string& text, Controller::InsertType type )
2888 bool removedPrevious = false;
2889 bool removedSelected = false;
2890 bool maxLengthReached = false;
2892 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
2894 if( NULL == mImpl->mEventData )
2899 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
2900 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
2901 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
2903 // TODO: At the moment the underline runs are only for pre-edit.
2904 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
2906 // Remove the previous IMF pre-edit.
2907 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
2909 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
2910 mImpl->mEventData->mPreEditLength,
2911 DONT_UPDATE_INPUT_STYLE );
2913 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
2914 mImpl->mEventData->mPreEditLength = 0u;
2918 // Remove the previous Selection.
2919 removedSelected = RemoveSelectedText();
2923 Vector<Character> utf32Characters;
2924 Length characterCount = 0u;
2928 // Convert text into UTF-32
2929 utf32Characters.Resize( text.size() );
2931 // This is a bit horrible but std::string returns a (signed) char*
2932 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
2934 // Transform a text array encoded in utf8 into an array encoded in utf32.
2935 // It returns the actual number of characters.
2936 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
2937 utf32Characters.Resize( characterCount );
2939 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
2940 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
2943 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
2945 // The placeholder text is no longer needed
2946 if( mImpl->IsShowingPlaceholderText() )
2951 mImpl->ChangeState( EventData::EDITING );
2953 // Handle the IMF (predicitive text) state changes
2954 if( COMMIT == type )
2956 // IMF manager is no longer handling key-events
2957 mImpl->ClearPreEditFlag();
2961 if( !mImpl->mEventData->mPreEditFlag )
2963 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
2965 // Record the start of the pre-edit text
2966 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
2969 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
2970 mImpl->mEventData->mPreEditFlag = true;
2972 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
2975 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
2977 // Restrict new text to fit within Maximum characters setting.
2978 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
2979 maxLengthReached = ( characterCount > maxSizeOfNewText );
2981 // The cursor position.
2982 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
2984 // Update the text's style.
2986 // Updates the text style runs by adding characters.
2987 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
2989 // Get the character index from the cursor index.
2990 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
2992 // Retrieve the text's style for the given index.
2994 mImpl->RetrieveDefaultInputStyle( style );
2995 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
2997 // Whether to add a new text color run.
2998 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor );
3000 // Whether to add a new font run.
3001 const bool addFontNameRun = style.familyName != mImpl->mEventData->mInputStyle.familyName;
3002 const bool addFontWeightRun = style.weight != mImpl->mEventData->mInputStyle.weight;
3003 const bool addFontWidthRun = style.width != mImpl->mEventData->mInputStyle.width;
3004 const bool addFontSlantRun = style.slant != mImpl->mEventData->mInputStyle.slant;
3005 const bool addFontSizeRun = style.size != mImpl->mEventData->mInputStyle.size;
3010 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
3011 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
3013 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
3014 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
3015 colorRun.characterRun.characterIndex = cursorIndex;
3016 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3019 if( addFontNameRun ||
3025 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
3026 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
3028 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
3030 if( addFontNameRun )
3032 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
3033 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
3034 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
3035 fontDescriptionRun.familyDefined = true;
3037 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
3040 if( addFontWeightRun )
3042 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
3043 fontDescriptionRun.weightDefined = true;
3046 if( addFontWidthRun )
3048 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
3049 fontDescriptionRun.widthDefined = true;
3052 if( addFontSlantRun )
3054 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
3055 fontDescriptionRun.slantDefined = true;
3058 if( addFontSizeRun )
3060 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
3061 fontDescriptionRun.sizeDefined = true;
3064 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
3065 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3068 // Insert at current cursor position.
3069 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
3071 if( cursorIndex < numberOfCharactersInModel )
3073 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3077 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3080 // Mark the first paragraph to be updated.
3081 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3083 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3084 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3085 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
3086 mImpl->mTextUpdateInfo.mClearAll = true;
3090 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3091 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
3094 // Update the cursor index.
3095 cursorIndex += maxSizeOfNewText;
3097 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 );
3100 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
3101 mImpl->IsPlaceholderAvailable() )
3103 // Show place-holder if empty after removing the pre-edit text
3104 ShowPlaceholderText();
3105 mImpl->mEventData->mUpdateCursorPosition = true;
3106 mImpl->ClearPreEditFlag();
3108 else if( removedPrevious ||
3110 ( 0 != utf32Characters.Count() ) )
3112 // Queue an inserted event
3113 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
3115 mImpl->mEventData->mUpdateCursorPosition = true;
3116 if( removedSelected )
3118 mImpl->mEventData->mScrollAfterDelete = true;
3122 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3126 if( maxLengthReached )
3128 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
3130 mImpl->ResetImfManager();
3132 if( NULL != mImpl->mEditableControlInterface )
3134 // Do this last since it provides callbacks into application code
3135 mImpl->mEditableControlInterface->MaxLengthReached();
3140 void Controller::PasteText( const std::string& stringToPaste )
3142 InsertText( stringToPaste, Text::Controller::COMMIT );
3143 mImpl->ChangeState( EventData::EDITING );
3144 mImpl->RequestRelayout();
3146 if( NULL != mImpl->mEditableControlInterface )
3148 // Do this last since it provides callbacks into application code
3149 mImpl->mEditableControlInterface->TextChanged();
3153 bool Controller::RemoveText( int cursorOffset,
3154 int numberOfCharacters,
3155 UpdateInputStyleType type )
3157 bool removed = false;
3159 if( NULL == mImpl->mEventData )
3164 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
3165 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
3167 if( !mImpl->IsShowingPlaceholderText() )
3169 // Delete at current cursor position
3170 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
3171 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3173 CharacterIndex cursorIndex = 0;
3175 // Validate the cursor position & number of characters
3176 if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
3178 cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
3181 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
3183 numberOfCharacters = currentText.Count() - cursorIndex;
3186 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.
3187 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
3189 // Mark the paragraphs to be updated.
3190 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3192 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3193 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3194 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
3195 mImpl->mTextUpdateInfo.mClearAll = true;
3199 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3200 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
3203 // Update the input style and remove the text's style before removing the text.
3205 if( UPDATE_INPUT_STYLE == type )
3207 // Keep a copy of the current input style.
3208 InputStyle currentInputStyle;
3209 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
3211 // Set first the default input style.
3212 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
3214 // Update the input style.
3215 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
3217 // Compare if the input style has changed.
3218 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
3220 if( hasInputStyleChanged )
3222 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
3223 // Queue the input style changed signal.
3224 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
3228 // Updates the text style runs by removing characters. Runs with no characters are removed.
3229 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
3231 // Remove the characters.
3232 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
3233 Vector<Character>::Iterator last = first + numberOfCharacters;
3235 currentText.Erase( first, last );
3237 // Cursor position retreat
3238 oldCursorIndex = cursorIndex;
3240 mImpl->mEventData->mScrollAfterDelete = true;
3242 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
3250 bool Controller::RemoveSelectedText()
3252 bool textRemoved( false );
3254 if( EventData::SELECTING == mImpl->mEventData->mState )
3256 std::string removedString;
3257 mImpl->RetrieveSelection( removedString, true );
3259 if( !removedString.empty() )
3262 mImpl->ChangeState( EventData::EDITING );
3269 // private : Relayout.
3271 bool Controller::DoRelayout( const Size& size,
3272 OperationsMask operationsRequired,
3275 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
3276 bool viewUpdated( false );
3278 // Calculate the operations to be done.
3279 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
3281 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
3282 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
3284 // Get the current layout size.
3285 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3287 if( NO_OPERATION != ( LAYOUT & operations ) )
3289 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
3291 // Some vectors with data needed to layout and reorder may be void
3292 // after the first time the text has been laid out.
3293 // Fill the vectors again.
3295 // Calculate the number of glyphs to layout.
3296 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
3297 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
3298 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
3299 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
3301 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
3302 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
3303 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
3304 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
3306 if( 0u == totalNumberOfGlyphs )
3308 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3310 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
3313 // Nothing else to do if there is no glyphs.
3314 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
3318 const Vector<LineBreakInfo>& lineBreakInfo = mImpl->mModel->mLogicalModel->mLineBreakInfo;
3319 const Vector<WordBreakInfo>& wordBreakInfo = mImpl->mModel->mLogicalModel->mWordBreakInfo;
3320 const Vector<CharacterDirection>& characterDirection = mImpl->mModel->mLogicalModel->mCharacterDirections;
3321 const Vector<GlyphInfo>& glyphs = mImpl->mModel->mVisualModel->mGlyphs;
3322 const Vector<CharacterIndex>& glyphsToCharactersMap = mImpl->mModel->mVisualModel->mGlyphsToCharacters;
3323 const Vector<Length>& charactersPerGlyph = mImpl->mModel->mVisualModel->mCharactersPerGlyph;
3324 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
3325 float outlineWidth = mImpl->mModel->GetOutlineWidth();
3327 // Set the layout parameters.
3328 Layout::Parameters layoutParameters( size,
3330 lineBreakInfo.Begin(),
3331 wordBreakInfo.Begin(),
3332 ( 0u != characterDirection.Count() ) ? characterDirection.Begin() : NULL,
3334 glyphsToCharactersMap.Begin(),
3335 charactersPerGlyph.Begin(),
3336 charactersToGlyphBuffer,
3337 glyphsPerCharacterBuffer,
3338 totalNumberOfGlyphs,
3339 mImpl->mModel->mHorizontalAlignment,
3340 mImpl->mModel->mLineWrapMode,
3343 // Resize the vector of positions to have the same size than the vector of glyphs.
3344 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
3345 glyphPositions.Resize( totalNumberOfGlyphs );
3347 // Whether the last character is a new paragraph character.
3348 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
3349 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
3351 // The initial glyph and the number of glyphs to layout.
3352 layoutParameters.startGlyphIndex = startGlyphIndex;
3353 layoutParameters.numberOfGlyphs = numberOfGlyphs;
3354 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
3355 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
3357 // Update the ellipsis
3358 bool elideTextEnabled = mImpl->mModel->mElideEnabled;
3360 if( NULL != mImpl->mEventData )
3362 if( mImpl->mEventData->mPlaceholderEllipsisFlag && mImpl->IsShowingPlaceholderText() )
3364 elideTextEnabled = mImpl->mEventData->mIsPlaceholderElideEnabled;
3366 else if( EventData::INACTIVE != mImpl->mEventData->mState )
3368 // Disable ellipsis when editing
3369 elideTextEnabled = false;
3372 // Reset the scroll position in inactive state
3373 if( elideTextEnabled && ( mImpl->mEventData->mState == EventData::INACTIVE ) )
3375 ResetScrollPosition();
3379 // Update the visual model.
3381 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
3383 mImpl->mModel->mVisualModel->mLines,
3387 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
3391 layoutSize = newLayoutSize;
3393 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
3395 mImpl->mAutoScrollDirectionRTL = false;
3398 // Reorder the lines
3399 if( NO_OPERATION != ( REORDER & operations ) )
3401 Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = mImpl->mModel->mLogicalModel->mBidirectionalParagraphInfo;
3402 Vector<BidirectionalLineInfoRun>& bidirectionalLineInfo = mImpl->mModel->mLogicalModel->mBidirectionalLineInfo;
3404 // Check first if there are paragraphs with bidirectional info.
3405 if( 0u != bidirectionalInfo.Count() )
3408 const Length numberOfLines = mImpl->mModel->mVisualModel->mLines.Count();
3410 // Reorder the lines.
3411 bidirectionalLineInfo.Reserve( numberOfLines ); // Reserve because is not known yet how many lines have right to left characters.
3412 ReorderLines( bidirectionalInfo,
3414 requestedNumberOfCharacters,
3415 mImpl->mModel->mVisualModel->mLines,
3416 bidirectionalLineInfo );
3418 // Set the bidirectional info per line into the layout parameters.
3419 layoutParameters.lineBidirectionalInfoRunsBuffer = bidirectionalLineInfo.Begin();
3420 layoutParameters.numberOfBidirectionalInfoRuns = bidirectionalLineInfo.Count();
3422 // Re-layout the text. Reorder those lines with right to left characters.
3423 mImpl->mLayoutEngine.ReLayoutRightToLeftLines( layoutParameters,
3425 requestedNumberOfCharacters,
3428 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && ( numberOfLines > 0 ) )
3430 const LineRun* const firstline = mImpl->mModel->mVisualModel->mLines.Begin();
3433 mImpl->mAutoScrollDirectionRTL = firstline->direction;
3439 // Sets the layout size.
3440 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3442 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
3447 if( NO_OPERATION != ( ALIGN & operations ) )
3449 // The laid-out lines.
3450 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
3452 // Need to align with the control's size as the text may contain lines
3453 // starting either with left to right text or right to left.
3454 mImpl->mLayoutEngine.Align( size,
3456 requestedNumberOfCharacters,
3457 mImpl->mModel->mHorizontalAlignment,
3459 mImpl->mModel->mAlignmentOffset );
3463 #if defined(DEBUG_ENABLED)
3464 std::string currentText;
3465 GetText( currentText );
3466 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mAutoScrollDirectionRTL[%s] [%s]\n", this, (mImpl->mAutoScrollDirectionRTL)?"true":"false", currentText.c_str() );
3468 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
3472 void Controller::CalculateVerticalOffset( const Size& controlSize )
3474 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3476 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
3478 // Get the line height of the default font.
3479 layoutSize.height = mImpl->GetDefaultFontLineHeight();
3482 switch( mImpl->mModel->mVerticalAlignment )
3484 case VerticalAlignment::TOP:
3486 mImpl->mModel->mScrollPosition.y = 0.f;
3489 case VerticalAlignment::CENTER:
3491 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
3494 case VerticalAlignment::BOTTOM:
3496 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
3502 // private : Events.
3504 void Controller::ProcessModifyEvents()
3506 Vector<ModifyEvent>& events = mImpl->mModifyEvents;
3508 if( 0u == events.Count() )
3514 for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
3515 endIt = events.End();
3519 const ModifyEvent& event = *it;
3521 if( ModifyEvent::TEXT_REPLACED == event.type )
3523 // A (single) replace event should come first, otherwise we wasted time processing NOOP events
3524 DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
3526 TextReplacedEvent();
3528 else if( ModifyEvent::TEXT_INSERTED == event.type )
3530 TextInsertedEvent();
3532 else if( ModifyEvent::TEXT_DELETED == event.type )
3534 // Placeholder-text cannot be deleted
3535 if( !mImpl->IsShowingPlaceholderText() )
3542 if( NULL != mImpl->mEventData )
3544 // When the text is being modified, delay cursor blinking
3545 mImpl->mEventData->mDecorator->DelayCursorBlink();
3548 // Discard temporary text
3552 void Controller::TextReplacedEvent()
3554 // The natural size needs to be re-calculated.
3555 mImpl->mRecalculateNaturalSize = true;
3557 // Apply modifications to the model
3558 mImpl->mOperationsPending = ALL_OPERATIONS;
3561 void Controller::TextInsertedEvent()
3563 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
3565 if( NULL == mImpl->mEventData )
3570 mImpl->mEventData->mCheckScrollAmount = true;
3572 // The natural size needs to be re-calculated.
3573 mImpl->mRecalculateNaturalSize = true;
3575 // Apply modifications to the model; TODO - Optimize this
3576 mImpl->mOperationsPending = ALL_OPERATIONS;
3579 void Controller::TextDeletedEvent()
3581 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
3583 if( NULL == mImpl->mEventData )
3588 mImpl->mEventData->mCheckScrollAmount = true;
3590 // The natural size needs to be re-calculated.
3591 mImpl->mRecalculateNaturalSize = true;
3593 // Apply modifications to the model; TODO - Optimize this
3594 mImpl->mOperationsPending = ALL_OPERATIONS;
3597 void Controller::SelectEvent( float x, float y, bool selectAll )
3599 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
3601 if( NULL != mImpl->mEventData )
3605 Event event( Event::SELECT_ALL );
3606 mImpl->mEventData->mEventQueue.push_back( event );
3610 Event event( Event::SELECT );
3611 event.p2.mFloat = x;
3612 event.p3.mFloat = y;
3613 mImpl->mEventData->mEventQueue.push_back( event );
3616 mImpl->mEventData->mCheckScrollAmount = true;
3617 mImpl->mEventData->mIsLeftHandleSelected = true;
3618 mImpl->mEventData->mIsRightHandleSelected = true;
3619 mImpl->RequestRelayout();
3623 bool Controller::DeleteEvent( int keyCode )
3625 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p KeyCode : %d \n", this, keyCode );
3627 bool removed = false;
3629 if( NULL == mImpl->mEventData )
3634 // IMF manager is no longer handling key-events
3635 mImpl->ClearPreEditFlag();
3637 if( EventData::SELECTING == mImpl->mEventData->mState )
3639 removed = RemoveSelectedText();
3641 else if( ( mImpl->mEventData->mPrimaryCursorPosition > 0 ) && ( keyCode == Dali::DALI_KEY_BACKSPACE) )
3643 // Remove the character before the current cursor position
3644 removed = RemoveText( -1,
3646 UPDATE_INPUT_STYLE );
3648 else if( ( mImpl->mEventData->mPrimaryCursorPosition >= 0 ) && ( keyCode == Dali::DevelKey::DALI_KEY_DELETE ) )
3650 // Remove the character after the current cursor position
3651 removed = RemoveText( 0,
3653 UPDATE_INPUT_STYLE );
3658 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3659 !mImpl->IsPlaceholderAvailable() )
3661 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3665 ShowPlaceholderText();
3667 mImpl->mEventData->mUpdateCursorPosition = true;
3668 mImpl->mEventData->mScrollAfterDelete = true;
3674 // private : Helpers.
3676 void Controller::ResetText()
3679 mImpl->mModel->mLogicalModel->mText.Clear();
3681 // We have cleared everything including the placeholder-text
3682 mImpl->PlaceholderCleared();
3684 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3685 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3686 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
3688 // Clear any previous text.
3689 mImpl->mTextUpdateInfo.mClearAll = true;
3691 // The natural size needs to be re-calculated.
3692 mImpl->mRecalculateNaturalSize = true;
3694 // Apply modifications to the model
3695 mImpl->mOperationsPending = ALL_OPERATIONS;
3698 void Controller::ShowPlaceholderText()
3700 if( mImpl->IsPlaceholderAvailable() )
3702 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
3704 if( NULL == mImpl->mEventData )
3709 mImpl->mEventData->mIsShowingPlaceholderText = true;
3711 // Disable handles when showing place-holder text
3712 mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
3713 mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
3714 mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
3716 const char* text( NULL );
3719 // TODO - Switch Placeholder text when changing state
3720 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
3721 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
3723 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
3724 size = mImpl->mEventData->mPlaceholderTextActive.size();
3728 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
3729 size = mImpl->mEventData->mPlaceholderTextInactive.size();
3732 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3733 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3735 // Reset model for showing placeholder.
3736 mImpl->mModel->mLogicalModel->mText.Clear();
3737 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
3739 // Convert text into UTF-32
3740 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
3741 utf32Characters.Resize( size );
3743 // This is a bit horrible but std::string returns a (signed) char*
3744 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
3746 // Transform a text array encoded in utf8 into an array encoded in utf32.
3747 // It returns the actual number of characters.
3748 const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
3749 utf32Characters.Resize( characterCount );
3751 // The characters to be added.
3752 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
3754 // Reset the cursor position
3755 mImpl->mEventData->mPrimaryCursorPosition = 0;
3757 // The natural size needs to be re-calculated.
3758 mImpl->mRecalculateNaturalSize = true;
3760 // Apply modifications to the model
3761 mImpl->mOperationsPending = ALL_OPERATIONS;
3763 // Update the rest of the model during size negotiation
3764 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
3768 void Controller::ClearFontData()
3770 if( mImpl->mFontDefaults )
3772 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
3775 // Set flags to update the model.
3776 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3777 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3778 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
3780 mImpl->mTextUpdateInfo.mClearAll = true;
3781 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
3782 mImpl->mRecalculateNaturalSize = true;
3784 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
3789 UPDATE_LAYOUT_SIZE |
3794 void Controller::ClearStyleData()
3796 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
3797 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
3800 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
3802 // Reset the cursor position
3803 if( NULL != mImpl->mEventData )
3805 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
3807 // Update the cursor if it's in editing mode.
3808 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
3810 mImpl->mEventData->mUpdateCursorPosition = true;
3815 void Controller::ResetScrollPosition()
3817 if( NULL != mImpl->mEventData )
3819 // Reset the scroll position.
3820 mImpl->mModel->mScrollPosition = Vector2::ZERO;
3821 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3825 void Controller::SetControlInterface( ControlInterface* controlInterface )
3827 mImpl->mControlInterface = controlInterface;
3830 bool Controller::ShouldClearFocusOnEscape() const
3832 return mImpl->mShouldClearFocusOnEscape;
3835 // private : Private contructors & copy operator.
3837 Controller::Controller()
3840 mImpl = new Controller::Impl( NULL, NULL );
3843 Controller::Controller( ControlInterface* controlInterface )
3845 mImpl = new Controller::Impl( controlInterface, NULL );
3848 Controller::Controller( ControlInterface* controlInterface,
3849 EditableControlInterface* editableControlInterface )
3851 mImpl = new Controller::Impl( controlInterface,
3852 editableControlInterface );
3855 // The copy constructor and operator are left unimplemented.
3857 // protected : Destructor.
3859 Controller::~Controller()
3866 } // namespace Toolkit