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->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | layoutOperations );
352 mImpl->RequestRelayout();
356 bool Controller::IsMultiLineEnabled() const
358 return Layout::Engine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
361 void Controller::SetHorizontalAlignment( Text::HorizontalAlignment::Type alignment )
363 if( alignment != mImpl->mModel->mHorizontalAlignment )
365 // Set the alignment.
366 mImpl->mModel->mHorizontalAlignment = alignment;
368 // Set the flag to redo the alignment operation.
369 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
371 mImpl->RequestRelayout();
375 Text::HorizontalAlignment::Type Controller::GetHorizontalAlignment() const
377 return mImpl->mModel->mHorizontalAlignment;
380 void Controller::SetVerticalAlignment( VerticalAlignment::Type alignment )
382 if( alignment != mImpl->mModel->mVerticalAlignment )
384 // Set the alignment.
385 mImpl->mModel->mVerticalAlignment = alignment;
387 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
389 mImpl->RequestRelayout();
393 VerticalAlignment::Type Controller::GetVerticalAlignment() const
395 return mImpl->mModel->mVerticalAlignment;
398 void Controller::SetLineWrapMode( Text::LineWrap::Mode lineWrapMode )
400 if( lineWrapMode != mImpl->mModel->mLineWrapMode )
402 // Set the text wrap mode.
403 mImpl->mModel->mLineWrapMode = lineWrapMode;
406 // Update Text layout for applying wrap mode
407 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
412 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
413 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
414 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
417 mImpl->RequestRelayout();
421 Text::LineWrap::Mode Controller::GetLineWrapMode() const
423 return mImpl->mModel->mLineWrapMode;
426 void Controller::SetTextElideEnabled( bool enabled )
428 mImpl->mModel->mElideEnabled = enabled;
431 bool Controller::IsTextElideEnabled() const
433 return mImpl->mModel->mElideEnabled;
436 void Controller::SetPlaceholderTextElideEnabled( bool enabled )
438 mImpl->mEventData->mIsPlaceholderElideEnabled = enabled;
439 mImpl->mEventData->mPlaceholderEllipsisFlag = true;
441 // Update placeholder if there is no text
442 if( mImpl->IsShowingPlaceholderText() ||
443 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
445 ShowPlaceholderText();
449 bool Controller::IsPlaceholderTextElideEnabled() const
451 return mImpl->mEventData->mIsPlaceholderElideEnabled;
454 void Controller::SetSelectionEnabled( bool enabled )
456 mImpl->mEventData->mSelectionEnabled = enabled;
459 bool Controller::IsSelectionEnabled() const
461 return mImpl->mEventData->mSelectionEnabled;
466 void Controller::SetText( const std::string& text )
468 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" );
470 // Reset keyboard as text changed
471 mImpl->ResetImfManager();
473 // Remove the previously set text and style.
479 CharacterIndex lastCursorIndex = 0u;
481 if( NULL != mImpl->mEventData )
483 // If popup shown then hide it by switching to Editing state
484 if( ( EventData::SELECTING == mImpl->mEventData->mState ) ||
485 ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
486 ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) ||
487 ( EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState ) )
489 mImpl->ChangeState( EventData::EDITING );
495 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mTextColor );
497 MarkupProcessData markupProcessData( mImpl->mModel->mLogicalModel->mColorRuns,
498 mImpl->mModel->mLogicalModel->mFontDescriptionRuns );
500 Length textSize = 0u;
501 const uint8_t* utf8 = NULL;
502 if( mImpl->mMarkupProcessorEnabled )
504 ProcessMarkupString( text, markupProcessData );
505 textSize = markupProcessData.markupProcessedText.size();
507 // This is a bit horrible but std::string returns a (signed) char*
508 utf8 = reinterpret_cast<const uint8_t*>( markupProcessData.markupProcessedText.c_str() );
512 textSize = text.size();
514 // This is a bit horrible but std::string returns a (signed) char*
515 utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
518 // Convert text into UTF-32
519 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
520 utf32Characters.Resize( textSize );
522 // Transform a text array encoded in utf8 into an array encoded in utf32.
523 // It returns the actual number of characters.
524 Length characterCount = Utf8ToUtf32( utf8, textSize, utf32Characters.Begin() );
525 utf32Characters.Resize( characterCount );
527 DALI_ASSERT_DEBUG( textSize >= characterCount && "Invalid UTF32 conversion length" );
528 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", this, textSize, mImpl->mModel->mLogicalModel->mText.Count() );
530 // The characters to be added.
531 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
533 // To reset the cursor position
534 lastCursorIndex = characterCount;
536 // Update the rest of the model during size negotiation
537 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
539 // The natural size needs to be re-calculated.
540 mImpl->mRecalculateNaturalSize = true;
542 // Apply modifications to the model
543 mImpl->mOperationsPending = ALL_OPERATIONS;
547 ShowPlaceholderText();
550 // Resets the cursor position.
551 ResetCursorPosition( lastCursorIndex );
553 // Scrolls the text to make the cursor visible.
554 ResetScrollPosition();
556 mImpl->RequestRelayout();
558 if( NULL != mImpl->mEventData )
560 // Cancel previously queued events
561 mImpl->mEventData->mEventQueue.clear();
564 // Do this last since it provides callbacks into application code.
565 if( NULL != mImpl->mEditableControlInterface )
567 mImpl->mEditableControlInterface->TextChanged();
571 void Controller::GetText( std::string& text ) const
573 if( !mImpl->IsShowingPlaceholderText() )
575 // Retrieves the text string.
576 mImpl->GetText( 0u, text );
580 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this );
584 void Controller::SetPlaceholderText( PlaceholderType type, const std::string& text )
586 if( NULL != mImpl->mEventData )
588 if( PLACEHOLDER_TYPE_INACTIVE == type )
590 mImpl->mEventData->mPlaceholderTextInactive = text;
594 mImpl->mEventData->mPlaceholderTextActive = text;
597 // Update placeholder if there is no text
598 if( mImpl->IsShowingPlaceholderText() ||
599 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
601 ShowPlaceholderText();
606 void Controller::GetPlaceholderText( PlaceholderType type, std::string& text ) const
608 if( NULL != mImpl->mEventData )
610 if( PLACEHOLDER_TYPE_INACTIVE == type )
612 text = mImpl->mEventData->mPlaceholderTextInactive;
616 text = mImpl->mEventData->mPlaceholderTextActive;
621 void Controller::UpdateAfterFontChange( const std::string& newDefaultFont )
623 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
625 if( !mImpl->mFontDefaults->familyDefined ) // If user defined font then should not update when system font changes
627 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
628 mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
632 mImpl->RequestRelayout();
636 // public : Default style & Input style
638 void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
640 if( NULL == mImpl->mFontDefaults )
642 mImpl->mFontDefaults = new FontDefaults();
645 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
646 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
647 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
649 // Clear the font-specific data
652 mImpl->RequestRelayout();
655 const std::string& Controller::GetDefaultFontFamily() const
657 if( NULL != mImpl->mFontDefaults )
659 return mImpl->mFontDefaults->mFontDescription.family;
665 void Controller::SetPlaceholderFontFamily( const std::string& placeholderTextFontFamily )
667 if( NULL != mImpl->mEventData )
669 if( NULL == mImpl->mEventData->mPlaceholderFont )
671 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
674 mImpl->mEventData->mPlaceholderFont->mFontDescription.family = placeholderTextFontFamily;
675 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetPlaceholderFontFamily %s\n", placeholderTextFontFamily.c_str());
676 mImpl->mEventData->mPlaceholderFont->familyDefined = !placeholderTextFontFamily.empty();
678 mImpl->RequestRelayout();
682 const std::string& Controller::GetPlaceholderFontFamily() const
684 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
686 return mImpl->mEventData->mPlaceholderFont->mFontDescription.family;
692 void Controller::SetDefaultFontWeight( FontWeight weight )
694 if( NULL == mImpl->mFontDefaults )
696 mImpl->mFontDefaults = new FontDefaults();
699 mImpl->mFontDefaults->mFontDescription.weight = weight;
700 mImpl->mFontDefaults->weightDefined = true;
702 // Clear the font-specific data
705 mImpl->RequestRelayout();
708 bool Controller::IsDefaultFontWeightDefined() const
710 if( NULL != mImpl->mFontDefaults )
712 return mImpl->mFontDefaults->weightDefined;
718 FontWeight Controller::GetDefaultFontWeight() const
720 if( NULL != mImpl->mFontDefaults )
722 return mImpl->mFontDefaults->mFontDescription.weight;
725 return TextAbstraction::FontWeight::NORMAL;
728 void Controller::SetPlaceholderTextFontWeight( FontWeight weight )
730 if( NULL != mImpl->mEventData )
732 if( NULL == mImpl->mEventData->mPlaceholderFont )
734 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
737 mImpl->mEventData->mPlaceholderFont->mFontDescription.weight = weight;
738 mImpl->mEventData->mPlaceholderFont->weightDefined = true;
740 mImpl->RequestRelayout();
744 bool Controller::IsPlaceholderTextFontWeightDefined() const
746 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
748 return mImpl->mEventData->mPlaceholderFont->weightDefined;
753 FontWeight Controller::GetPlaceholderTextFontWeight() const
755 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
757 return mImpl->mEventData->mPlaceholderFont->mFontDescription.weight;
760 return TextAbstraction::FontWeight::NORMAL;
763 void Controller::SetDefaultFontWidth( FontWidth width )
765 if( NULL == mImpl->mFontDefaults )
767 mImpl->mFontDefaults = new FontDefaults();
770 mImpl->mFontDefaults->mFontDescription.width = width;
771 mImpl->mFontDefaults->widthDefined = true;
773 // Clear the font-specific data
776 mImpl->RequestRelayout();
779 bool Controller::IsDefaultFontWidthDefined() const
781 if( NULL != mImpl->mFontDefaults )
783 return mImpl->mFontDefaults->widthDefined;
789 FontWidth Controller::GetDefaultFontWidth() const
791 if( NULL != mImpl->mFontDefaults )
793 return mImpl->mFontDefaults->mFontDescription.width;
796 return TextAbstraction::FontWidth::NORMAL;
799 void Controller::SetPlaceholderTextFontWidth( FontWidth width )
801 if( NULL != mImpl->mEventData )
803 if( NULL == mImpl->mEventData->mPlaceholderFont )
805 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
808 mImpl->mEventData->mPlaceholderFont->mFontDescription.width = width;
809 mImpl->mEventData->mPlaceholderFont->widthDefined = true;
811 mImpl->RequestRelayout();
815 bool Controller::IsPlaceholderTextFontWidthDefined() const
817 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
819 return mImpl->mEventData->mPlaceholderFont->widthDefined;
824 FontWidth Controller::GetPlaceholderTextFontWidth() const
826 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
828 return mImpl->mEventData->mPlaceholderFont->mFontDescription.width;
831 return TextAbstraction::FontWidth::NORMAL;
834 void Controller::SetDefaultFontSlant( FontSlant slant )
836 if( NULL == mImpl->mFontDefaults )
838 mImpl->mFontDefaults = new FontDefaults();
841 mImpl->mFontDefaults->mFontDescription.slant = slant;
842 mImpl->mFontDefaults->slantDefined = true;
844 // Clear the font-specific data
847 mImpl->RequestRelayout();
850 bool Controller::IsDefaultFontSlantDefined() const
852 if( NULL != mImpl->mFontDefaults )
854 return mImpl->mFontDefaults->slantDefined;
859 FontSlant Controller::GetDefaultFontSlant() const
861 if( NULL != mImpl->mFontDefaults )
863 return mImpl->mFontDefaults->mFontDescription.slant;
866 return TextAbstraction::FontSlant::NORMAL;
869 void Controller::SetPlaceholderTextFontSlant( FontSlant slant )
871 if( NULL != mImpl->mEventData )
873 if( NULL == mImpl->mEventData->mPlaceholderFont )
875 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
878 mImpl->mEventData->mPlaceholderFont->mFontDescription.slant = slant;
879 mImpl->mEventData->mPlaceholderFont->slantDefined = true;
881 mImpl->RequestRelayout();
885 bool Controller::IsPlaceholderTextFontSlantDefined() const
887 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
889 return mImpl->mEventData->mPlaceholderFont->slantDefined;
894 FontSlant Controller::GetPlaceholderTextFontSlant() const
896 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
898 return mImpl->mEventData->mPlaceholderFont->mFontDescription.slant;
901 return TextAbstraction::FontSlant::NORMAL;
904 void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
906 if( NULL == mImpl->mFontDefaults )
908 mImpl->mFontDefaults = new FontDefaults();
915 mImpl->mFontDefaults->mDefaultPointSize = fontSize;
916 mImpl->mFontDefaults->sizeDefined = true;
921 // Point size = Pixel size * 72.f / DPI
922 unsigned int horizontalDpi = 0u;
923 unsigned int verticalDpi = 0u;
924 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
925 fontClient.GetDpi( horizontalDpi, verticalDpi );
927 mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
928 mImpl->mFontDefaults->sizeDefined = true;
933 // Clear the font-specific data
936 mImpl->RequestRelayout();
939 float Controller::GetDefaultFontSize( FontSizeType type ) const
942 if( NULL != mImpl->mFontDefaults )
948 value = mImpl->mFontDefaults->mDefaultPointSize;
953 // Pixel size = Point size * DPI / 72.f
954 unsigned int horizontalDpi = 0u;
955 unsigned int verticalDpi = 0u;
956 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
957 fontClient.GetDpi( horizontalDpi, verticalDpi );
959 value = mImpl->mFontDefaults->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
969 void Controller::SetPlaceholderTextFontSize( float fontSize, FontSizeType type )
971 if( NULL != mImpl->mEventData )
973 if( NULL == mImpl->mEventData->mPlaceholderFont )
975 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
982 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = fontSize;
983 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
984 mImpl->mEventData->mIsPlaceholderPixelSize = false; // Font size flag
989 // Point size = Pixel size * 72.f / DPI
990 unsigned int horizontalDpi = 0u;
991 unsigned int verticalDpi = 0u;
992 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
993 fontClient.GetDpi( horizontalDpi, verticalDpi );
995 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
996 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
997 mImpl->mEventData->mIsPlaceholderPixelSize = true; // Font size flag
1002 mImpl->RequestRelayout();
1006 float Controller::GetPlaceholderTextFontSize( FontSizeType type ) const
1009 if( NULL != mImpl->mEventData )
1015 if( NULL != mImpl->mEventData->mPlaceholderFont )
1017 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize;
1021 // If the placeholder text font size is not set, then return the default font size.
1022 value = GetDefaultFontSize( POINT_SIZE );
1028 if( NULL != mImpl->mEventData->mPlaceholderFont )
1030 // Pixel size = Point size * DPI / 72.f
1031 unsigned int horizontalDpi = 0u;
1032 unsigned int verticalDpi = 0u;
1033 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1034 fontClient.GetDpi( horizontalDpi, verticalDpi );
1036 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1040 // If the placeholder text font size is not set, then return the default font size.
1041 value = GetDefaultFontSize( PIXEL_SIZE );
1052 void Controller::SetDefaultColor( const Vector4& color )
1054 mImpl->mTextColor = color;
1056 if( !mImpl->IsShowingPlaceholderText() )
1058 mImpl->mModel->mVisualModel->SetTextColor( color );
1060 mImpl->RequestRelayout();
1064 const Vector4& Controller::GetDefaultColor() const
1066 return mImpl->mTextColor;
1069 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
1071 if( NULL != mImpl->mEventData )
1073 mImpl->mEventData->mPlaceholderTextColor = textColor;
1076 if( mImpl->IsShowingPlaceholderText() )
1078 mImpl->mModel->mVisualModel->SetTextColor( textColor );
1079 mImpl->RequestRelayout();
1083 const Vector4& Controller::GetPlaceholderTextColor() const
1085 if( NULL != mImpl->mEventData )
1087 return mImpl->mEventData->mPlaceholderTextColor;
1090 return Color::BLACK;
1093 void Controller::SetShadowOffset( const Vector2& shadowOffset )
1095 mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
1097 mImpl->RequestRelayout();
1100 const Vector2& Controller::GetShadowOffset() const
1102 return mImpl->mModel->mVisualModel->GetShadowOffset();
1105 void Controller::SetShadowColor( const Vector4& shadowColor )
1107 mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
1109 mImpl->RequestRelayout();
1112 const Vector4& Controller::GetShadowColor() const
1114 return mImpl->mModel->mVisualModel->GetShadowColor();
1117 void Controller::SetShadowBlurRadius( const float& shadowBlurRadius )
1119 if ( fabsf( GetShadowBlurRadius() - shadowBlurRadius ) > Math::MACHINE_EPSILON_1 )
1121 mImpl->mModel->mVisualModel->SetShadowBlurRadius( shadowBlurRadius );
1123 mImpl->RequestRelayout();
1127 const float& Controller::GetShadowBlurRadius() const
1129 return mImpl->mModel->mVisualModel->GetShadowBlurRadius();
1132 void Controller::SetUnderlineColor( const Vector4& color )
1134 mImpl->mModel->mVisualModel->SetUnderlineColor( color );
1136 mImpl->RequestRelayout();
1139 const Vector4& Controller::GetUnderlineColor() const
1141 return mImpl->mModel->mVisualModel->GetUnderlineColor();
1144 void Controller::SetUnderlineEnabled( bool enabled )
1146 mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
1148 mImpl->RequestRelayout();
1151 bool Controller::IsUnderlineEnabled() const
1153 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
1156 void Controller::SetUnderlineHeight( float height )
1158 mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
1160 mImpl->RequestRelayout();
1163 float Controller::GetUnderlineHeight() const
1165 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
1168 void Controller::SetOutlineColor( const Vector4& color )
1170 mImpl->mModel->mVisualModel->SetOutlineColor( color );
1172 mImpl->RequestRelayout();
1175 const Vector4& Controller::GetOutlineColor() const
1177 return mImpl->mModel->mVisualModel->GetOutlineColor();
1180 void Controller::SetOutlineWidth( float width )
1182 mImpl->mModel->mVisualModel->SetOutlineWidth( width );
1184 mImpl->RequestRelayout();
1187 float Controller::GetOutlineWidth() const
1189 return mImpl->mModel->mVisualModel->GetOutlineWidth();
1192 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
1194 if( NULL == mImpl->mEmbossDefaults )
1196 mImpl->mEmbossDefaults = new EmbossDefaults();
1199 mImpl->mEmbossDefaults->properties = embossProperties;
1202 const std::string& Controller::GetDefaultEmbossProperties() const
1204 if( NULL != mImpl->mEmbossDefaults )
1206 return mImpl->mEmbossDefaults->properties;
1209 return EMPTY_STRING;
1212 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
1214 if( NULL == mImpl->mOutlineDefaults )
1216 mImpl->mOutlineDefaults = new OutlineDefaults();
1219 mImpl->mOutlineDefaults->properties = outlineProperties;
1222 const std::string& Controller::GetDefaultOutlineProperties() const
1224 if( NULL != mImpl->mOutlineDefaults )
1226 return mImpl->mOutlineDefaults->properties;
1229 return EMPTY_STRING;
1232 void Controller::SetDefaultLineSpacing( float lineSpacing )
1234 //TODO finish implementation
1235 mImpl->mLayoutEngine.SetDefaultLineSpacing( lineSpacing );
1238 float Controller::GetDefaultLineSpacing() const
1240 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
1243 void Controller::SetInputColor( const Vector4& color )
1245 if( NULL != mImpl->mEventData )
1247 mImpl->mEventData->mInputStyle.textColor = color;
1248 mImpl->mEventData->mInputStyle.isDefaultColor = false;
1250 if( EventData::SELECTING == mImpl->mEventData->mState )
1252 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
1254 // Get start and end position of selection
1255 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
1256 const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
1258 // Add the color run.
1259 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1260 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
1262 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
1263 colorRun.color = color;
1264 colorRun.characterRun.characterIndex = startOfSelectedText;
1265 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1267 // Request to relayout.
1268 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1269 mImpl->RequestRelayout();
1271 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1272 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1273 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1278 const Vector4& Controller::GetInputColor() const
1280 if( NULL != mImpl->mEventData )
1282 return mImpl->mEventData->mInputStyle.textColor;
1285 // Return the default text's color if there is no EventData.
1286 return mImpl->mTextColor;
1290 void Controller::SetInputFontFamily( const std::string& fontFamily )
1292 if( NULL != mImpl->mEventData )
1294 mImpl->mEventData->mInputStyle.familyName = fontFamily;
1295 mImpl->mEventData->mInputStyle.isFamilyDefined = true;
1297 if( EventData::SELECTING == mImpl->mEventData->mState )
1299 CharacterIndex startOfSelectedText = 0u;
1300 Length lengthOfSelectedText = 0u;
1301 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1302 mImpl->mModel->mLogicalModel,
1303 startOfSelectedText,
1304 lengthOfSelectedText );
1306 fontDescriptionRun.familyLength = fontFamily.size();
1307 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
1308 memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength );
1309 fontDescriptionRun.familyDefined = true;
1311 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
1313 // Request to relayout.
1314 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1319 UPDATE_LAYOUT_SIZE |
1322 mImpl->mRecalculateNaturalSize = true;
1323 mImpl->RequestRelayout();
1325 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1326 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1327 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1329 // As the font changes, recalculate the handle positions is needed.
1330 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1331 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1332 mImpl->mEventData->mUpdateHighlightBox = true;
1333 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1338 const std::string& Controller::GetInputFontFamily() const
1340 if( NULL != mImpl->mEventData )
1342 return mImpl->mEventData->mInputStyle.familyName;
1345 // Return the default font's family if there is no EventData.
1346 return GetDefaultFontFamily();
1349 void Controller::SetInputFontWeight( FontWeight weight )
1351 if( NULL != mImpl->mEventData )
1353 mImpl->mEventData->mInputStyle.weight = weight;
1354 mImpl->mEventData->mInputStyle.isWeightDefined = true;
1356 if( EventData::SELECTING == mImpl->mEventData->mState )
1358 CharacterIndex startOfSelectedText = 0u;
1359 Length lengthOfSelectedText = 0u;
1360 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1361 mImpl->mModel->mLogicalModel,
1362 startOfSelectedText,
1363 lengthOfSelectedText );
1365 fontDescriptionRun.weight = weight;
1366 fontDescriptionRun.weightDefined = true;
1368 // Request to relayout.
1369 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1374 UPDATE_LAYOUT_SIZE |
1377 mImpl->mRecalculateNaturalSize = true;
1378 mImpl->RequestRelayout();
1380 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1381 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1382 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1384 // As the font might change, recalculate the handle positions is needed.
1385 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1386 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1387 mImpl->mEventData->mUpdateHighlightBox = true;
1388 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1393 bool Controller::IsInputFontWeightDefined() const
1395 bool defined = false;
1397 if( NULL != mImpl->mEventData )
1399 defined = mImpl->mEventData->mInputStyle.isWeightDefined;
1405 FontWeight Controller::GetInputFontWeight() const
1407 if( NULL != mImpl->mEventData )
1409 return mImpl->mEventData->mInputStyle.weight;
1412 return GetDefaultFontWeight();
1415 void Controller::SetInputFontWidth( FontWidth width )
1417 if( NULL != mImpl->mEventData )
1419 mImpl->mEventData->mInputStyle.width = width;
1420 mImpl->mEventData->mInputStyle.isWidthDefined = true;
1422 if( EventData::SELECTING == mImpl->mEventData->mState )
1424 CharacterIndex startOfSelectedText = 0u;
1425 Length lengthOfSelectedText = 0u;
1426 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1427 mImpl->mModel->mLogicalModel,
1428 startOfSelectedText,
1429 lengthOfSelectedText );
1431 fontDescriptionRun.width = width;
1432 fontDescriptionRun.widthDefined = true;
1434 // Request to relayout.
1435 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1440 UPDATE_LAYOUT_SIZE |
1443 mImpl->mRecalculateNaturalSize = true;
1444 mImpl->RequestRelayout();
1446 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1447 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1448 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1450 // As the font might change, recalculate the handle positions is needed.
1451 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1452 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1453 mImpl->mEventData->mUpdateHighlightBox = true;
1454 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1459 bool Controller::IsInputFontWidthDefined() const
1461 bool defined = false;
1463 if( NULL != mImpl->mEventData )
1465 defined = mImpl->mEventData->mInputStyle.isWidthDefined;
1471 FontWidth Controller::GetInputFontWidth() const
1473 if( NULL != mImpl->mEventData )
1475 return mImpl->mEventData->mInputStyle.width;
1478 return GetDefaultFontWidth();
1481 void Controller::SetInputFontSlant( FontSlant slant )
1483 if( NULL != mImpl->mEventData )
1485 mImpl->mEventData->mInputStyle.slant = slant;
1486 mImpl->mEventData->mInputStyle.isSlantDefined = true;
1488 if( EventData::SELECTING == mImpl->mEventData->mState )
1490 CharacterIndex startOfSelectedText = 0u;
1491 Length lengthOfSelectedText = 0u;
1492 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1493 mImpl->mModel->mLogicalModel,
1494 startOfSelectedText,
1495 lengthOfSelectedText );
1497 fontDescriptionRun.slant = slant;
1498 fontDescriptionRun.slantDefined = true;
1500 // Request to relayout.
1501 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1506 UPDATE_LAYOUT_SIZE |
1509 mImpl->mRecalculateNaturalSize = true;
1510 mImpl->RequestRelayout();
1512 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1513 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1514 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1516 // As the font might change, recalculate the handle positions is needed.
1517 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1518 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1519 mImpl->mEventData->mUpdateHighlightBox = true;
1520 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1525 bool Controller::IsInputFontSlantDefined() const
1527 bool defined = false;
1529 if( NULL != mImpl->mEventData )
1531 defined = mImpl->mEventData->mInputStyle.isSlantDefined;
1537 FontSlant Controller::GetInputFontSlant() const
1539 if( NULL != mImpl->mEventData )
1541 return mImpl->mEventData->mInputStyle.slant;
1544 return GetDefaultFontSlant();
1547 void Controller::SetInputFontPointSize( float size )
1549 if( NULL != mImpl->mEventData )
1551 mImpl->mEventData->mInputStyle.size = size;
1552 mImpl->mEventData->mInputStyle.isSizeDefined = true;
1554 if( EventData::SELECTING == mImpl->mEventData->mState )
1556 CharacterIndex startOfSelectedText = 0u;
1557 Length lengthOfSelectedText = 0u;
1558 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1559 mImpl->mModel->mLogicalModel,
1560 startOfSelectedText,
1561 lengthOfSelectedText );
1563 fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
1564 fontDescriptionRun.sizeDefined = true;
1566 // Request to relayout.
1567 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1572 UPDATE_LAYOUT_SIZE |
1575 mImpl->mRecalculateNaturalSize = true;
1576 mImpl->RequestRelayout();
1578 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1579 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1580 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1582 // As the font might change, recalculate the handle positions is needed.
1583 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1584 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1585 mImpl->mEventData->mUpdateHighlightBox = true;
1586 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1591 float Controller::GetInputFontPointSize() const
1593 if( NULL != mImpl->mEventData )
1595 return mImpl->mEventData->mInputStyle.size;
1598 // Return the default font's point size if there is no EventData.
1599 return GetDefaultFontSize( Text::Controller::POINT_SIZE );
1602 void Controller::SetInputLineSpacing( float lineSpacing )
1604 if( NULL != mImpl->mEventData )
1606 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1607 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1611 float Controller::GetInputLineSpacing() const
1613 if( NULL != mImpl->mEventData )
1615 return mImpl->mEventData->mInputStyle.lineSpacing;
1621 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1623 if( NULL != mImpl->mEventData )
1625 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1629 const std::string& Controller::GetInputShadowProperties() const
1631 if( NULL != mImpl->mEventData )
1633 return mImpl->mEventData->mInputStyle.shadowProperties;
1636 return EMPTY_STRING;
1639 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1641 if( NULL != mImpl->mEventData )
1643 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1647 const std::string& Controller::GetInputUnderlineProperties() const
1649 if( NULL != mImpl->mEventData )
1651 return mImpl->mEventData->mInputStyle.underlineProperties;
1654 return EMPTY_STRING;
1657 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
1659 if( NULL != mImpl->mEventData )
1661 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1665 const std::string& Controller::GetInputEmbossProperties() const
1667 if( NULL != mImpl->mEventData )
1669 return mImpl->mEventData->mInputStyle.embossProperties;
1672 return GetDefaultEmbossProperties();
1675 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
1677 if( NULL != mImpl->mEventData )
1679 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1683 const std::string& Controller::GetInputOutlineProperties() const
1685 if( NULL != mImpl->mEventData )
1687 return mImpl->mEventData->mInputStyle.outlineProperties;
1690 return GetDefaultOutlineProperties();
1693 void Controller::SetInputModePassword( bool passwordInput )
1695 if( NULL != mImpl->mEventData )
1697 mImpl->mEventData->mPasswordInput = passwordInput;
1701 bool Controller::IsInputModePassword()
1703 if( NULL != mImpl->mEventData )
1705 return mImpl->mEventData->mPasswordInput;
1710 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
1712 if( NULL != mImpl->mEventData )
1714 mImpl->mEventData->mDoubleTapAction = action;
1718 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1720 NoTextTap::Action action = NoTextTap::NO_ACTION;
1722 if( NULL != mImpl->mEventData )
1724 action = mImpl->mEventData->mDoubleTapAction;
1730 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
1732 if( NULL != mImpl->mEventData )
1734 mImpl->mEventData->mLongPressAction = action;
1738 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1740 NoTextTap::Action action = NoTextTap::NO_ACTION;
1742 if( NULL != mImpl->mEventData )
1744 action = mImpl->mEventData->mLongPressAction;
1750 bool Controller::IsUnderlineSetByString()
1752 return mImpl->mUnderlineSetByString;
1755 void Controller::UnderlineSetByString( bool setByString )
1757 mImpl->mUnderlineSetByString = setByString;
1760 bool Controller::IsShadowSetByString()
1762 return mImpl->mShadowSetByString;
1765 void Controller::ShadowSetByString( bool setByString )
1767 mImpl->mShadowSetByString = setByString;
1770 bool Controller::IsOutlineSetByString()
1772 return mImpl->mOutlineSetByString;
1775 void Controller::OutlineSetByString( bool setByString )
1777 mImpl->mOutlineSetByString = setByString;
1780 bool Controller::IsFontStyleSetByString()
1782 return mImpl->mFontStyleSetByString;
1785 void Controller::FontStyleSetByString( bool setByString )
1787 mImpl->mFontStyleSetByString = setByString;
1790 // public : Queries & retrieves.
1792 Layout::Engine& Controller::GetLayoutEngine()
1794 return mImpl->mLayoutEngine;
1797 View& Controller::GetView()
1799 return mImpl->mView;
1802 Vector3 Controller::GetNaturalSize()
1804 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
1805 Vector3 naturalSize;
1807 // Make sure the model is up-to-date before layouting
1808 ProcessModifyEvents();
1810 if( mImpl->mRecalculateNaturalSize )
1812 // Operations that can be done only once until the text changes.
1813 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1820 GET_GLYPH_METRICS );
1822 // Set the update info to relayout the whole text.
1823 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1824 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1826 // Make sure the model is up-to-date before layouting
1827 mImpl->UpdateModel( onlyOnceOperations );
1829 // Layout the text for the new width.
1830 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT | REORDER );
1832 // Store the actual control's size to restore later.
1833 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
1835 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
1836 static_cast<OperationsMask>( onlyOnceOperations |
1838 naturalSize.GetVectorXY() );
1840 // Do not do again the only once operations.
1841 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1843 // Do the size related operations again.
1844 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1847 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1849 // Stores the natural size to avoid recalculate it again
1850 // unless the text/style changes.
1851 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
1853 mImpl->mRecalculateNaturalSize = false;
1855 // Clear the update info. This info will be set the next time the text is updated.
1856 mImpl->mTextUpdateInfo.Clear();
1858 // Restore the actual control's size.
1859 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
1861 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1865 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
1867 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1870 naturalSize.x = ConvertToEven( naturalSize.x );
1871 naturalSize.y = ConvertToEven( naturalSize.y );
1876 float Controller::GetHeightForWidth( float width )
1878 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
1879 // Make sure the model is up-to-date before layouting
1880 ProcessModifyEvents();
1883 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ||
1884 mImpl->mTextUpdateInfo.mFullRelayoutNeeded ||
1885 mImpl->mTextUpdateInfo.mClearAll )
1887 // Operations that can be done only once until the text changes.
1888 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1895 GET_GLYPH_METRICS );
1897 // Set the update info to relayout the whole text.
1898 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1899 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1901 // Make sure the model is up-to-date before layouting
1902 mImpl->UpdateModel( onlyOnceOperations );
1905 // Layout the text for the new width.
1906 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
1908 // Store the actual control's width.
1909 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
1911 DoRelayout( Size( width, MAX_FLOAT ),
1912 static_cast<OperationsMask>( onlyOnceOperations |
1916 // Do not do again the only once operations.
1917 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1919 // Do the size related operations again.
1920 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1924 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1926 // Clear the update info. This info will be set the next time the text is updated.
1927 mImpl->mTextUpdateInfo.Clear();
1929 // Restore the actual control's width.
1930 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
1932 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
1936 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
1937 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
1940 return layoutSize.height;
1943 int Controller::GetLineCount( float width )
1945 GetHeightForWidth( width );
1946 int numberofLines = mImpl->mModel->GetNumberOfLines();
1947 return numberofLines;
1950 const ModelInterface* const Controller::GetTextModel() const
1952 return mImpl->mModel.Get();
1955 float Controller::GetScrollAmountByUserInput()
1957 float scrollAmount = 0.0f;
1959 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
1961 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
1962 mImpl->mEventData->mCheckScrollAmount = false;
1964 return scrollAmount;
1967 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
1969 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
1972 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
1973 layoutHeight = layout.height;
1974 scrollPosition = mImpl->mModel->mScrollPosition.y;
1975 isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
1979 void Controller::SetHiddenInputOption(const Property::Map& options )
1981 if( NULL == mImpl->mHiddenInput )
1983 mImpl->mHiddenInput = new HiddenText( this );
1985 mImpl->mHiddenInput->SetProperties(options);
1988 void Controller::GetHiddenInputOption(Property::Map& options )
1990 if( NULL != mImpl->mHiddenInput )
1992 mImpl->mHiddenInput->GetProperties(options);
1996 void Controller::SetPlaceholderProperty( const Property::Map& map )
1998 const Property::Map::SizeType count = map.Count();
2000 for( Property::Map::SizeType position = 0; position < count; ++position )
2002 KeyValuePair keyValue = map.GetKeyValue( position );
2003 Property::Key& key = keyValue.first;
2004 Property::Value& value = keyValue.second;
2006 if( key == Toolkit::Text::PlaceHolder::Property::TEXT || key == PLACEHOLDER_TEXT )
2008 std::string text = "";
2010 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
2012 else if( key == Toolkit::Text::PlaceHolder::Property::TEXT_FOCUSED || key == PLACEHOLDER_TEXT_FOCUSED )
2014 std::string text = "";
2016 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
2018 else if( key == Toolkit::Text::PlaceHolder::Property::COLOR || key == PLACEHOLDER_COLOR )
2021 value.Get( textColor );
2022 if( GetPlaceholderTextColor() != textColor )
2024 SetPlaceholderTextColor( textColor );
2027 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_FAMILY || key == PLACEHOLDER_FONT_FAMILY )
2029 std::string fontFamily = "";
2030 value.Get( fontFamily );
2031 SetPlaceholderFontFamily( fontFamily );
2033 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_STYLE || key == PLACEHOLDER_FONT_STYLE )
2035 SetFontStyleProperty( this, value, Text::FontStyle::PLACEHOLDER );
2037 else if( key == Toolkit::Text::PlaceHolder::Property::POINT_SIZE || key == PLACEHOLDER_POINT_SIZE )
2040 value.Get( pointSize );
2041 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
2043 SetPlaceholderTextFontSize( pointSize, Text::Controller::POINT_SIZE );
2046 else if( key == Toolkit::Text::PlaceHolder::Property::PIXEL_SIZE || key == PLACEHOLDER_PIXEL_SIZE )
2049 value.Get( pixelSize );
2050 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
2052 SetPlaceholderTextFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
2055 else if( key == Toolkit::Text::PlaceHolder::Property::ELLIPSIS || key == PLACEHOLDER_ELLIPSIS )
2058 value.Get( ellipsis );
2059 SetPlaceholderTextElideEnabled( ellipsis );
2064 void Controller::GetPlaceholderProperty( Property::Map& map )
2066 if( NULL != mImpl->mEventData )
2068 if( !mImpl->mEventData->mPlaceholderTextActive.empty() )
2070 map[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = mImpl->mEventData->mPlaceholderTextActive;
2072 if( !mImpl->mEventData->mPlaceholderTextInactive.empty() )
2074 map[ Text::PlaceHolder::Property::TEXT ] = mImpl->mEventData->mPlaceholderTextInactive;
2077 map[ Text::PlaceHolder::Property::COLOR ] = mImpl->mEventData->mPlaceholderTextColor;
2078 map[ Text::PlaceHolder::Property::FONT_FAMILY ] = GetPlaceholderFontFamily();
2080 Property::Value fontStyleMapGet;
2081 GetFontStyleProperty( this, fontStyleMapGet, Text::FontStyle::PLACEHOLDER );
2082 map[ Text::PlaceHolder::Property::FONT_STYLE ] = fontStyleMapGet;
2084 // Choose font size : POINT_SIZE or PIXEL_SIZE
2085 if( !mImpl->mEventData->mIsPlaceholderPixelSize )
2087 map[ Text::PlaceHolder::Property::POINT_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE );
2091 map[ Text::PlaceHolder::Property::PIXEL_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE );
2094 if( mImpl->mEventData->mPlaceholderEllipsisFlag )
2096 map[ Text::PlaceHolder::Property::ELLIPSIS ] = IsPlaceholderTextElideEnabled();
2101 // public : Relayout.
2103 Controller::UpdateTextType Controller::Relayout( const Size& size )
2105 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
2107 UpdateTextType updateTextType = NONE_UPDATED;
2109 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
2111 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
2113 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
2114 updateTextType = MODEL_UPDATED;
2117 // Clear the update info. This info will be set the next time the text is updated.
2118 mImpl->mTextUpdateInfo.Clear();
2120 // Not worth to relayout if width or height is equal to zero.
2121 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
2123 return updateTextType;
2126 // Whether a new size has been set.
2127 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
2131 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
2133 // Layout operations that need to be done if the size changes.
2134 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2137 UPDATE_LAYOUT_SIZE |
2139 // Set the update info to relayout the whole text.
2140 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2141 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2143 // Store the size used to layout the text.
2144 mImpl->mModel->mVisualModel->mControlSize = size;
2147 // Whether there are modify events.
2148 if( 0u != mImpl->mModifyEvents.Count() )
2150 // Style operations that need to be done if the text is modified.
2151 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2155 // Set the update info to elide the text.
2156 if( mImpl->mModel->mElideEnabled ||
2157 ( ( NULL != mImpl->mEventData ) && mImpl->mEventData->mIsPlaceholderElideEnabled ) )
2159 // Update Text layout for applying elided
2160 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2163 UPDATE_LAYOUT_SIZE |
2165 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2166 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2169 // Make sure the model is up-to-date before layouting.
2170 ProcessModifyEvents();
2171 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
2175 updated = DoRelayout( size,
2176 mImpl->mOperationsPending,
2177 layoutSize ) || updated;
2181 updateTextType = MODEL_UPDATED;
2184 // Do not re-do any operation until something changes.
2185 mImpl->mOperationsPending = NO_OPERATION;
2186 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
2188 // Whether the text control is editable
2189 const bool isEditable = NULL != mImpl->mEventData;
2191 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
2193 if( newSize && isEditable )
2195 offset = mImpl->mModel->mScrollPosition;
2198 if( !isEditable || !IsMultiLineEnabled() )
2200 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
2201 CalculateVerticalOffset( size );
2208 // If there is a new size, the scroll position needs to be clamped.
2209 mImpl->ClampHorizontalScroll( layoutSize );
2211 // Update the decorator's positions is needed if there is a new size.
2212 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
2215 // Move the cursor, grab handle etc.
2216 if( mImpl->ProcessInputEvents() )
2218 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
2222 // Clear the update info. This info will be set the next time the text is updated.
2223 mImpl->mTextUpdateInfo.Clear();
2224 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
2226 return updateTextType;
2229 void Controller::RequestRelayout()
2231 mImpl->RequestRelayout();
2234 // public : Input style change signals.
2236 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
2238 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
2241 void Controller::ProcessInputStyleChangedSignals()
2243 if( NULL == mImpl->mEventData )
2249 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
2250 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
2254 const InputStyle::Mask mask = *it;
2256 if( NULL != mImpl->mEditableControlInterface )
2258 // Emit the input style changed signal.
2259 mImpl->mEditableControlInterface->InputStyleChanged( mask );
2263 mImpl->mEventData->mInputStyleChangedQueue.Clear();
2266 // public : Text-input Event Queuing.
2268 void Controller::KeyboardFocusGainEvent()
2270 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
2272 if( NULL != mImpl->mEventData )
2274 if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
2275 ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
2277 mImpl->ChangeState( EventData::EDITING );
2278 mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
2279 mImpl->mEventData->mUpdateInputStyle = true;
2281 mImpl->NotifyImfMultiLineStatus();
2282 if( mImpl->IsShowingPlaceholderText() )
2284 // Show alternative placeholder-text when editing
2285 ShowPlaceholderText();
2288 mImpl->RequestRelayout();
2292 void Controller::KeyboardFocusLostEvent()
2294 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
2296 if( NULL != mImpl->mEventData )
2298 if( EventData::INTERRUPTED != mImpl->mEventData->mState )
2300 mImpl->ChangeState( EventData::INACTIVE );
2302 if( !mImpl->IsShowingRealText() )
2304 // Revert to regular placeholder-text when not editing
2305 ShowPlaceholderText();
2309 mImpl->RequestRelayout();
2312 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
2314 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
2316 bool textChanged = false;
2317 bool relayoutNeeded = false;
2319 if( ( NULL != mImpl->mEventData ) &&
2320 ( keyEvent.state == KeyEvent::Down ) )
2322 int keyCode = keyEvent.keyCode;
2323 const std::string& keyString = keyEvent.keyPressed;
2325 const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
2327 // Pre-process to separate modifying events from non-modifying input events.
2330 // In some platforms arrive key events with no key code.
2334 else if( Dali::DALI_KEY_ESCAPE == keyCode || Dali::DALI_KEY_BACK == keyCode || Dali::DALI_KEY_SEARCH == keyCode )
2339 else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) ||
2340 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
2341 ( Dali::DALI_KEY_CURSOR_UP == keyCode ) ||
2342 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) )
2344 // If don't have any text, do nothing.
2345 if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
2350 uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition;
2351 uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2352 uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition );
2353 uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines();
2355 // Logic to determine whether this text control will lose focus or not.
2356 if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition ) ||
2357 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition) ||
2358 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) ||
2359 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) ||
2360 ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) ||
2361 ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) )
2366 mImpl->mEventData->mCheckScrollAmount = true;
2367 Event event( Event::CURSOR_KEY_EVENT );
2368 event.p1.mInt = keyCode;
2369 mImpl->mEventData->mEventQueue.push_back( event );
2371 // Will request for relayout.
2372 relayoutNeeded = true;
2374 else if( ( Dali::DALI_KEY_BACKSPACE == keyCode ) ||
2375 ( Dali::DevelKey::DALI_KEY_DELETE == keyCode ) )
2377 textChanged = DeleteEvent( keyCode );
2379 // Will request for relayout.
2380 relayoutNeeded = true;
2382 else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
2383 IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
2384 IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
2386 // Power key/Menu/Home key behaviour does not allow edit mode to resume.
2387 mImpl->ChangeState( EventData::INACTIVE );
2389 // Will request for relayout.
2390 relayoutNeeded = true;
2392 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2394 else if( Dali::DALI_KEY_SHIFT_LEFT == keyCode )
2396 // DALI_KEY_SHIFT_LEFT is the key code for the Left Shift. It's sent (by the imf?) when the predictive text is enabled
2397 // and a character is typed after the type of a upper case latin character.
2402 else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
2404 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2410 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
2412 // IMF manager is no longer handling key-events
2413 mImpl->ClearPreEditFlag();
2415 InsertText( keyString, COMMIT );
2418 // Will request for relayout.
2419 relayoutNeeded = true;
2422 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
2423 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
2425 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
2426 ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
2427 ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
2429 // Should not change the state if the key is the shift send by the imf manager.
2430 // Otherwise, when the state is SELECTING the text controller can't send the right
2431 // surrounding info to the imf.
2432 mImpl->ChangeState( EventData::EDITING );
2434 // Will request for relayout.
2435 relayoutNeeded = true;
2438 if( relayoutNeeded )
2440 mImpl->RequestRelayout();
2445 ( NULL != mImpl->mEditableControlInterface ) )
2447 // Do this last since it provides callbacks into application code
2448 mImpl->mEditableControlInterface->TextChanged();
2454 void Controller::TapEvent( unsigned int tapCount, float x, float y )
2456 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
2458 if( NULL != mImpl->mEventData )
2460 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
2461 EventData::State state( mImpl->mEventData->mState );
2462 bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
2464 if( mImpl->IsClipboardVisible() )
2466 if( EventData::INACTIVE == state || EventData::EDITING == state)
2468 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2470 relayoutNeeded = true;
2472 else if( 1u == tapCount )
2474 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
2476 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
2479 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
2481 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2482 relayoutNeeded = true;
2486 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
2488 // Hide placeholder text
2492 if( EventData::INACTIVE == state )
2494 mImpl->ChangeState( EventData::EDITING );
2496 else if( !mImpl->IsClipboardEmpty() )
2498 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
2500 relayoutNeeded = true;
2503 else if( 2u == tapCount )
2505 if( mImpl->mEventData->mSelectionEnabled &&
2506 mImpl->IsShowingRealText() )
2508 relayoutNeeded = true;
2509 mImpl->mEventData->mIsLeftHandleSelected = true;
2510 mImpl->mEventData->mIsRightHandleSelected = true;
2514 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
2515 if( relayoutNeeded )
2517 Event event( Event::TAP_EVENT );
2518 event.p1.mUint = tapCount;
2519 event.p2.mFloat = x;
2520 event.p3.mFloat = y;
2521 mImpl->mEventData->mEventQueue.push_back( event );
2523 mImpl->RequestRelayout();
2527 // Reset keyboard as tap event has occurred.
2528 mImpl->ResetImfManager();
2531 void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
2533 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
2535 if( NULL != mImpl->mEventData )
2537 Event event( Event::PAN_EVENT );
2538 event.p1.mInt = state;
2539 event.p2.mFloat = displacement.x;
2540 event.p3.mFloat = displacement.y;
2541 mImpl->mEventData->mEventQueue.push_back( event );
2543 mImpl->RequestRelayout();
2547 void Controller::LongPressEvent( Gesture::State state, float x, float y )
2549 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
2551 if( ( state == Gesture::Started ) &&
2552 ( NULL != mImpl->mEventData ) )
2554 // The 1st long-press on inactive text-field is treated as tap
2555 if( EventData::INACTIVE == mImpl->mEventData->mState )
2557 mImpl->ChangeState( EventData::EDITING );
2559 Event event( Event::TAP_EVENT );
2561 event.p2.mFloat = x;
2562 event.p3.mFloat = y;
2563 mImpl->mEventData->mEventQueue.push_back( event );
2565 mImpl->RequestRelayout();
2567 else if( !mImpl->IsShowingRealText() )
2569 Event event( Event::LONG_PRESS_EVENT );
2570 event.p1.mInt = state;
2571 event.p2.mFloat = x;
2572 event.p3.mFloat = y;
2573 mImpl->mEventData->mEventQueue.push_back( event );
2574 mImpl->RequestRelayout();
2576 else if( !mImpl->IsClipboardVisible() )
2578 // Reset the imf manager to commit the pre-edit before selecting the text.
2579 mImpl->ResetImfManager();
2581 Event event( Event::LONG_PRESS_EVENT );
2582 event.p1.mInt = state;
2583 event.p2.mFloat = x;
2584 event.p3.mFloat = y;
2585 mImpl->mEventData->mEventQueue.push_back( event );
2586 mImpl->RequestRelayout();
2588 mImpl->mEventData->mIsLeftHandleSelected = true;
2589 mImpl->mEventData->mIsRightHandleSelected = true;
2594 ImfManager::ImfCallbackData Controller::OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
2596 // Whether the text needs to be relaid-out.
2597 bool requestRelayout = false;
2599 // Whether to retrieve the text and cursor position to be sent to the IMF manager.
2600 bool retrieveText = false;
2601 bool retrieveCursor = false;
2603 switch( imfEvent.eventName )
2605 case ImfManager::COMMIT:
2607 InsertText( imfEvent.predictiveString, Text::Controller::COMMIT );
2608 requestRelayout = true;
2609 retrieveCursor = true;
2612 case ImfManager::PREEDIT:
2614 InsertText( imfEvent.predictiveString, Text::Controller::PRE_EDIT );
2615 requestRelayout = true;
2616 retrieveCursor = true;
2619 case ImfManager::DELETESURROUNDING:
2621 const bool textDeleted = RemoveText( imfEvent.cursorOffset,
2622 imfEvent.numberOfChars,
2623 DONT_UPDATE_INPUT_STYLE );
2627 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2628 !mImpl->IsPlaceholderAvailable() )
2630 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2634 ShowPlaceholderText();
2636 mImpl->mEventData->mUpdateCursorPosition = true;
2637 mImpl->mEventData->mScrollAfterDelete = true;
2639 requestRelayout = true;
2643 case ImfManager::GETSURROUNDING:
2645 retrieveText = true;
2646 retrieveCursor = true;
2649 case ImfManager::PRIVATECOMMAND:
2651 // PRIVATECOMMAND event is just for getting the private command message
2652 retrieveText = true;
2653 retrieveCursor = true;
2656 case ImfManager::VOID:
2663 if( requestRelayout )
2665 mImpl->mOperationsPending = ALL_OPERATIONS;
2666 mImpl->RequestRelayout();
2670 CharacterIndex cursorPosition = 0u;
2671 Length numberOfWhiteSpaces = 0u;
2673 if( retrieveCursor )
2675 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
2677 cursorPosition = mImpl->GetLogicalCursorPosition();
2679 if( cursorPosition < numberOfWhiteSpaces )
2681 cursorPosition = 0u;
2685 cursorPosition -= numberOfWhiteSpaces;
2691 mImpl->GetText( numberOfWhiteSpaces, text );
2694 ImfManager::ImfCallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
2696 if( requestRelayout &&
2697 ( NULL != mImpl->mEditableControlInterface ) )
2699 // Do this last since it provides callbacks into application code
2700 mImpl->mEditableControlInterface->TextChanged();
2703 return callbackData;
2706 void Controller::PasteClipboardItemEvent()
2708 // Retrieve the clipboard contents first
2709 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
2710 std::string stringToPaste( notifier.GetContent() );
2712 // Commit the current pre-edit text; the contents of the clipboard should be appended
2713 mImpl->ResetImfManager();
2715 // Temporary disable hiding clipboard
2716 mImpl->SetClipboardHideEnable( false );
2719 PasteText( stringToPaste );
2721 mImpl->SetClipboardHideEnable( true );
2724 // protected : Inherit from Text::Decorator::ControllerInterface.
2726 void Controller::GetTargetSize( Vector2& targetSize )
2728 targetSize = mImpl->mModel->mVisualModel->mControlSize;
2731 void Controller::AddDecoration( Actor& actor, bool needsClipping )
2733 if( NULL != mImpl->mEditableControlInterface )
2735 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
2739 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
2741 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
2743 if( NULL != mImpl->mEventData )
2745 switch( handleType )
2749 Event event( Event::GRAB_HANDLE_EVENT );
2750 event.p1.mUint = state;
2751 event.p2.mFloat = x;
2752 event.p3.mFloat = y;
2754 mImpl->mEventData->mEventQueue.push_back( event );
2757 case LEFT_SELECTION_HANDLE:
2759 Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
2760 event.p1.mUint = state;
2761 event.p2.mFloat = x;
2762 event.p3.mFloat = y;
2764 mImpl->mEventData->mEventQueue.push_back( event );
2767 case RIGHT_SELECTION_HANDLE:
2769 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
2770 event.p1.mUint = state;
2771 event.p2.mFloat = x;
2772 event.p3.mFloat = y;
2774 mImpl->mEventData->mEventQueue.push_back( event );
2777 case LEFT_SELECTION_HANDLE_MARKER:
2778 case RIGHT_SELECTION_HANDLE_MARKER:
2780 // Markers do not move the handles.
2783 case HANDLE_TYPE_COUNT:
2785 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
2789 mImpl->RequestRelayout();
2793 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
2795 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
2797 if( NULL == mImpl->mEventData )
2804 case Toolkit::TextSelectionPopup::CUT:
2806 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
2807 mImpl->mOperationsPending = ALL_OPERATIONS;
2809 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2810 !mImpl->IsPlaceholderAvailable() )
2812 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2816 ShowPlaceholderText();
2819 mImpl->mEventData->mUpdateCursorPosition = true;
2820 mImpl->mEventData->mScrollAfterDelete = true;
2822 mImpl->RequestRelayout();
2824 if( NULL != mImpl->mEditableControlInterface )
2826 mImpl->mEditableControlInterface->TextChanged();
2830 case Toolkit::TextSelectionPopup::COPY:
2832 mImpl->SendSelectionToClipboard( false ); // Text not modified
2834 mImpl->mEventData->mUpdateCursorPosition = true;
2836 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
2839 case Toolkit::TextSelectionPopup::PASTE:
2841 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
2844 case Toolkit::TextSelectionPopup::SELECT:
2846 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
2848 if( mImpl->mEventData->mSelectionEnabled )
2850 // Creates a SELECT event.
2851 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
2855 case Toolkit::TextSelectionPopup::SELECT_ALL:
2857 // Creates a SELECT_ALL event
2858 SelectEvent( 0.f, 0.f, true );
2861 case Toolkit::TextSelectionPopup::CLIPBOARD:
2863 mImpl->ShowClipboard();
2866 case Toolkit::TextSelectionPopup::NONE:
2874 void Controller::DisplayTimeExpired()
2876 mImpl->mEventData->mUpdateCursorPosition = true;
2877 // Apply modifications to the model
2878 mImpl->mOperationsPending = ALL_OPERATIONS;
2880 mImpl->RequestRelayout();
2883 // private : Update.
2885 void Controller::InsertText( const std::string& text, Controller::InsertType type )
2887 bool removedPrevious = false;
2888 bool removedSelected = false;
2889 bool maxLengthReached = false;
2891 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
2893 if( NULL == mImpl->mEventData )
2898 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
2899 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
2900 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
2902 // TODO: At the moment the underline runs are only for pre-edit.
2903 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
2905 // Remove the previous IMF pre-edit.
2906 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
2908 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
2909 mImpl->mEventData->mPreEditLength,
2910 DONT_UPDATE_INPUT_STYLE );
2912 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
2913 mImpl->mEventData->mPreEditLength = 0u;
2917 // Remove the previous Selection.
2918 removedSelected = RemoveSelectedText();
2922 Vector<Character> utf32Characters;
2923 Length characterCount = 0u;
2927 // Convert text into UTF-32
2928 utf32Characters.Resize( text.size() );
2930 // This is a bit horrible but std::string returns a (signed) char*
2931 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
2933 // Transform a text array encoded in utf8 into an array encoded in utf32.
2934 // It returns the actual number of characters.
2935 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
2936 utf32Characters.Resize( characterCount );
2938 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
2939 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
2942 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
2944 // The placeholder text is no longer needed
2945 if( mImpl->IsShowingPlaceholderText() )
2950 mImpl->ChangeState( EventData::EDITING );
2952 // Handle the IMF (predicitive text) state changes
2953 if( COMMIT == type )
2955 // IMF manager is no longer handling key-events
2956 mImpl->ClearPreEditFlag();
2960 if( !mImpl->mEventData->mPreEditFlag )
2962 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
2964 // Record the start of the pre-edit text
2965 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
2968 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
2969 mImpl->mEventData->mPreEditFlag = true;
2971 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
2974 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
2976 // Restrict new text to fit within Maximum characters setting.
2977 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
2978 maxLengthReached = ( characterCount > maxSizeOfNewText );
2980 // The cursor position.
2981 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
2983 // Update the text's style.
2985 // Updates the text style runs by adding characters.
2986 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
2988 // Get the character index from the cursor index.
2989 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
2991 // Retrieve the text's style for the given index.
2993 mImpl->RetrieveDefaultInputStyle( style );
2994 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
2996 // Whether to add a new text color run.
2997 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor );
2999 // Whether to add a new font run.
3000 const bool addFontNameRun = style.familyName != mImpl->mEventData->mInputStyle.familyName;
3001 const bool addFontWeightRun = style.weight != mImpl->mEventData->mInputStyle.weight;
3002 const bool addFontWidthRun = style.width != mImpl->mEventData->mInputStyle.width;
3003 const bool addFontSlantRun = style.slant != mImpl->mEventData->mInputStyle.slant;
3004 const bool addFontSizeRun = style.size != mImpl->mEventData->mInputStyle.size;
3009 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
3010 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
3012 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
3013 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
3014 colorRun.characterRun.characterIndex = cursorIndex;
3015 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3018 if( addFontNameRun ||
3024 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
3025 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
3027 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
3029 if( addFontNameRun )
3031 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
3032 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
3033 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
3034 fontDescriptionRun.familyDefined = true;
3036 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
3039 if( addFontWeightRun )
3041 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
3042 fontDescriptionRun.weightDefined = true;
3045 if( addFontWidthRun )
3047 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
3048 fontDescriptionRun.widthDefined = true;
3051 if( addFontSlantRun )
3053 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
3054 fontDescriptionRun.slantDefined = true;
3057 if( addFontSizeRun )
3059 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
3060 fontDescriptionRun.sizeDefined = true;
3063 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
3064 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3067 // Insert at current cursor position.
3068 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
3070 if( cursorIndex < numberOfCharactersInModel )
3072 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3076 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3079 // Mark the first paragraph to be updated.
3080 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3082 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3083 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3084 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
3085 mImpl->mTextUpdateInfo.mClearAll = true;
3089 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3090 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
3093 // Update the cursor index.
3094 cursorIndex += maxSizeOfNewText;
3096 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 );
3099 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
3100 mImpl->IsPlaceholderAvailable() )
3102 // Show place-holder if empty after removing the pre-edit text
3103 ShowPlaceholderText();
3104 mImpl->mEventData->mUpdateCursorPosition = true;
3105 mImpl->ClearPreEditFlag();
3107 else if( removedPrevious ||
3109 ( 0 != utf32Characters.Count() ) )
3111 // Queue an inserted event
3112 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
3114 mImpl->mEventData->mUpdateCursorPosition = true;
3115 if( removedSelected )
3117 mImpl->mEventData->mScrollAfterDelete = true;
3121 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3125 if( maxLengthReached )
3127 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
3129 mImpl->ResetImfManager();
3131 if( NULL != mImpl->mEditableControlInterface )
3133 // Do this last since it provides callbacks into application code
3134 mImpl->mEditableControlInterface->MaxLengthReached();
3139 void Controller::PasteText( const std::string& stringToPaste )
3141 InsertText( stringToPaste, Text::Controller::COMMIT );
3142 mImpl->ChangeState( EventData::EDITING );
3143 mImpl->RequestRelayout();
3145 if( NULL != mImpl->mEditableControlInterface )
3147 // Do this last since it provides callbacks into application code
3148 mImpl->mEditableControlInterface->TextChanged();
3152 bool Controller::RemoveText( int cursorOffset,
3153 int numberOfCharacters,
3154 UpdateInputStyleType type )
3156 bool removed = false;
3158 if( NULL == mImpl->mEventData )
3163 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
3164 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
3166 if( !mImpl->IsShowingPlaceholderText() )
3168 // Delete at current cursor position
3169 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
3170 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3172 CharacterIndex cursorIndex = 0;
3174 // Validate the cursor position & number of characters
3175 if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
3177 cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
3180 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
3182 numberOfCharacters = currentText.Count() - cursorIndex;
3185 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.
3186 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
3188 // Mark the paragraphs to be updated.
3189 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3191 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3192 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3193 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
3194 mImpl->mTextUpdateInfo.mClearAll = true;
3198 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3199 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
3202 // Update the input style and remove the text's style before removing the text.
3204 if( UPDATE_INPUT_STYLE == type )
3206 // Keep a copy of the current input style.
3207 InputStyle currentInputStyle;
3208 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
3210 // Set first the default input style.
3211 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
3213 // Update the input style.
3214 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
3216 // Compare if the input style has changed.
3217 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
3219 if( hasInputStyleChanged )
3221 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
3222 // Queue the input style changed signal.
3223 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
3227 // Updates the text style runs by removing characters. Runs with no characters are removed.
3228 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
3230 // Remove the characters.
3231 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
3232 Vector<Character>::Iterator last = first + numberOfCharacters;
3234 currentText.Erase( first, last );
3236 // Cursor position retreat
3237 oldCursorIndex = cursorIndex;
3239 mImpl->mEventData->mScrollAfterDelete = true;
3241 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
3249 bool Controller::RemoveSelectedText()
3251 bool textRemoved( false );
3253 if( EventData::SELECTING == mImpl->mEventData->mState )
3255 std::string removedString;
3256 mImpl->RetrieveSelection( removedString, true );
3258 if( !removedString.empty() )
3261 mImpl->ChangeState( EventData::EDITING );
3268 // private : Relayout.
3270 bool Controller::DoRelayout( const Size& size,
3271 OperationsMask operationsRequired,
3274 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
3275 bool viewUpdated( false );
3277 // Calculate the operations to be done.
3278 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
3280 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
3281 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
3283 // Get the current layout size.
3284 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3286 if( NO_OPERATION != ( LAYOUT & operations ) )
3288 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
3290 // Some vectors with data needed to layout and reorder may be void
3291 // after the first time the text has been laid out.
3292 // Fill the vectors again.
3294 // Calculate the number of glyphs to layout.
3295 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
3296 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
3297 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
3298 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
3300 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
3301 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
3302 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
3303 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
3305 if( 0u == totalNumberOfGlyphs )
3307 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3309 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
3312 // Nothing else to do if there is no glyphs.
3313 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
3317 const Vector<LineBreakInfo>& lineBreakInfo = mImpl->mModel->mLogicalModel->mLineBreakInfo;
3318 const Vector<WordBreakInfo>& wordBreakInfo = mImpl->mModel->mLogicalModel->mWordBreakInfo;
3319 const Vector<CharacterDirection>& characterDirection = mImpl->mModel->mLogicalModel->mCharacterDirections;
3320 const Vector<GlyphInfo>& glyphs = mImpl->mModel->mVisualModel->mGlyphs;
3321 const Vector<CharacterIndex>& glyphsToCharactersMap = mImpl->mModel->mVisualModel->mGlyphsToCharacters;
3322 const Vector<Length>& charactersPerGlyph = mImpl->mModel->mVisualModel->mCharactersPerGlyph;
3323 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
3324 float outlineWidth = mImpl->mModel->GetOutlineWidth();
3326 // Set the layout parameters.
3327 Layout::Parameters layoutParameters( size,
3329 lineBreakInfo.Begin(),
3330 wordBreakInfo.Begin(),
3331 ( 0u != characterDirection.Count() ) ? characterDirection.Begin() : NULL,
3333 glyphsToCharactersMap.Begin(),
3334 charactersPerGlyph.Begin(),
3335 charactersToGlyphBuffer,
3336 glyphsPerCharacterBuffer,
3337 totalNumberOfGlyphs,
3338 mImpl->mModel->mHorizontalAlignment,
3339 mImpl->mModel->mLineWrapMode,
3342 // Resize the vector of positions to have the same size than the vector of glyphs.
3343 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
3344 glyphPositions.Resize( totalNumberOfGlyphs );
3346 // Whether the last character is a new paragraph character.
3347 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
3348 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
3350 // The initial glyph and the number of glyphs to layout.
3351 layoutParameters.startGlyphIndex = startGlyphIndex;
3352 layoutParameters.numberOfGlyphs = numberOfGlyphs;
3353 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
3354 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
3356 // Update the ellipsis
3357 bool elideTextEnabled = mImpl->mModel->mElideEnabled;
3359 if( NULL != mImpl->mEventData )
3361 if( mImpl->mEventData->mPlaceholderEllipsisFlag && mImpl->IsShowingPlaceholderText() )
3363 elideTextEnabled = mImpl->mEventData->mIsPlaceholderElideEnabled;
3365 else if( EventData::INACTIVE != mImpl->mEventData->mState )
3367 // Disable ellipsis when editing
3368 elideTextEnabled = false;
3371 // Reset the scroll position in inactive state
3372 if( elideTextEnabled && ( mImpl->mEventData->mState == EventData::INACTIVE ) )
3374 ResetScrollPosition();
3378 // Update the visual model.
3380 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
3382 mImpl->mModel->mVisualModel->mLines,
3386 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
3390 layoutSize = newLayoutSize;
3392 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
3394 mImpl->mAutoScrollDirectionRTL = false;
3397 // Reorder the lines
3398 if( NO_OPERATION != ( REORDER & operations ) )
3400 Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = mImpl->mModel->mLogicalModel->mBidirectionalParagraphInfo;
3401 Vector<BidirectionalLineInfoRun>& bidirectionalLineInfo = mImpl->mModel->mLogicalModel->mBidirectionalLineInfo;
3403 // Check first if there are paragraphs with bidirectional info.
3404 if( 0u != bidirectionalInfo.Count() )
3407 const Length numberOfLines = mImpl->mModel->mVisualModel->mLines.Count();
3409 // Reorder the lines.
3410 bidirectionalLineInfo.Reserve( numberOfLines ); // Reserve because is not known yet how many lines have right to left characters.
3411 ReorderLines( bidirectionalInfo,
3413 requestedNumberOfCharacters,
3414 mImpl->mModel->mVisualModel->mLines,
3415 bidirectionalLineInfo );
3417 // Set the bidirectional info per line into the layout parameters.
3418 layoutParameters.lineBidirectionalInfoRunsBuffer = bidirectionalLineInfo.Begin();
3419 layoutParameters.numberOfBidirectionalInfoRuns = bidirectionalLineInfo.Count();
3421 // Re-layout the text. Reorder those lines with right to left characters.
3422 mImpl->mLayoutEngine.ReLayoutRightToLeftLines( layoutParameters,
3424 requestedNumberOfCharacters,
3427 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && ( numberOfLines > 0 ) )
3429 const LineRun* const firstline = mImpl->mModel->mVisualModel->mLines.Begin();
3432 mImpl->mAutoScrollDirectionRTL = firstline->direction;
3438 // Sets the layout size.
3439 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3441 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
3446 if( NO_OPERATION != ( ALIGN & operations ) )
3448 // The laid-out lines.
3449 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
3451 // Need to align with the control's size as the text may contain lines
3452 // starting either with left to right text or right to left.
3453 mImpl->mLayoutEngine.Align( size,
3455 requestedNumberOfCharacters,
3456 mImpl->mModel->mHorizontalAlignment,
3458 mImpl->mModel->mAlignmentOffset );
3462 #if defined(DEBUG_ENABLED)
3463 std::string currentText;
3464 GetText( currentText );
3465 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mAutoScrollDirectionRTL[%s] [%s]\n", this, (mImpl->mAutoScrollDirectionRTL)?"true":"false", currentText.c_str() );
3467 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
3471 void Controller::CalculateVerticalOffset( const Size& controlSize )
3473 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3475 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
3477 // Get the line height of the default font.
3478 layoutSize.height = mImpl->GetDefaultFontLineHeight();
3481 switch( mImpl->mModel->mVerticalAlignment )
3483 case VerticalAlignment::TOP:
3485 mImpl->mModel->mScrollPosition.y = 0.f;
3488 case VerticalAlignment::CENTER:
3490 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
3493 case VerticalAlignment::BOTTOM:
3495 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
3501 // private : Events.
3503 void Controller::ProcessModifyEvents()
3505 Vector<ModifyEvent>& events = mImpl->mModifyEvents;
3507 if( 0u == events.Count() )
3513 for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
3514 endIt = events.End();
3518 const ModifyEvent& event = *it;
3520 if( ModifyEvent::TEXT_REPLACED == event.type )
3522 // A (single) replace event should come first, otherwise we wasted time processing NOOP events
3523 DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
3525 TextReplacedEvent();
3527 else if( ModifyEvent::TEXT_INSERTED == event.type )
3529 TextInsertedEvent();
3531 else if( ModifyEvent::TEXT_DELETED == event.type )
3533 // Placeholder-text cannot be deleted
3534 if( !mImpl->IsShowingPlaceholderText() )
3541 if( NULL != mImpl->mEventData )
3543 // When the text is being modified, delay cursor blinking
3544 mImpl->mEventData->mDecorator->DelayCursorBlink();
3547 // Discard temporary text
3551 void Controller::TextReplacedEvent()
3553 // The natural size needs to be re-calculated.
3554 mImpl->mRecalculateNaturalSize = true;
3556 // Apply modifications to the model
3557 mImpl->mOperationsPending = ALL_OPERATIONS;
3560 void Controller::TextInsertedEvent()
3562 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
3564 if( NULL == mImpl->mEventData )
3569 mImpl->mEventData->mCheckScrollAmount = true;
3571 // The natural size needs to be re-calculated.
3572 mImpl->mRecalculateNaturalSize = true;
3574 // Apply modifications to the model; TODO - Optimize this
3575 mImpl->mOperationsPending = ALL_OPERATIONS;
3578 void Controller::TextDeletedEvent()
3580 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
3582 if( NULL == mImpl->mEventData )
3587 mImpl->mEventData->mCheckScrollAmount = true;
3589 // The natural size needs to be re-calculated.
3590 mImpl->mRecalculateNaturalSize = true;
3592 // Apply modifications to the model; TODO - Optimize this
3593 mImpl->mOperationsPending = ALL_OPERATIONS;
3596 void Controller::SelectEvent( float x, float y, bool selectAll )
3598 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
3600 if( NULL != mImpl->mEventData )
3604 Event event( Event::SELECT_ALL );
3605 mImpl->mEventData->mEventQueue.push_back( event );
3609 Event event( Event::SELECT );
3610 event.p2.mFloat = x;
3611 event.p3.mFloat = y;
3612 mImpl->mEventData->mEventQueue.push_back( event );
3615 mImpl->mEventData->mCheckScrollAmount = true;
3616 mImpl->mEventData->mIsLeftHandleSelected = true;
3617 mImpl->mEventData->mIsRightHandleSelected = true;
3618 mImpl->RequestRelayout();
3622 bool Controller::DeleteEvent( int keyCode )
3624 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p KeyCode : %d \n", this, keyCode );
3626 bool removed = false;
3628 if( NULL == mImpl->mEventData )
3633 // IMF manager is no longer handling key-events
3634 mImpl->ClearPreEditFlag();
3636 if( EventData::SELECTING == mImpl->mEventData->mState )
3638 removed = RemoveSelectedText();
3640 else if( ( mImpl->mEventData->mPrimaryCursorPosition > 0 ) && ( keyCode == Dali::DALI_KEY_BACKSPACE) )
3642 // Remove the character before the current cursor position
3643 removed = RemoveText( -1,
3645 UPDATE_INPUT_STYLE );
3647 else if( ( mImpl->mEventData->mPrimaryCursorPosition >= 0 ) && ( keyCode == Dali::DevelKey::DALI_KEY_DELETE ) )
3649 // Remove the character after the current cursor position
3650 removed = RemoveText( 0,
3652 UPDATE_INPUT_STYLE );
3657 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3658 !mImpl->IsPlaceholderAvailable() )
3660 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3664 ShowPlaceholderText();
3666 mImpl->mEventData->mUpdateCursorPosition = true;
3667 mImpl->mEventData->mScrollAfterDelete = true;
3673 // private : Helpers.
3675 void Controller::ResetText()
3678 mImpl->mModel->mLogicalModel->mText.Clear();
3680 // We have cleared everything including the placeholder-text
3681 mImpl->PlaceholderCleared();
3683 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3684 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3685 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
3687 // Clear any previous text.
3688 mImpl->mTextUpdateInfo.mClearAll = true;
3690 // The natural size needs to be re-calculated.
3691 mImpl->mRecalculateNaturalSize = true;
3693 // Apply modifications to the model
3694 mImpl->mOperationsPending = ALL_OPERATIONS;
3697 void Controller::ShowPlaceholderText()
3699 if( mImpl->IsPlaceholderAvailable() )
3701 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
3703 if( NULL == mImpl->mEventData )
3708 mImpl->mEventData->mIsShowingPlaceholderText = true;
3710 // Disable handles when showing place-holder text
3711 mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
3712 mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
3713 mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
3715 const char* text( NULL );
3718 // TODO - Switch Placeholder text when changing state
3719 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
3720 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
3722 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
3723 size = mImpl->mEventData->mPlaceholderTextActive.size();
3727 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
3728 size = mImpl->mEventData->mPlaceholderTextInactive.size();
3731 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3732 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3734 // Reset model for showing placeholder.
3735 mImpl->mModel->mLogicalModel->mText.Clear();
3736 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
3738 // Convert text into UTF-32
3739 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
3740 utf32Characters.Resize( size );
3742 // This is a bit horrible but std::string returns a (signed) char*
3743 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
3745 // Transform a text array encoded in utf8 into an array encoded in utf32.
3746 // It returns the actual number of characters.
3747 const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
3748 utf32Characters.Resize( characterCount );
3750 // The characters to be added.
3751 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
3753 // Reset the cursor position
3754 mImpl->mEventData->mPrimaryCursorPosition = 0;
3756 // The natural size needs to be re-calculated.
3757 mImpl->mRecalculateNaturalSize = true;
3759 // Apply modifications to the model
3760 mImpl->mOperationsPending = ALL_OPERATIONS;
3762 // Update the rest of the model during size negotiation
3763 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
3767 void Controller::ClearFontData()
3769 if( mImpl->mFontDefaults )
3771 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
3774 // Set flags to update the model.
3775 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3776 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3777 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
3779 mImpl->mTextUpdateInfo.mClearAll = true;
3780 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
3781 mImpl->mRecalculateNaturalSize = true;
3783 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
3788 UPDATE_LAYOUT_SIZE |
3793 void Controller::ClearStyleData()
3795 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
3796 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
3799 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
3801 // Reset the cursor position
3802 if( NULL != mImpl->mEventData )
3804 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
3806 // Update the cursor if it's in editing mode.
3807 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
3809 mImpl->mEventData->mUpdateCursorPosition = true;
3814 void Controller::ResetScrollPosition()
3816 if( NULL != mImpl->mEventData )
3818 // Reset the scroll position.
3819 mImpl->mModel->mScrollPosition = Vector2::ZERO;
3820 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3824 void Controller::SetControlInterface( ControlInterface* controlInterface )
3826 mImpl->mControlInterface = controlInterface;
3829 bool Controller::ShouldClearFocusOnEscape() const
3831 return mImpl->mShouldClearFocusOnEscape;
3834 // private : Private contructors & copy operator.
3836 Controller::Controller()
3839 mImpl = new Controller::Impl( NULL, NULL );
3842 Controller::Controller( ControlInterface* controlInterface )
3844 mImpl = new Controller::Impl( controlInterface, NULL );
3847 Controller::Controller( ControlInterface* controlInterface,
3848 EditableControlInterface* editableControlInterface )
3850 mImpl = new Controller::Impl( controlInterface,
3851 editableControlInterface );
3854 // The copy constructor and operator are left unimplemented.
3856 // protected : Destructor.
3858 Controller::~Controller()
3865 } // namespace Toolkit