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>
30 #include <dali-toolkit/public-api/controls/text-controls/placeholder-properties.h>
31 #include <dali-toolkit/internal/text/bidirectional-support.h>
32 #include <dali-toolkit/internal/text/character-set-conversion.h>
33 #include <dali-toolkit/internal/text/layouts/layout-parameters.h>
34 #include <dali-toolkit/internal/text/markup-processor.h>
35 #include <dali-toolkit/internal/text/multi-language-support.h>
36 #include <dali-toolkit/internal/text/text-controller-impl.h>
37 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
38 #include <dali-toolkit/internal/text/text-font-style.h>
43 #if defined(DEBUG_ENABLED)
44 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
47 const float MAX_FLOAT = std::numeric_limits<float>::max();
49 const std::string EMPTY_STRING("");
51 const char * const PLACEHOLDER_TEXT = "text";
52 const char * const PLACEHOLDER_TEXT_FOCUSED = "textFocused";
53 const char * const PLACEHOLDER_COLOR = "color";
54 const char * const PLACEHOLDER_FONT_FAMILY = "fontFamily";
55 const char * const PLACEHOLDER_FONT_STYLE = "fontStyle";
56 const char * const PLACEHOLDER_POINT_SIZE = "pointSize";
57 const char * const PLACEHOLDER_PIXEL_SIZE = "pixelSize";
58 const char * const PLACEHOLDER_ELLIPSIS = "ellipsis";
60 float ConvertToEven( float value )
62 int intValue(static_cast<int>( value ));
63 return static_cast<float>(intValue % 2 == 0) ? intValue : (intValue + 1);
78 * @brief Adds a new font description run for the selected text.
80 * The new font parameters are added after the call to this method.
82 * @param[in] eventData The event data pointer.
83 * @param[in] logicalModel The logical model where to add the new font description run.
84 * @param[out] startOfSelectedText Index to the first selected character.
85 * @param[out] lengthOfSelectedText Number of selected characters.
87 FontDescriptionRun& UpdateSelectionFontStyleRun( EventData* eventData,
88 LogicalModelPtr logicalModel,
89 CharacterIndex& startOfSelectedText,
90 Length& lengthOfSelectedText )
92 const bool handlesCrossed = eventData->mLeftSelectionPosition > eventData->mRightSelectionPosition;
94 // Get start and end position of selection
95 startOfSelectedText = handlesCrossed ? eventData->mRightSelectionPosition : eventData->mLeftSelectionPosition;
96 lengthOfSelectedText = ( handlesCrossed ? eventData->mLeftSelectionPosition : eventData->mRightSelectionPosition ) - startOfSelectedText;
99 const VectorBase::SizeType numberOfRuns = logicalModel->mFontDescriptionRuns.Count();
100 logicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
102 FontDescriptionRun& fontDescriptionRun = *( logicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
104 fontDescriptionRun.characterRun.characterIndex = startOfSelectedText;
105 fontDescriptionRun.characterRun.numberOfCharacters = lengthOfSelectedText;
107 // Recalculate the selection highlight as the metrics may have changed.
108 eventData->mUpdateLeftSelectionPosition = true;
109 eventData->mUpdateRightSelectionPosition = true;
110 eventData->mUpdateHighlightBox = true;
112 return fontDescriptionRun;
115 // public : Constructor.
117 ControllerPtr Controller::New()
119 return ControllerPtr( new Controller() );
122 ControllerPtr Controller::New( ControlInterface* controlInterface )
124 return ControllerPtr( new Controller( controlInterface ) );
127 ControllerPtr Controller::New( ControlInterface* controlInterface,
128 EditableControlInterface* editableControlInterface )
130 return ControllerPtr( new Controller( controlInterface,
131 editableControlInterface ) );
134 // public : Configure the text controller.
136 void Controller::EnableTextInput( DecoratorPtr decorator )
140 delete mImpl->mEventData;
141 mImpl->mEventData = NULL;
143 // Nothing else to do.
147 if( NULL == mImpl->mEventData )
149 mImpl->mEventData = new EventData( decorator );
153 void Controller::SetGlyphType( TextAbstraction::GlyphType glyphType )
155 // Metrics for bitmap & vector based glyphs are different
156 mImpl->mMetrics->SetGlyphType( glyphType );
158 // Clear the font-specific data
161 mImpl->RequestRelayout();
164 void Controller::SetMarkupProcessorEnabled( bool enable )
166 mImpl->mMarkupProcessorEnabled = enable;
169 bool Controller::IsMarkupProcessorEnabled() const
171 return mImpl->mMarkupProcessorEnabled;
174 void Controller::SetAutoScrollEnabled( bool enable )
176 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 );
178 if( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX )
182 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled for SINGLE_LINE_BOX\n" );
183 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
193 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled Disabling autoscroll\n");
194 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
201 mImpl->mIsAutoScrollEnabled = enable;
202 mImpl->RequestRelayout();
206 DALI_LOG_WARNING( "Attempted AutoScrolling on a non SINGLE_LINE_BOX, request ignored\n" );
207 mImpl->mIsAutoScrollEnabled = false;
211 bool Controller::IsAutoScrollEnabled() const
213 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::IsAutoScrollEnabled[%s]\n", mImpl->mIsAutoScrollEnabled?"true":"false" );
215 return mImpl->mIsAutoScrollEnabled;
218 CharacterDirection Controller::GetAutoScrollDirection() const
220 return mImpl->mAutoScrollDirectionRTL;
223 float Controller::GetAutoScrollLineAlignment() const
227 if( mImpl->mModel->mVisualModel &&
228 ( 0u != mImpl->mModel->mVisualModel->mLines.Count() ) )
230 offset = ( *mImpl->mModel->mVisualModel->mLines.Begin() ).alignmentOffset;
236 void Controller::SetHorizontalScrollEnabled( bool enable )
238 if( ( NULL != mImpl->mEventData ) &&
239 mImpl->mEventData->mDecorator )
241 mImpl->mEventData->mDecorator->SetHorizontalScrollEnabled( enable );
244 bool Controller::IsHorizontalScrollEnabled() const
246 if( ( NULL != mImpl->mEventData ) &&
247 mImpl->mEventData->mDecorator )
249 return mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
255 void Controller::SetVerticalScrollEnabled( bool enable )
257 if( ( NULL != mImpl->mEventData ) &&
258 mImpl->mEventData->mDecorator )
260 if( mImpl->mEventData->mDecorator )
262 mImpl->mEventData->mDecorator->SetVerticalScrollEnabled( enable );
267 bool Controller::IsVerticalScrollEnabled() const
269 if( ( NULL != mImpl->mEventData ) &&
270 mImpl->mEventData->mDecorator )
272 return mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
278 void Controller::SetSmoothHandlePanEnabled( bool enable )
280 if( ( NULL != mImpl->mEventData ) &&
281 mImpl->mEventData->mDecorator )
283 mImpl->mEventData->mDecorator->SetSmoothHandlePanEnabled( enable );
287 bool Controller::IsSmoothHandlePanEnabled() const
289 if( ( NULL != mImpl->mEventData ) &&
290 mImpl->mEventData->mDecorator )
292 return mImpl->mEventData->mDecorator->IsSmoothHandlePanEnabled();
298 void Controller::SetMaximumNumberOfCharacters( Length maxCharacters )
300 mImpl->mMaximumNumberOfCharacters = maxCharacters;
303 int Controller::GetMaximumNumberOfCharacters()
305 return mImpl->mMaximumNumberOfCharacters;
308 void Controller::SetEnableCursorBlink( bool enable )
310 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "TextInput disabled" );
312 if( NULL != mImpl->mEventData )
314 mImpl->mEventData->mCursorBlinkEnabled = enable;
317 mImpl->mEventData->mDecorator )
319 mImpl->mEventData->mDecorator->StopCursorBlink();
324 bool Controller::GetEnableCursorBlink() const
326 if( NULL != mImpl->mEventData )
328 return mImpl->mEventData->mCursorBlinkEnabled;
334 void Controller::SetMultiLineEnabled( bool enable )
336 const Layout::Engine::Type layout = enable ? Layout::Engine::MULTI_LINE_BOX : Layout::Engine::SINGLE_LINE_BOX;
338 if( layout != mImpl->mLayoutEngine.GetLayout() )
340 // Set the layout type.
341 mImpl->mLayoutEngine.SetLayout( layout );
343 // Set the flags to redo the layout operations
344 const OperationsMask layoutOperations = static_cast<OperationsMask>( LAYOUT |
349 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | layoutOperations );
351 mImpl->RequestRelayout();
355 bool Controller::IsMultiLineEnabled() const
357 return Layout::Engine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
360 void Controller::SetHorizontalAlignment( Text::HorizontalAlignment::Type alignment )
362 if( alignment != mImpl->mModel->mHorizontalAlignment )
364 // Set the alignment.
365 mImpl->mModel->mHorizontalAlignment = alignment;
367 // Set the flag to redo the alignment operation.
368 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
370 mImpl->RequestRelayout();
374 Text::HorizontalAlignment::Type Controller::GetHorizontalAlignment() const
376 return mImpl->mModel->mHorizontalAlignment;
379 void Controller::SetVerticalAlignment( VerticalAlignment::Type alignment )
381 if( alignment != mImpl->mModel->mVerticalAlignment )
383 // Set the alignment.
384 mImpl->mModel->mVerticalAlignment = alignment;
386 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
388 mImpl->RequestRelayout();
392 VerticalAlignment::Type Controller::GetVerticalAlignment() const
394 return mImpl->mModel->mVerticalAlignment;
397 void Controller::SetLineWrapMode( Text::LineWrap::Mode lineWrapMode )
399 if( lineWrapMode != mImpl->mModel->mLineWrapMode )
401 // Set the text wrap mode.
402 mImpl->mModel->mLineWrapMode = lineWrapMode;
405 // Update Text layout for applying wrap mode
406 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
411 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
412 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
413 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
416 mImpl->RequestRelayout();
420 Text::LineWrap::Mode Controller::GetLineWrapMode() const
422 return mImpl->mModel->mLineWrapMode;
425 void Controller::SetTextElideEnabled( bool enabled )
427 mImpl->mModel->mElideEnabled = enabled;
430 bool Controller::IsTextElideEnabled() const
432 return mImpl->mModel->mElideEnabled;
435 void Controller::SetPlaceholderTextElideEnabled( bool enabled )
437 mImpl->mEventData->mIsPlaceholderElideEnabled = enabled;
438 mImpl->mEventData->mPlaceholderEllipsisFlag = true;
440 // Update placeholder if there is no text
441 if( mImpl->IsShowingPlaceholderText() ||
442 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
444 ShowPlaceholderText();
448 bool Controller::IsPlaceholderTextElideEnabled() const
450 return mImpl->mEventData->mIsPlaceholderElideEnabled;
453 void Controller::SetSelectionEnabled( bool enabled )
455 mImpl->mEventData->mSelectionEnabled = enabled;
458 bool Controller::IsSelectionEnabled() const
460 return mImpl->mEventData->mSelectionEnabled;
465 void Controller::SetText( const std::string& text )
467 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" );
469 // Reset keyboard as text changed
470 mImpl->ResetImfManager();
472 // Remove the previously set text and style.
478 CharacterIndex lastCursorIndex = 0u;
480 if( NULL != mImpl->mEventData )
482 // If popup shown then hide it by switching to Editing state
483 if( ( EventData::SELECTING == mImpl->mEventData->mState ) ||
484 ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
485 ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) ||
486 ( EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState ) )
488 mImpl->ChangeState( EventData::EDITING );
494 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mTextColor );
496 MarkupProcessData markupProcessData( mImpl->mModel->mLogicalModel->mColorRuns,
497 mImpl->mModel->mLogicalModel->mFontDescriptionRuns );
499 Length textSize = 0u;
500 const uint8_t* utf8 = NULL;
501 if( mImpl->mMarkupProcessorEnabled )
503 ProcessMarkupString( text, markupProcessData );
504 textSize = markupProcessData.markupProcessedText.size();
506 // This is a bit horrible but std::string returns a (signed) char*
507 utf8 = reinterpret_cast<const uint8_t*>( markupProcessData.markupProcessedText.c_str() );
511 textSize = text.size();
513 // This is a bit horrible but std::string returns a (signed) char*
514 utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
517 // Convert text into UTF-32
518 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
519 utf32Characters.Resize( textSize );
521 // Transform a text array encoded in utf8 into an array encoded in utf32.
522 // It returns the actual number of characters.
523 Length characterCount = Utf8ToUtf32( utf8, textSize, utf32Characters.Begin() );
524 utf32Characters.Resize( characterCount );
526 DALI_ASSERT_DEBUG( textSize >= characterCount && "Invalid UTF32 conversion length" );
527 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", this, textSize, mImpl->mModel->mLogicalModel->mText.Count() );
529 // The characters to be added.
530 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
532 // To reset the cursor position
533 lastCursorIndex = characterCount;
535 // Update the rest of the model during size negotiation
536 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
538 // The natural size needs to be re-calculated.
539 mImpl->mRecalculateNaturalSize = true;
541 // Apply modifications to the model
542 mImpl->mOperationsPending = ALL_OPERATIONS;
546 ShowPlaceholderText();
549 // Resets the cursor position.
550 ResetCursorPosition( lastCursorIndex );
552 // Scrolls the text to make the cursor visible.
553 ResetScrollPosition();
555 mImpl->RequestRelayout();
557 if( NULL != mImpl->mEventData )
559 // Cancel previously queued events
560 mImpl->mEventData->mEventQueue.clear();
563 // Do this last since it provides callbacks into application code.
564 if( NULL != mImpl->mEditableControlInterface )
566 mImpl->mEditableControlInterface->TextChanged();
570 void Controller::GetText( std::string& text ) const
572 if( !mImpl->IsShowingPlaceholderText() )
574 // Retrieves the text string.
575 mImpl->GetText( 0u, text );
579 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this );
583 void Controller::SetPlaceholderText( PlaceholderType type, const std::string& text )
585 if( NULL != mImpl->mEventData )
587 if( PLACEHOLDER_TYPE_INACTIVE == type )
589 mImpl->mEventData->mPlaceholderTextInactive = text;
593 mImpl->mEventData->mPlaceholderTextActive = text;
596 // Update placeholder if there is no text
597 if( mImpl->IsShowingPlaceholderText() ||
598 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
600 ShowPlaceholderText();
605 void Controller::GetPlaceholderText( PlaceholderType type, std::string& text ) const
607 if( NULL != mImpl->mEventData )
609 if( PLACEHOLDER_TYPE_INACTIVE == type )
611 text = mImpl->mEventData->mPlaceholderTextInactive;
615 text = mImpl->mEventData->mPlaceholderTextActive;
620 void Controller::UpdateAfterFontChange( const std::string& newDefaultFont )
622 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
624 if( !mImpl->mFontDefaults->familyDefined ) // If user defined font then should not update when system font changes
626 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
627 mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
631 mImpl->RequestRelayout();
635 // public : Default style & Input style
637 void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
639 if( NULL == mImpl->mFontDefaults )
641 mImpl->mFontDefaults = new FontDefaults();
644 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
645 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
646 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
648 // Clear the font-specific data
651 mImpl->RequestRelayout();
654 const std::string& Controller::GetDefaultFontFamily() const
656 if( NULL != mImpl->mFontDefaults )
658 return mImpl->mFontDefaults->mFontDescription.family;
664 void Controller::SetPlaceholderFontFamily( const std::string& placeholderTextFontFamily )
666 if( NULL != mImpl->mEventData )
668 if( NULL == mImpl->mEventData->mPlaceholderFont )
670 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
673 mImpl->mEventData->mPlaceholderFont->mFontDescription.family = placeholderTextFontFamily;
674 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetPlaceholderFontFamily %s\n", placeholderTextFontFamily.c_str());
675 mImpl->mEventData->mPlaceholderFont->familyDefined = !placeholderTextFontFamily.empty();
677 mImpl->RequestRelayout();
681 const std::string& Controller::GetPlaceholderFontFamily() const
683 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
685 return mImpl->mEventData->mPlaceholderFont->mFontDescription.family;
691 void Controller::SetDefaultFontWeight( FontWeight weight )
693 if( NULL == mImpl->mFontDefaults )
695 mImpl->mFontDefaults = new FontDefaults();
698 mImpl->mFontDefaults->mFontDescription.weight = weight;
699 mImpl->mFontDefaults->weightDefined = true;
701 // Clear the font-specific data
704 mImpl->RequestRelayout();
707 bool Controller::IsDefaultFontWeightDefined() const
709 if( NULL != mImpl->mFontDefaults )
711 return mImpl->mFontDefaults->weightDefined;
717 FontWeight Controller::GetDefaultFontWeight() const
719 if( NULL != mImpl->mFontDefaults )
721 return mImpl->mFontDefaults->mFontDescription.weight;
724 return TextAbstraction::FontWeight::NORMAL;
727 void Controller::SetPlaceholderTextFontWeight( FontWeight weight )
729 if( NULL != mImpl->mEventData )
731 if( NULL == mImpl->mEventData->mPlaceholderFont )
733 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
736 mImpl->mEventData->mPlaceholderFont->mFontDescription.weight = weight;
737 mImpl->mEventData->mPlaceholderFont->weightDefined = true;
739 mImpl->RequestRelayout();
743 bool Controller::IsPlaceholderTextFontWeightDefined() const
745 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
747 return mImpl->mEventData->mPlaceholderFont->weightDefined;
752 FontWeight Controller::GetPlaceholderTextFontWeight() const
754 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
756 return mImpl->mEventData->mPlaceholderFont->mFontDescription.weight;
759 return TextAbstraction::FontWeight::NORMAL;
762 void Controller::SetDefaultFontWidth( FontWidth width )
764 if( NULL == mImpl->mFontDefaults )
766 mImpl->mFontDefaults = new FontDefaults();
769 mImpl->mFontDefaults->mFontDescription.width = width;
770 mImpl->mFontDefaults->widthDefined = true;
772 // Clear the font-specific data
775 mImpl->RequestRelayout();
778 bool Controller::IsDefaultFontWidthDefined() const
780 if( NULL != mImpl->mFontDefaults )
782 return mImpl->mFontDefaults->widthDefined;
788 FontWidth Controller::GetDefaultFontWidth() const
790 if( NULL != mImpl->mFontDefaults )
792 return mImpl->mFontDefaults->mFontDescription.width;
795 return TextAbstraction::FontWidth::NORMAL;
798 void Controller::SetPlaceholderTextFontWidth( FontWidth width )
800 if( NULL != mImpl->mEventData )
802 if( NULL == mImpl->mEventData->mPlaceholderFont )
804 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
807 mImpl->mEventData->mPlaceholderFont->mFontDescription.width = width;
808 mImpl->mEventData->mPlaceholderFont->widthDefined = true;
810 mImpl->RequestRelayout();
814 bool Controller::IsPlaceholderTextFontWidthDefined() const
816 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
818 return mImpl->mEventData->mPlaceholderFont->widthDefined;
823 FontWidth Controller::GetPlaceholderTextFontWidth() const
825 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
827 return mImpl->mEventData->mPlaceholderFont->mFontDescription.width;
830 return TextAbstraction::FontWidth::NORMAL;
833 void Controller::SetDefaultFontSlant( FontSlant slant )
835 if( NULL == mImpl->mFontDefaults )
837 mImpl->mFontDefaults = new FontDefaults();
840 mImpl->mFontDefaults->mFontDescription.slant = slant;
841 mImpl->mFontDefaults->slantDefined = true;
843 // Clear the font-specific data
846 mImpl->RequestRelayout();
849 bool Controller::IsDefaultFontSlantDefined() const
851 if( NULL != mImpl->mFontDefaults )
853 return mImpl->mFontDefaults->slantDefined;
858 FontSlant Controller::GetDefaultFontSlant() const
860 if( NULL != mImpl->mFontDefaults )
862 return mImpl->mFontDefaults->mFontDescription.slant;
865 return TextAbstraction::FontSlant::NORMAL;
868 void Controller::SetPlaceholderTextFontSlant( FontSlant slant )
870 if( NULL != mImpl->mEventData )
872 if( NULL == mImpl->mEventData->mPlaceholderFont )
874 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
877 mImpl->mEventData->mPlaceholderFont->mFontDescription.slant = slant;
878 mImpl->mEventData->mPlaceholderFont->slantDefined = true;
880 mImpl->RequestRelayout();
884 bool Controller::IsPlaceholderTextFontSlantDefined() const
886 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
888 return mImpl->mEventData->mPlaceholderFont->slantDefined;
893 FontSlant Controller::GetPlaceholderTextFontSlant() const
895 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
897 return mImpl->mEventData->mPlaceholderFont->mFontDescription.slant;
900 return TextAbstraction::FontSlant::NORMAL;
903 void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
905 if( NULL == mImpl->mFontDefaults )
907 mImpl->mFontDefaults = new FontDefaults();
914 mImpl->mFontDefaults->mDefaultPointSize = fontSize;
915 mImpl->mFontDefaults->sizeDefined = true;
920 // Point size = Pixel size * 72.f / DPI
921 unsigned int horizontalDpi = 0u;
922 unsigned int verticalDpi = 0u;
923 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
924 fontClient.GetDpi( horizontalDpi, verticalDpi );
926 mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
927 mImpl->mFontDefaults->sizeDefined = true;
932 // Clear the font-specific data
935 mImpl->RequestRelayout();
938 float Controller::GetDefaultFontSize( FontSizeType type ) const
941 if( NULL != mImpl->mFontDefaults )
947 value = mImpl->mFontDefaults->mDefaultPointSize;
952 // Pixel size = Point size * DPI / 72.f
953 unsigned int horizontalDpi = 0u;
954 unsigned int verticalDpi = 0u;
955 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
956 fontClient.GetDpi( horizontalDpi, verticalDpi );
958 value = mImpl->mFontDefaults->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
968 void Controller::SetPlaceholderTextFontSize( float fontSize, FontSizeType type )
970 if( NULL != mImpl->mEventData )
972 if( NULL == mImpl->mEventData->mPlaceholderFont )
974 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
981 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = fontSize;
982 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
983 mImpl->mEventData->mIsPlaceholderPixelSize = false; // Font size flag
988 // Point size = Pixel size * 72.f / DPI
989 unsigned int horizontalDpi = 0u;
990 unsigned int verticalDpi = 0u;
991 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
992 fontClient.GetDpi( horizontalDpi, verticalDpi );
994 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
995 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
996 mImpl->mEventData->mIsPlaceholderPixelSize = true; // Font size flag
1001 mImpl->RequestRelayout();
1005 float Controller::GetPlaceholderTextFontSize( FontSizeType type ) const
1008 if( NULL != mImpl->mEventData )
1014 if( NULL != mImpl->mEventData->mPlaceholderFont )
1016 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize;
1020 // If the placeholder text font size is not set, then return the default font size.
1021 value = GetDefaultFontSize( POINT_SIZE );
1027 if( NULL != mImpl->mEventData->mPlaceholderFont )
1029 // Pixel size = Point size * DPI / 72.f
1030 unsigned int horizontalDpi = 0u;
1031 unsigned int verticalDpi = 0u;
1032 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1033 fontClient.GetDpi( horizontalDpi, verticalDpi );
1035 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1039 // If the placeholder text font size is not set, then return the default font size.
1040 value = GetDefaultFontSize( PIXEL_SIZE );
1051 void Controller::SetDefaultColor( const Vector4& color )
1053 mImpl->mTextColor = color;
1055 if( !mImpl->IsShowingPlaceholderText() )
1057 mImpl->mModel->mVisualModel->SetTextColor( color );
1059 mImpl->RequestRelayout();
1063 const Vector4& Controller::GetDefaultColor() const
1065 return mImpl->mTextColor;
1068 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
1070 if( NULL != mImpl->mEventData )
1072 mImpl->mEventData->mPlaceholderTextColor = textColor;
1075 if( mImpl->IsShowingPlaceholderText() )
1077 mImpl->mModel->mVisualModel->SetTextColor( textColor );
1078 mImpl->RequestRelayout();
1082 const Vector4& Controller::GetPlaceholderTextColor() const
1084 if( NULL != mImpl->mEventData )
1086 return mImpl->mEventData->mPlaceholderTextColor;
1089 return Color::BLACK;
1092 void Controller::SetShadowOffset( const Vector2& shadowOffset )
1094 mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
1096 mImpl->RequestRelayout();
1099 const Vector2& Controller::GetShadowOffset() const
1101 return mImpl->mModel->mVisualModel->GetShadowOffset();
1104 void Controller::SetShadowColor( const Vector4& shadowColor )
1106 mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
1108 mImpl->RequestRelayout();
1111 const Vector4& Controller::GetShadowColor() const
1113 return mImpl->mModel->mVisualModel->GetShadowColor();
1116 void Controller::SetShadowBlurRadius( const float& shadowBlurRadius )
1118 if ( fabsf( GetShadowBlurRadius() - shadowBlurRadius ) > Math::MACHINE_EPSILON_1 )
1120 mImpl->mModel->mVisualModel->SetShadowBlurRadius( shadowBlurRadius );
1122 mImpl->RequestRelayout();
1126 const float& Controller::GetShadowBlurRadius() const
1128 return mImpl->mModel->mVisualModel->GetShadowBlurRadius();
1131 void Controller::SetUnderlineColor( const Vector4& color )
1133 mImpl->mModel->mVisualModel->SetUnderlineColor( color );
1135 mImpl->RequestRelayout();
1138 const Vector4& Controller::GetUnderlineColor() const
1140 return mImpl->mModel->mVisualModel->GetUnderlineColor();
1143 void Controller::SetUnderlineEnabled( bool enabled )
1145 mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
1147 mImpl->RequestRelayout();
1150 bool Controller::IsUnderlineEnabled() const
1152 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
1155 void Controller::SetUnderlineHeight( float height )
1157 mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
1159 mImpl->RequestRelayout();
1162 float Controller::GetUnderlineHeight() const
1164 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
1167 void Controller::SetOutlineColor( const Vector4& color )
1169 mImpl->mModel->mVisualModel->SetOutlineColor( color );
1171 mImpl->RequestRelayout();
1174 const Vector4& Controller::GetOutlineColor() const
1176 return mImpl->mModel->mVisualModel->GetOutlineColor();
1179 void Controller::SetOutlineWidth( float width )
1181 mImpl->mModel->mVisualModel->SetOutlineWidth( width );
1183 mImpl->RequestRelayout();
1186 float Controller::GetOutlineWidth() const
1188 return mImpl->mModel->mVisualModel->GetOutlineWidth();
1191 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
1193 if( NULL == mImpl->mEmbossDefaults )
1195 mImpl->mEmbossDefaults = new EmbossDefaults();
1198 mImpl->mEmbossDefaults->properties = embossProperties;
1201 const std::string& Controller::GetDefaultEmbossProperties() const
1203 if( NULL != mImpl->mEmbossDefaults )
1205 return mImpl->mEmbossDefaults->properties;
1208 return EMPTY_STRING;
1211 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
1213 if( NULL == mImpl->mOutlineDefaults )
1215 mImpl->mOutlineDefaults = new OutlineDefaults();
1218 mImpl->mOutlineDefaults->properties = outlineProperties;
1221 const std::string& Controller::GetDefaultOutlineProperties() const
1223 if( NULL != mImpl->mOutlineDefaults )
1225 return mImpl->mOutlineDefaults->properties;
1228 return EMPTY_STRING;
1231 void Controller::SetDefaultLineSpacing( float lineSpacing )
1233 //TODO finish implementation
1234 mImpl->mLayoutEngine.SetDefaultLineSpacing( lineSpacing );
1237 float Controller::GetDefaultLineSpacing() const
1239 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
1242 void Controller::SetInputColor( const Vector4& color )
1244 if( NULL != mImpl->mEventData )
1246 mImpl->mEventData->mInputStyle.textColor = color;
1247 mImpl->mEventData->mInputStyle.isDefaultColor = false;
1249 if( EventData::SELECTING == mImpl->mEventData->mState )
1251 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
1253 // Get start and end position of selection
1254 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
1255 const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
1257 // Add the color run.
1258 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1259 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
1261 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
1262 colorRun.color = color;
1263 colorRun.characterRun.characterIndex = startOfSelectedText;
1264 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1266 // Request to relayout.
1267 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1268 mImpl->RequestRelayout();
1270 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1271 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1272 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1277 const Vector4& Controller::GetInputColor() const
1279 if( NULL != mImpl->mEventData )
1281 return mImpl->mEventData->mInputStyle.textColor;
1284 // Return the default text's color if there is no EventData.
1285 return mImpl->mTextColor;
1289 void Controller::SetInputFontFamily( const std::string& fontFamily )
1291 if( NULL != mImpl->mEventData )
1293 mImpl->mEventData->mInputStyle.familyName = fontFamily;
1294 mImpl->mEventData->mInputStyle.isFamilyDefined = true;
1296 if( EventData::SELECTING == mImpl->mEventData->mState )
1298 CharacterIndex startOfSelectedText = 0u;
1299 Length lengthOfSelectedText = 0u;
1300 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1301 mImpl->mModel->mLogicalModel,
1302 startOfSelectedText,
1303 lengthOfSelectedText );
1305 fontDescriptionRun.familyLength = fontFamily.size();
1306 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
1307 memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength );
1308 fontDescriptionRun.familyDefined = true;
1310 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
1312 // Request to relayout.
1313 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1318 UPDATE_LAYOUT_SIZE |
1321 mImpl->mRecalculateNaturalSize = true;
1322 mImpl->RequestRelayout();
1324 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1325 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1326 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1328 // As the font changes, recalculate the handle positions is needed.
1329 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1330 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1331 mImpl->mEventData->mUpdateHighlightBox = true;
1332 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1337 const std::string& Controller::GetInputFontFamily() const
1339 if( NULL != mImpl->mEventData )
1341 return mImpl->mEventData->mInputStyle.familyName;
1344 // Return the default font's family if there is no EventData.
1345 return GetDefaultFontFamily();
1348 void Controller::SetInputFontWeight( FontWeight weight )
1350 if( NULL != mImpl->mEventData )
1352 mImpl->mEventData->mInputStyle.weight = weight;
1353 mImpl->mEventData->mInputStyle.isWeightDefined = true;
1355 if( EventData::SELECTING == mImpl->mEventData->mState )
1357 CharacterIndex startOfSelectedText = 0u;
1358 Length lengthOfSelectedText = 0u;
1359 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1360 mImpl->mModel->mLogicalModel,
1361 startOfSelectedText,
1362 lengthOfSelectedText );
1364 fontDescriptionRun.weight = weight;
1365 fontDescriptionRun.weightDefined = true;
1367 // Request to relayout.
1368 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1373 UPDATE_LAYOUT_SIZE |
1376 mImpl->mRecalculateNaturalSize = true;
1377 mImpl->RequestRelayout();
1379 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1380 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1381 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1383 // As the font might change, recalculate the handle positions is needed.
1384 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1385 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1386 mImpl->mEventData->mUpdateHighlightBox = true;
1387 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1392 bool Controller::IsInputFontWeightDefined() const
1394 bool defined = false;
1396 if( NULL != mImpl->mEventData )
1398 defined = mImpl->mEventData->mInputStyle.isWeightDefined;
1404 FontWeight Controller::GetInputFontWeight() const
1406 if( NULL != mImpl->mEventData )
1408 return mImpl->mEventData->mInputStyle.weight;
1411 return GetDefaultFontWeight();
1414 void Controller::SetInputFontWidth( FontWidth width )
1416 if( NULL != mImpl->mEventData )
1418 mImpl->mEventData->mInputStyle.width = width;
1419 mImpl->mEventData->mInputStyle.isWidthDefined = true;
1421 if( EventData::SELECTING == mImpl->mEventData->mState )
1423 CharacterIndex startOfSelectedText = 0u;
1424 Length lengthOfSelectedText = 0u;
1425 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1426 mImpl->mModel->mLogicalModel,
1427 startOfSelectedText,
1428 lengthOfSelectedText );
1430 fontDescriptionRun.width = width;
1431 fontDescriptionRun.widthDefined = true;
1433 // Request to relayout.
1434 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1439 UPDATE_LAYOUT_SIZE |
1442 mImpl->mRecalculateNaturalSize = true;
1443 mImpl->RequestRelayout();
1445 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1446 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1447 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1449 // As the font might change, recalculate the handle positions is needed.
1450 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1451 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1452 mImpl->mEventData->mUpdateHighlightBox = true;
1453 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1458 bool Controller::IsInputFontWidthDefined() const
1460 bool defined = false;
1462 if( NULL != mImpl->mEventData )
1464 defined = mImpl->mEventData->mInputStyle.isWidthDefined;
1470 FontWidth Controller::GetInputFontWidth() const
1472 if( NULL != mImpl->mEventData )
1474 return mImpl->mEventData->mInputStyle.width;
1477 return GetDefaultFontWidth();
1480 void Controller::SetInputFontSlant( FontSlant slant )
1482 if( NULL != mImpl->mEventData )
1484 mImpl->mEventData->mInputStyle.slant = slant;
1485 mImpl->mEventData->mInputStyle.isSlantDefined = true;
1487 if( EventData::SELECTING == mImpl->mEventData->mState )
1489 CharacterIndex startOfSelectedText = 0u;
1490 Length lengthOfSelectedText = 0u;
1491 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1492 mImpl->mModel->mLogicalModel,
1493 startOfSelectedText,
1494 lengthOfSelectedText );
1496 fontDescriptionRun.slant = slant;
1497 fontDescriptionRun.slantDefined = true;
1499 // Request to relayout.
1500 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1505 UPDATE_LAYOUT_SIZE |
1508 mImpl->mRecalculateNaturalSize = true;
1509 mImpl->RequestRelayout();
1511 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1512 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1513 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1515 // As the font might change, recalculate the handle positions is needed.
1516 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1517 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1518 mImpl->mEventData->mUpdateHighlightBox = true;
1519 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1524 bool Controller::IsInputFontSlantDefined() const
1526 bool defined = false;
1528 if( NULL != mImpl->mEventData )
1530 defined = mImpl->mEventData->mInputStyle.isSlantDefined;
1536 FontSlant Controller::GetInputFontSlant() const
1538 if( NULL != mImpl->mEventData )
1540 return mImpl->mEventData->mInputStyle.slant;
1543 return GetDefaultFontSlant();
1546 void Controller::SetInputFontPointSize( float size )
1548 if( NULL != mImpl->mEventData )
1550 mImpl->mEventData->mInputStyle.size = size;
1551 mImpl->mEventData->mInputStyle.isSizeDefined = true;
1553 if( EventData::SELECTING == mImpl->mEventData->mState )
1555 CharacterIndex startOfSelectedText = 0u;
1556 Length lengthOfSelectedText = 0u;
1557 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1558 mImpl->mModel->mLogicalModel,
1559 startOfSelectedText,
1560 lengthOfSelectedText );
1562 fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
1563 fontDescriptionRun.sizeDefined = true;
1565 // Request to relayout.
1566 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1571 UPDATE_LAYOUT_SIZE |
1574 mImpl->mRecalculateNaturalSize = true;
1575 mImpl->RequestRelayout();
1577 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1578 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1579 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1581 // As the font might change, recalculate the handle positions is needed.
1582 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1583 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1584 mImpl->mEventData->mUpdateHighlightBox = true;
1585 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1590 float Controller::GetInputFontPointSize() const
1592 if( NULL != mImpl->mEventData )
1594 return mImpl->mEventData->mInputStyle.size;
1597 // Return the default font's point size if there is no EventData.
1598 return GetDefaultFontSize( Text::Controller::POINT_SIZE );
1601 void Controller::SetInputLineSpacing( float lineSpacing )
1603 if( NULL != mImpl->mEventData )
1605 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1606 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1610 float Controller::GetInputLineSpacing() const
1612 if( NULL != mImpl->mEventData )
1614 return mImpl->mEventData->mInputStyle.lineSpacing;
1620 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1622 if( NULL != mImpl->mEventData )
1624 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1628 const std::string& Controller::GetInputShadowProperties() const
1630 if( NULL != mImpl->mEventData )
1632 return mImpl->mEventData->mInputStyle.shadowProperties;
1635 return EMPTY_STRING;
1638 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1640 if( NULL != mImpl->mEventData )
1642 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1646 const std::string& Controller::GetInputUnderlineProperties() const
1648 if( NULL != mImpl->mEventData )
1650 return mImpl->mEventData->mInputStyle.underlineProperties;
1653 return EMPTY_STRING;
1656 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
1658 if( NULL != mImpl->mEventData )
1660 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1664 const std::string& Controller::GetInputEmbossProperties() const
1666 if( NULL != mImpl->mEventData )
1668 return mImpl->mEventData->mInputStyle.embossProperties;
1671 return GetDefaultEmbossProperties();
1674 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
1676 if( NULL != mImpl->mEventData )
1678 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1682 const std::string& Controller::GetInputOutlineProperties() const
1684 if( NULL != mImpl->mEventData )
1686 return mImpl->mEventData->mInputStyle.outlineProperties;
1689 return GetDefaultOutlineProperties();
1692 void Controller::SetInputModePassword( bool passwordInput )
1694 if( NULL != mImpl->mEventData )
1696 mImpl->mEventData->mPasswordInput = passwordInput;
1700 bool Controller::IsInputModePassword()
1702 if( NULL != mImpl->mEventData )
1704 return mImpl->mEventData->mPasswordInput;
1709 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
1711 if( NULL != mImpl->mEventData )
1713 mImpl->mEventData->mDoubleTapAction = action;
1717 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1719 NoTextTap::Action action = NoTextTap::NO_ACTION;
1721 if( NULL != mImpl->mEventData )
1723 action = mImpl->mEventData->mDoubleTapAction;
1729 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
1731 if( NULL != mImpl->mEventData )
1733 mImpl->mEventData->mLongPressAction = action;
1737 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1739 NoTextTap::Action action = NoTextTap::NO_ACTION;
1741 if( NULL != mImpl->mEventData )
1743 action = mImpl->mEventData->mLongPressAction;
1749 bool Controller::IsUnderlineSetByString()
1751 return mImpl->mUnderlineSetByString;
1754 void Controller::UnderlineSetByString( bool setByString )
1756 mImpl->mUnderlineSetByString = setByString;
1759 bool Controller::IsShadowSetByString()
1761 return mImpl->mShadowSetByString;
1764 void Controller::ShadowSetByString( bool setByString )
1766 mImpl->mShadowSetByString = setByString;
1769 bool Controller::IsOutlineSetByString()
1771 return mImpl->mOutlineSetByString;
1774 void Controller::OutlineSetByString( bool setByString )
1776 mImpl->mOutlineSetByString = setByString;
1779 bool Controller::IsFontStyleSetByString()
1781 return mImpl->mFontStyleSetByString;
1784 void Controller::FontStyleSetByString( bool setByString )
1786 mImpl->mFontStyleSetByString = setByString;
1789 // public : Queries & retrieves.
1791 Layout::Engine& Controller::GetLayoutEngine()
1793 return mImpl->mLayoutEngine;
1796 View& Controller::GetView()
1798 return mImpl->mView;
1801 Vector3 Controller::GetNaturalSize()
1803 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
1804 Vector3 naturalSize;
1806 // Make sure the model is up-to-date before layouting
1807 ProcessModifyEvents();
1809 if( mImpl->mRecalculateNaturalSize )
1811 // Operations that can be done only once until the text changes.
1812 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1819 GET_GLYPH_METRICS );
1821 // Set the update info to relayout the whole text.
1822 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1823 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1825 // Make sure the model is up-to-date before layouting
1826 mImpl->UpdateModel( onlyOnceOperations );
1828 // Layout the text for the new width.
1829 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT | REORDER );
1831 // Store the actual control's size to restore later.
1832 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
1834 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
1835 static_cast<OperationsMask>( onlyOnceOperations |
1837 naturalSize.GetVectorXY() );
1839 // Do not do again the only once operations.
1840 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1842 // Do the size related operations again.
1843 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1846 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1848 // Stores the natural size to avoid recalculate it again
1849 // unless the text/style changes.
1850 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
1852 mImpl->mRecalculateNaturalSize = false;
1854 // Clear the update info. This info will be set the next time the text is updated.
1855 mImpl->mTextUpdateInfo.Clear();
1857 // Restore the actual control's size.
1858 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
1860 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1864 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
1866 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1869 naturalSize.x = ConvertToEven( naturalSize.x );
1870 naturalSize.y = ConvertToEven( naturalSize.y );
1875 float Controller::GetHeightForWidth( float width )
1877 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
1878 // Make sure the model is up-to-date before layouting
1879 ProcessModifyEvents();
1882 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ||
1883 mImpl->mTextUpdateInfo.mFullRelayoutNeeded ||
1884 mImpl->mTextUpdateInfo.mClearAll )
1886 // Operations that can be done only once until the text changes.
1887 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1894 GET_GLYPH_METRICS );
1896 // Set the update info to relayout the whole text.
1897 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1898 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1900 // Make sure the model is up-to-date before layouting
1901 mImpl->UpdateModel( onlyOnceOperations );
1904 // Layout the text for the new width.
1905 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
1907 // Store the actual control's width.
1908 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
1910 DoRelayout( Size( width, MAX_FLOAT ),
1911 static_cast<OperationsMask>( onlyOnceOperations |
1915 // Do not do again the only once operations.
1916 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1918 // Do the size related operations again.
1919 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1923 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1925 // Clear the update info. This info will be set the next time the text is updated.
1926 mImpl->mTextUpdateInfo.Clear();
1928 // Restore the actual control's width.
1929 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
1931 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
1935 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
1936 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
1939 return layoutSize.height;
1942 int Controller::GetLineCount( float width )
1944 GetHeightForWidth( width );
1945 int numberofLines = mImpl->mModel->GetNumberOfLines();
1946 return numberofLines;
1949 const ModelInterface* const Controller::GetTextModel() const
1951 return mImpl->mModel.Get();
1954 float Controller::GetScrollAmountByUserInput()
1956 float scrollAmount = 0.0f;
1958 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
1960 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
1961 mImpl->mEventData->mCheckScrollAmount = false;
1963 return scrollAmount;
1966 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
1968 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
1971 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
1972 layoutHeight = layout.height;
1973 scrollPosition = mImpl->mModel->mScrollPosition.y;
1974 isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
1978 void Controller::SetHiddenInputOption(const Property::Map& options )
1980 if( NULL == mImpl->mHiddenInput )
1982 mImpl->mHiddenInput = new HiddenText( this );
1984 mImpl->mHiddenInput->SetProperties(options);
1987 void Controller::GetHiddenInputOption(Property::Map& options )
1989 if( NULL != mImpl->mHiddenInput )
1991 mImpl->mHiddenInput->GetProperties(options);
1995 void Controller::SetPlaceholderProperty( const Property::Map& map )
1997 const Property::Map::SizeType count = map.Count();
1999 for( Property::Map::SizeType position = 0; position < count; ++position )
2001 KeyValuePair keyValue = map.GetKeyValue( position );
2002 Property::Key& key = keyValue.first;
2003 Property::Value& value = keyValue.second;
2005 if( key == Toolkit::Text::PlaceHolder::Property::TEXT || key == PLACEHOLDER_TEXT )
2007 std::string text = "";
2009 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
2011 else if( key == Toolkit::Text::PlaceHolder::Property::TEXT_FOCUSED || key == PLACEHOLDER_TEXT_FOCUSED )
2013 std::string text = "";
2015 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
2017 else if( key == Toolkit::Text::PlaceHolder::Property::COLOR || key == PLACEHOLDER_COLOR )
2020 value.Get( textColor );
2021 if( GetPlaceholderTextColor() != textColor )
2023 SetPlaceholderTextColor( textColor );
2026 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_FAMILY || key == PLACEHOLDER_FONT_FAMILY )
2028 std::string fontFamily = "";
2029 value.Get( fontFamily );
2030 SetPlaceholderFontFamily( fontFamily );
2032 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_STYLE || key == PLACEHOLDER_FONT_STYLE )
2034 SetFontStyleProperty( this, value, Text::FontStyle::PLACEHOLDER );
2036 else if( key == Toolkit::Text::PlaceHolder::Property::POINT_SIZE || key == PLACEHOLDER_POINT_SIZE )
2039 value.Get( pointSize );
2040 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
2042 SetPlaceholderTextFontSize( pointSize, Text::Controller::POINT_SIZE );
2045 else if( key == Toolkit::Text::PlaceHolder::Property::PIXEL_SIZE || key == PLACEHOLDER_PIXEL_SIZE )
2048 value.Get( pixelSize );
2049 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
2051 SetPlaceholderTextFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
2054 else if( key == Toolkit::Text::PlaceHolder::Property::ELLIPSIS || key == PLACEHOLDER_ELLIPSIS )
2057 value.Get( ellipsis );
2058 SetPlaceholderTextElideEnabled( ellipsis );
2063 void Controller::GetPlaceholderProperty( Property::Map& map )
2065 if( NULL != mImpl->mEventData )
2067 if( !mImpl->mEventData->mPlaceholderTextActive.empty() )
2069 map[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = mImpl->mEventData->mPlaceholderTextActive;
2071 if( !mImpl->mEventData->mPlaceholderTextInactive.empty() )
2073 map[ Text::PlaceHolder::Property::TEXT ] = mImpl->mEventData->mPlaceholderTextInactive;
2076 map[ Text::PlaceHolder::Property::COLOR ] = mImpl->mEventData->mPlaceholderTextColor;
2077 map[ Text::PlaceHolder::Property::FONT_FAMILY ] = GetPlaceholderFontFamily();
2079 Property::Value fontStyleMapGet;
2080 GetFontStyleProperty( this, fontStyleMapGet, Text::FontStyle::PLACEHOLDER );
2081 map[ Text::PlaceHolder::Property::FONT_STYLE ] = fontStyleMapGet;
2083 // Choose font size : POINT_SIZE or PIXEL_SIZE
2084 if( !mImpl->mEventData->mIsPlaceholderPixelSize )
2086 map[ Text::PlaceHolder::Property::POINT_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE );
2090 map[ Text::PlaceHolder::Property::PIXEL_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE );
2093 if( mImpl->mEventData->mPlaceholderEllipsisFlag )
2095 map[ Text::PlaceHolder::Property::ELLIPSIS ] = IsPlaceholderTextElideEnabled();
2100 // public : Relayout.
2102 Controller::UpdateTextType Controller::Relayout( const Size& size )
2104 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
2106 UpdateTextType updateTextType = NONE_UPDATED;
2108 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
2110 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
2112 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
2113 updateTextType = MODEL_UPDATED;
2116 // Clear the update info. This info will be set the next time the text is updated.
2117 mImpl->mTextUpdateInfo.Clear();
2119 // Not worth to relayout if width or height is equal to zero.
2120 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
2122 return updateTextType;
2125 // Whether a new size has been set.
2126 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
2130 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
2132 // Layout operations that need to be done if the size changes.
2133 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2136 UPDATE_LAYOUT_SIZE |
2138 // Set the update info to relayout the whole text.
2139 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2140 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2142 // Store the size used to layout the text.
2143 mImpl->mModel->mVisualModel->mControlSize = size;
2146 // Whether there are modify events.
2147 if( 0u != mImpl->mModifyEvents.Count() )
2149 // Style operations that need to be done if the text is modified.
2150 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2154 // Set the update info to elide the text.
2155 if( mImpl->mModel->mElideEnabled ||
2156 ( ( NULL != mImpl->mEventData ) && mImpl->mEventData->mIsPlaceholderElideEnabled ) )
2158 // Update Text layout for applying elided
2159 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2162 UPDATE_LAYOUT_SIZE |
2164 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2165 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2168 // Make sure the model is up-to-date before layouting.
2169 ProcessModifyEvents();
2170 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
2174 updated = DoRelayout( size,
2175 mImpl->mOperationsPending,
2176 layoutSize ) || updated;
2180 updateTextType = MODEL_UPDATED;
2183 // Do not re-do any operation until something changes.
2184 mImpl->mOperationsPending = NO_OPERATION;
2185 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
2187 // Whether the text control is editable
2188 const bool isEditable = NULL != mImpl->mEventData;
2190 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
2192 if( newSize && isEditable )
2194 offset = mImpl->mModel->mScrollPosition;
2197 if( !isEditable || !IsMultiLineEnabled() )
2199 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
2200 CalculateVerticalOffset( size );
2207 // If there is a new size, the scroll position needs to be clamped.
2208 mImpl->ClampHorizontalScroll( layoutSize );
2210 // Update the decorator's positions is needed if there is a new size.
2211 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
2214 // Move the cursor, grab handle etc.
2215 if( mImpl->ProcessInputEvents() )
2217 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
2221 // Clear the update info. This info will be set the next time the text is updated.
2222 mImpl->mTextUpdateInfo.Clear();
2223 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
2225 return updateTextType;
2228 void Controller::RequestRelayout()
2230 mImpl->RequestRelayout();
2233 // public : Input style change signals.
2235 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
2237 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
2240 void Controller::ProcessInputStyleChangedSignals()
2242 if( NULL == mImpl->mEventData )
2248 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
2249 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
2253 const InputStyle::Mask mask = *it;
2255 if( NULL != mImpl->mEditableControlInterface )
2257 // Emit the input style changed signal.
2258 mImpl->mEditableControlInterface->InputStyleChanged( mask );
2262 mImpl->mEventData->mInputStyleChangedQueue.Clear();
2265 // public : Text-input Event Queuing.
2267 void Controller::KeyboardFocusGainEvent()
2269 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
2271 if( NULL != mImpl->mEventData )
2273 if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
2274 ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
2276 mImpl->ChangeState( EventData::EDITING );
2277 mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
2278 mImpl->mEventData->mUpdateInputStyle = true;
2280 mImpl->NotifyImfMultiLineStatus();
2281 if( mImpl->IsShowingPlaceholderText() )
2283 // Show alternative placeholder-text when editing
2284 ShowPlaceholderText();
2287 mImpl->RequestRelayout();
2291 void Controller::KeyboardFocusLostEvent()
2293 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
2295 if( NULL != mImpl->mEventData )
2297 if( EventData::INTERRUPTED != mImpl->mEventData->mState )
2299 mImpl->ChangeState( EventData::INACTIVE );
2301 if( !mImpl->IsShowingRealText() )
2303 // Revert to regular placeholder-text when not editing
2304 ShowPlaceholderText();
2308 mImpl->RequestRelayout();
2311 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
2313 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
2315 bool textChanged = false;
2316 bool relayoutNeeded = false;
2318 if( ( NULL != mImpl->mEventData ) &&
2319 ( keyEvent.state == KeyEvent::Down ) )
2321 int keyCode = keyEvent.keyCode;
2322 const std::string& keyString = keyEvent.keyPressed;
2324 const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
2326 // Pre-process to separate modifying events from non-modifying input events.
2329 // In some platforms arrive key events with no key code.
2333 else if( Dali::DALI_KEY_ESCAPE == keyCode || Dali::DALI_KEY_BACK == keyCode || Dali::DALI_KEY_SEARCH == keyCode )
2338 else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) ||
2339 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
2340 ( Dali::DALI_KEY_CURSOR_UP == keyCode ) ||
2341 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) )
2343 // If don't have any text, do nothing.
2344 if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
2349 uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition;
2350 uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2351 uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition );
2352 uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines();
2354 // Logic to determine whether this text control will lose focus or not.
2355 if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition ) ||
2356 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition) ||
2357 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) ||
2358 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) ||
2359 ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) ||
2360 ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) )
2365 mImpl->mEventData->mCheckScrollAmount = true;
2366 Event event( Event::CURSOR_KEY_EVENT );
2367 event.p1.mInt = keyCode;
2368 mImpl->mEventData->mEventQueue.push_back( event );
2370 // Will request for relayout.
2371 relayoutNeeded = true;
2373 else if( Dali::DALI_KEY_BACKSPACE == keyCode )
2375 textChanged = BackspaceKeyEvent();
2377 // Will request for relayout.
2378 relayoutNeeded = true;
2380 else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
2381 IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
2382 IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
2384 // Power key/Menu/Home key behaviour does not allow edit mode to resume.
2385 mImpl->ChangeState( EventData::INACTIVE );
2387 // Will request for relayout.
2388 relayoutNeeded = true;
2390 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2392 else if( Dali::DALI_KEY_SHIFT_LEFT == keyCode )
2394 // DALI_KEY_SHIFT_LEFT is the key code for the Left Shift. It's sent (by the imf?) when the predictive text is enabled
2395 // and a character is typed after the type of a upper case latin character.
2400 else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
2402 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2408 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
2410 // IMF manager is no longer handling key-events
2411 mImpl->ClearPreEditFlag();
2413 InsertText( keyString, COMMIT );
2416 // Will request for relayout.
2417 relayoutNeeded = true;
2420 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
2421 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
2423 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
2424 ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
2425 ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
2427 // Should not change the state if the key is the shift send by the imf manager.
2428 // Otherwise, when the state is SELECTING the text controller can't send the right
2429 // surrounding info to the imf.
2430 mImpl->ChangeState( EventData::EDITING );
2432 // Will request for relayout.
2433 relayoutNeeded = true;
2436 if( relayoutNeeded )
2438 mImpl->RequestRelayout();
2443 ( NULL != mImpl->mEditableControlInterface ) )
2445 // Do this last since it provides callbacks into application code
2446 mImpl->mEditableControlInterface->TextChanged();
2452 void Controller::TapEvent( unsigned int tapCount, float x, float y )
2454 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
2456 if( NULL != mImpl->mEventData )
2458 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
2459 EventData::State state( mImpl->mEventData->mState );
2460 bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
2462 if( mImpl->IsClipboardVisible() )
2464 if( EventData::INACTIVE == state || EventData::EDITING == state)
2466 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2468 relayoutNeeded = true;
2470 else if( 1u == tapCount )
2472 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
2474 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
2477 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
2479 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2480 relayoutNeeded = true;
2484 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
2486 // Hide placeholder text
2490 if( EventData::INACTIVE == state )
2492 mImpl->ChangeState( EventData::EDITING );
2494 else if( !mImpl->IsClipboardEmpty() )
2496 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
2498 relayoutNeeded = true;
2501 else if( 2u == tapCount )
2503 if( mImpl->mEventData->mSelectionEnabled &&
2504 mImpl->IsShowingRealText() )
2506 relayoutNeeded = true;
2507 mImpl->mEventData->mIsLeftHandleSelected = true;
2508 mImpl->mEventData->mIsRightHandleSelected = true;
2512 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
2513 if( relayoutNeeded )
2515 Event event( Event::TAP_EVENT );
2516 event.p1.mUint = tapCount;
2517 event.p2.mFloat = x;
2518 event.p3.mFloat = y;
2519 mImpl->mEventData->mEventQueue.push_back( event );
2521 mImpl->RequestRelayout();
2525 // Reset keyboard as tap event has occurred.
2526 mImpl->ResetImfManager();
2529 void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
2531 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
2533 if( NULL != mImpl->mEventData )
2535 Event event( Event::PAN_EVENT );
2536 event.p1.mInt = state;
2537 event.p2.mFloat = displacement.x;
2538 event.p3.mFloat = displacement.y;
2539 mImpl->mEventData->mEventQueue.push_back( event );
2541 mImpl->RequestRelayout();
2545 void Controller::LongPressEvent( Gesture::State state, float x, float y )
2547 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
2549 if( ( state == Gesture::Started ) &&
2550 ( NULL != mImpl->mEventData ) )
2552 // The 1st long-press on inactive text-field is treated as tap
2553 if( EventData::INACTIVE == mImpl->mEventData->mState )
2555 mImpl->ChangeState( EventData::EDITING );
2557 Event event( Event::TAP_EVENT );
2559 event.p2.mFloat = x;
2560 event.p3.mFloat = y;
2561 mImpl->mEventData->mEventQueue.push_back( event );
2563 mImpl->RequestRelayout();
2565 else if( !mImpl->IsShowingRealText() )
2567 Event event( Event::LONG_PRESS_EVENT );
2568 event.p1.mInt = state;
2569 event.p2.mFloat = x;
2570 event.p3.mFloat = y;
2571 mImpl->mEventData->mEventQueue.push_back( event );
2572 mImpl->RequestRelayout();
2574 else if( !mImpl->IsClipboardVisible() )
2576 // Reset the imf manager to commit the pre-edit before selecting the text.
2577 mImpl->ResetImfManager();
2579 Event event( Event::LONG_PRESS_EVENT );
2580 event.p1.mInt = state;
2581 event.p2.mFloat = x;
2582 event.p3.mFloat = y;
2583 mImpl->mEventData->mEventQueue.push_back( event );
2584 mImpl->RequestRelayout();
2586 mImpl->mEventData->mIsLeftHandleSelected = true;
2587 mImpl->mEventData->mIsRightHandleSelected = true;
2592 ImfManager::ImfCallbackData Controller::OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
2594 // Whether the text needs to be relaid-out.
2595 bool requestRelayout = false;
2597 // Whether to retrieve the text and cursor position to be sent to the IMF manager.
2598 bool retrieveText = false;
2599 bool retrieveCursor = false;
2601 switch( imfEvent.eventName )
2603 case ImfManager::COMMIT:
2605 InsertText( imfEvent.predictiveString, Text::Controller::COMMIT );
2606 requestRelayout = true;
2607 retrieveCursor = true;
2610 case ImfManager::PREEDIT:
2612 InsertText( imfEvent.predictiveString, Text::Controller::PRE_EDIT );
2613 requestRelayout = true;
2614 retrieveCursor = true;
2617 case ImfManager::DELETESURROUNDING:
2619 const bool textDeleted = RemoveText( imfEvent.cursorOffset,
2620 imfEvent.numberOfChars,
2621 DONT_UPDATE_INPUT_STYLE );
2625 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2626 !mImpl->IsPlaceholderAvailable() )
2628 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2632 ShowPlaceholderText();
2634 mImpl->mEventData->mUpdateCursorPosition = true;
2635 mImpl->mEventData->mScrollAfterDelete = true;
2637 requestRelayout = true;
2641 case ImfManager::GETSURROUNDING:
2643 retrieveText = true;
2644 retrieveCursor = true;
2647 case ImfManager::PRIVATECOMMAND:
2649 // PRIVATECOMMAND event is just for getting the private command message
2650 retrieveText = true;
2651 retrieveCursor = true;
2654 case ImfManager::VOID:
2661 if( requestRelayout )
2663 mImpl->mOperationsPending = ALL_OPERATIONS;
2664 mImpl->RequestRelayout();
2668 CharacterIndex cursorPosition = 0u;
2669 Length numberOfWhiteSpaces = 0u;
2671 if( retrieveCursor )
2673 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
2675 cursorPosition = mImpl->GetLogicalCursorPosition();
2677 if( cursorPosition < numberOfWhiteSpaces )
2679 cursorPosition = 0u;
2683 cursorPosition -= numberOfWhiteSpaces;
2689 mImpl->GetText( numberOfWhiteSpaces, text );
2692 ImfManager::ImfCallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
2694 if( requestRelayout &&
2695 ( NULL != mImpl->mEditableControlInterface ) )
2697 // Do this last since it provides callbacks into application code
2698 mImpl->mEditableControlInterface->TextChanged();
2701 return callbackData;
2704 void Controller::PasteClipboardItemEvent()
2706 // Retrieve the clipboard contents first
2707 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
2708 std::string stringToPaste( notifier.GetContent() );
2710 // Commit the current pre-edit text; the contents of the clipboard should be appended
2711 mImpl->ResetImfManager();
2713 // Temporary disable hiding clipboard
2714 mImpl->SetClipboardHideEnable( false );
2717 PasteText( stringToPaste );
2719 mImpl->SetClipboardHideEnable( true );
2722 // protected : Inherit from Text::Decorator::ControllerInterface.
2724 void Controller::GetTargetSize( Vector2& targetSize )
2726 targetSize = mImpl->mModel->mVisualModel->mControlSize;
2729 void Controller::AddDecoration( Actor& actor, bool needsClipping )
2731 if( NULL != mImpl->mEditableControlInterface )
2733 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
2737 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
2739 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
2741 if( NULL != mImpl->mEventData )
2743 switch( handleType )
2747 Event event( Event::GRAB_HANDLE_EVENT );
2748 event.p1.mUint = state;
2749 event.p2.mFloat = x;
2750 event.p3.mFloat = y;
2752 mImpl->mEventData->mEventQueue.push_back( event );
2755 case LEFT_SELECTION_HANDLE:
2757 Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
2758 event.p1.mUint = state;
2759 event.p2.mFloat = x;
2760 event.p3.mFloat = y;
2762 mImpl->mEventData->mEventQueue.push_back( event );
2765 case RIGHT_SELECTION_HANDLE:
2767 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
2768 event.p1.mUint = state;
2769 event.p2.mFloat = x;
2770 event.p3.mFloat = y;
2772 mImpl->mEventData->mEventQueue.push_back( event );
2775 case LEFT_SELECTION_HANDLE_MARKER:
2776 case RIGHT_SELECTION_HANDLE_MARKER:
2778 // Markers do not move the handles.
2781 case HANDLE_TYPE_COUNT:
2783 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
2787 mImpl->RequestRelayout();
2791 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
2793 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
2795 if( NULL == mImpl->mEventData )
2802 case Toolkit::TextSelectionPopup::CUT:
2804 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
2805 mImpl->mOperationsPending = ALL_OPERATIONS;
2807 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2808 !mImpl->IsPlaceholderAvailable() )
2810 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2814 ShowPlaceholderText();
2817 mImpl->mEventData->mUpdateCursorPosition = true;
2818 mImpl->mEventData->mScrollAfterDelete = true;
2820 mImpl->RequestRelayout();
2822 if( NULL != mImpl->mEditableControlInterface )
2824 mImpl->mEditableControlInterface->TextChanged();
2828 case Toolkit::TextSelectionPopup::COPY:
2830 mImpl->SendSelectionToClipboard( false ); // Text not modified
2832 mImpl->mEventData->mUpdateCursorPosition = true;
2834 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
2837 case Toolkit::TextSelectionPopup::PASTE:
2839 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
2842 case Toolkit::TextSelectionPopup::SELECT:
2844 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
2846 if( mImpl->mEventData->mSelectionEnabled )
2848 // Creates a SELECT event.
2849 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
2853 case Toolkit::TextSelectionPopup::SELECT_ALL:
2855 // Creates a SELECT_ALL event
2856 SelectEvent( 0.f, 0.f, true );
2859 case Toolkit::TextSelectionPopup::CLIPBOARD:
2861 mImpl->ShowClipboard();
2864 case Toolkit::TextSelectionPopup::NONE:
2872 void Controller::DisplayTimeExpired()
2874 mImpl->mEventData->mUpdateCursorPosition = true;
2875 // Apply modifications to the model
2876 mImpl->mOperationsPending = ALL_OPERATIONS;
2878 mImpl->RequestRelayout();
2881 // private : Update.
2883 void Controller::InsertText( const std::string& text, Controller::InsertType type )
2885 bool removedPrevious = false;
2886 bool removedSelected = false;
2887 bool maxLengthReached = false;
2889 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
2891 if( NULL == mImpl->mEventData )
2896 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
2897 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
2898 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
2900 // TODO: At the moment the underline runs are only for pre-edit.
2901 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
2903 // Remove the previous IMF pre-edit.
2904 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
2906 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
2907 mImpl->mEventData->mPreEditLength,
2908 DONT_UPDATE_INPUT_STYLE );
2910 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
2911 mImpl->mEventData->mPreEditLength = 0u;
2915 // Remove the previous Selection.
2916 removedSelected = RemoveSelectedText();
2920 Vector<Character> utf32Characters;
2921 Length characterCount = 0u;
2925 // Convert text into UTF-32
2926 utf32Characters.Resize( text.size() );
2928 // This is a bit horrible but std::string returns a (signed) char*
2929 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
2931 // Transform a text array encoded in utf8 into an array encoded in utf32.
2932 // It returns the actual number of characters.
2933 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
2934 utf32Characters.Resize( characterCount );
2936 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
2937 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
2940 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
2942 // The placeholder text is no longer needed
2943 if( mImpl->IsShowingPlaceholderText() )
2948 mImpl->ChangeState( EventData::EDITING );
2950 // Handle the IMF (predicitive text) state changes
2951 if( COMMIT == type )
2953 // IMF manager is no longer handling key-events
2954 mImpl->ClearPreEditFlag();
2958 if( !mImpl->mEventData->mPreEditFlag )
2960 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
2962 // Record the start of the pre-edit text
2963 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
2966 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
2967 mImpl->mEventData->mPreEditFlag = true;
2969 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
2972 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
2974 // Restrict new text to fit within Maximum characters setting.
2975 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
2976 maxLengthReached = ( characterCount > maxSizeOfNewText );
2978 // The cursor position.
2979 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
2981 // Update the text's style.
2983 // Updates the text style runs by adding characters.
2984 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
2986 // Get the character index from the cursor index.
2987 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
2989 // Retrieve the text's style for the given index.
2991 mImpl->RetrieveDefaultInputStyle( style );
2992 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
2994 // Whether to add a new text color run.
2995 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor );
2997 // Whether to add a new font run.
2998 const bool addFontNameRun = style.familyName != mImpl->mEventData->mInputStyle.familyName;
2999 const bool addFontWeightRun = style.weight != mImpl->mEventData->mInputStyle.weight;
3000 const bool addFontWidthRun = style.width != mImpl->mEventData->mInputStyle.width;
3001 const bool addFontSlantRun = style.slant != mImpl->mEventData->mInputStyle.slant;
3002 const bool addFontSizeRun = style.size != mImpl->mEventData->mInputStyle.size;
3007 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
3008 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
3010 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
3011 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
3012 colorRun.characterRun.characterIndex = cursorIndex;
3013 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3016 if( addFontNameRun ||
3022 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
3023 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
3025 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
3027 if( addFontNameRun )
3029 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
3030 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
3031 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
3032 fontDescriptionRun.familyDefined = true;
3034 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
3037 if( addFontWeightRun )
3039 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
3040 fontDescriptionRun.weightDefined = true;
3043 if( addFontWidthRun )
3045 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
3046 fontDescriptionRun.widthDefined = true;
3049 if( addFontSlantRun )
3051 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
3052 fontDescriptionRun.slantDefined = true;
3055 if( addFontSizeRun )
3057 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
3058 fontDescriptionRun.sizeDefined = true;
3061 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
3062 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3065 // Insert at current cursor position.
3066 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
3068 if( cursorIndex < numberOfCharactersInModel )
3070 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3074 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3077 // Mark the first paragraph to be updated.
3078 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3080 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3081 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3082 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
3083 mImpl->mTextUpdateInfo.mClearAll = true;
3087 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3088 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
3091 // Update the cursor index.
3092 cursorIndex += maxSizeOfNewText;
3094 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 );
3097 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
3098 mImpl->IsPlaceholderAvailable() )
3100 // Show place-holder if empty after removing the pre-edit text
3101 ShowPlaceholderText();
3102 mImpl->mEventData->mUpdateCursorPosition = true;
3103 mImpl->ClearPreEditFlag();
3105 else if( removedPrevious ||
3107 ( 0 != utf32Characters.Count() ) )
3109 // Queue an inserted event
3110 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
3112 mImpl->mEventData->mUpdateCursorPosition = true;
3113 if( removedSelected )
3115 mImpl->mEventData->mScrollAfterDelete = true;
3119 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3123 if( maxLengthReached )
3125 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
3127 mImpl->ResetImfManager();
3129 if( NULL != mImpl->mEditableControlInterface )
3131 // Do this last since it provides callbacks into application code
3132 mImpl->mEditableControlInterface->MaxLengthReached();
3137 void Controller::PasteText( const std::string& stringToPaste )
3139 InsertText( stringToPaste, Text::Controller::COMMIT );
3140 mImpl->ChangeState( EventData::EDITING );
3141 mImpl->RequestRelayout();
3143 if( NULL != mImpl->mEditableControlInterface )
3145 // Do this last since it provides callbacks into application code
3146 mImpl->mEditableControlInterface->TextChanged();
3150 bool Controller::RemoveText( int cursorOffset,
3151 int numberOfCharacters,
3152 UpdateInputStyleType type )
3154 bool removed = false;
3156 if( NULL == mImpl->mEventData )
3161 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
3162 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
3164 if( !mImpl->IsShowingPlaceholderText() )
3166 // Delete at current cursor position
3167 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
3168 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3170 CharacterIndex cursorIndex = 0;
3172 // Validate the cursor position & number of characters
3173 if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
3175 cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
3178 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
3180 numberOfCharacters = currentText.Count() - cursorIndex;
3183 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.
3184 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
3186 // Mark the paragraphs to be updated.
3187 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3189 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3190 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3191 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
3192 mImpl->mTextUpdateInfo.mClearAll = true;
3196 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3197 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
3200 // Update the input style and remove the text's style before removing the text.
3202 if( UPDATE_INPUT_STYLE == type )
3204 // Keep a copy of the current input style.
3205 InputStyle currentInputStyle;
3206 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
3208 // Set first the default input style.
3209 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
3211 // Update the input style.
3212 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
3214 // Compare if the input style has changed.
3215 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
3217 if( hasInputStyleChanged )
3219 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
3220 // Queue the input style changed signal.
3221 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
3225 // Updates the text style runs by removing characters. Runs with no characters are removed.
3226 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
3228 // Remove the characters.
3229 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
3230 Vector<Character>::Iterator last = first + numberOfCharacters;
3232 currentText.Erase( first, last );
3234 // Cursor position retreat
3235 oldCursorIndex = cursorIndex;
3237 mImpl->mEventData->mScrollAfterDelete = true;
3239 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
3247 bool Controller::RemoveSelectedText()
3249 bool textRemoved( false );
3251 if( EventData::SELECTING == mImpl->mEventData->mState )
3253 std::string removedString;
3254 mImpl->RetrieveSelection( removedString, true );
3256 if( !removedString.empty() )
3259 mImpl->ChangeState( EventData::EDITING );
3266 // private : Relayout.
3268 bool Controller::DoRelayout( const Size& size,
3269 OperationsMask operationsRequired,
3272 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
3273 bool viewUpdated( false );
3275 // Calculate the operations to be done.
3276 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
3278 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
3279 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
3281 // Get the current layout size.
3282 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3284 if( NO_OPERATION != ( LAYOUT & operations ) )
3286 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
3288 // Some vectors with data needed to layout and reorder may be void
3289 // after the first time the text has been laid out.
3290 // Fill the vectors again.
3292 // Calculate the number of glyphs to layout.
3293 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
3294 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
3295 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
3296 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
3298 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
3299 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
3300 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
3301 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
3303 if( 0u == totalNumberOfGlyphs )
3305 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3307 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
3310 // Nothing else to do if there is no glyphs.
3311 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
3315 const Vector<LineBreakInfo>& lineBreakInfo = mImpl->mModel->mLogicalModel->mLineBreakInfo;
3316 const Vector<WordBreakInfo>& wordBreakInfo = mImpl->mModel->mLogicalModel->mWordBreakInfo;
3317 const Vector<CharacterDirection>& characterDirection = mImpl->mModel->mLogicalModel->mCharacterDirections;
3318 const Vector<GlyphInfo>& glyphs = mImpl->mModel->mVisualModel->mGlyphs;
3319 const Vector<CharacterIndex>& glyphsToCharactersMap = mImpl->mModel->mVisualModel->mGlyphsToCharacters;
3320 const Vector<Length>& charactersPerGlyph = mImpl->mModel->mVisualModel->mCharactersPerGlyph;
3321 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
3323 // Set the layout parameters.
3324 Layout::Parameters layoutParameters( size,
3326 lineBreakInfo.Begin(),
3327 wordBreakInfo.Begin(),
3328 ( 0u != characterDirection.Count() ) ? characterDirection.Begin() : NULL,
3330 glyphsToCharactersMap.Begin(),
3331 charactersPerGlyph.Begin(),
3332 charactersToGlyphBuffer,
3333 glyphsPerCharacterBuffer,
3334 totalNumberOfGlyphs,
3335 mImpl->mModel->mHorizontalAlignment,
3336 mImpl->mModel->mLineWrapMode );
3338 // Resize the vector of positions to have the same size than the vector of glyphs.
3339 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
3340 glyphPositions.Resize( totalNumberOfGlyphs );
3342 // Whether the last character is a new paragraph character.
3343 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
3344 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
3346 // The initial glyph and the number of glyphs to layout.
3347 layoutParameters.startGlyphIndex = startGlyphIndex;
3348 layoutParameters.numberOfGlyphs = numberOfGlyphs;
3349 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
3350 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
3352 // Update the ellipsis
3353 bool elideTextEnabled = mImpl->mModel->mElideEnabled;
3355 if( NULL != mImpl->mEventData )
3357 if( mImpl->mEventData->mPlaceholderEllipsisFlag && mImpl->IsShowingPlaceholderText() )
3359 elideTextEnabled = mImpl->mEventData->mIsPlaceholderElideEnabled;
3361 else if( EventData::INACTIVE != mImpl->mEventData->mState )
3363 // Disable ellipsis when editing
3364 elideTextEnabled = false;
3367 // Reset the scroll position in inactive state
3368 if( elideTextEnabled && ( mImpl->mEventData->mState == EventData::INACTIVE ) )
3370 ResetScrollPosition();
3374 // Update the visual model.
3376 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
3378 mImpl->mModel->mVisualModel->mLines,
3382 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
3386 layoutSize = newLayoutSize;
3388 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
3390 mImpl->mAutoScrollDirectionRTL = false;
3393 // Reorder the lines
3394 if( NO_OPERATION != ( REORDER & operations ) )
3396 Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = mImpl->mModel->mLogicalModel->mBidirectionalParagraphInfo;
3397 Vector<BidirectionalLineInfoRun>& bidirectionalLineInfo = mImpl->mModel->mLogicalModel->mBidirectionalLineInfo;
3399 // Check first if there are paragraphs with bidirectional info.
3400 if( 0u != bidirectionalInfo.Count() )
3403 const Length numberOfLines = mImpl->mModel->mVisualModel->mLines.Count();
3405 // Reorder the lines.
3406 bidirectionalLineInfo.Reserve( numberOfLines ); // Reserve because is not known yet how many lines have right to left characters.
3407 ReorderLines( bidirectionalInfo,
3409 requestedNumberOfCharacters,
3410 mImpl->mModel->mVisualModel->mLines,
3411 bidirectionalLineInfo );
3413 // Set the bidirectional info per line into the layout parameters.
3414 layoutParameters.lineBidirectionalInfoRunsBuffer = bidirectionalLineInfo.Begin();
3415 layoutParameters.numberOfBidirectionalInfoRuns = bidirectionalLineInfo.Count();
3417 // Re-layout the text. Reorder those lines with right to left characters.
3418 mImpl->mLayoutEngine.ReLayoutRightToLeftLines( layoutParameters,
3420 requestedNumberOfCharacters,
3423 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && ( numberOfLines > 0 ) )
3425 const LineRun* const firstline = mImpl->mModel->mVisualModel->mLines.Begin();
3428 mImpl->mAutoScrollDirectionRTL = firstline->direction;
3434 // Sets the layout size.
3435 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3437 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
3442 if( NO_OPERATION != ( ALIGN & operations ) )
3444 // The laid-out lines.
3445 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
3447 // Need to align with the control's size as the text may contain lines
3448 // starting either with left to right text or right to left.
3449 mImpl->mLayoutEngine.Align( size,
3451 requestedNumberOfCharacters,
3452 mImpl->mModel->mHorizontalAlignment,
3454 mImpl->mModel->mAlignmentOffset );
3458 #if defined(DEBUG_ENABLED)
3459 std::string currentText;
3460 GetText( currentText );
3461 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mAutoScrollDirectionRTL[%s] [%s]\n", this, (mImpl->mAutoScrollDirectionRTL)?"true":"false", currentText.c_str() );
3463 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
3467 void Controller::CalculateVerticalOffset( const Size& controlSize )
3469 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3471 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
3473 // Get the line height of the default font.
3474 layoutSize.height = mImpl->GetDefaultFontLineHeight();
3477 switch( mImpl->mModel->mVerticalAlignment )
3479 case VerticalAlignment::TOP:
3481 mImpl->mModel->mScrollPosition.y = 0.f;
3484 case VerticalAlignment::CENTER:
3486 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
3489 case VerticalAlignment::BOTTOM:
3491 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
3497 // private : Events.
3499 void Controller::ProcessModifyEvents()
3501 Vector<ModifyEvent>& events = mImpl->mModifyEvents;
3503 if( 0u == events.Count() )
3509 for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
3510 endIt = events.End();
3514 const ModifyEvent& event = *it;
3516 if( ModifyEvent::TEXT_REPLACED == event.type )
3518 // A (single) replace event should come first, otherwise we wasted time processing NOOP events
3519 DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
3521 TextReplacedEvent();
3523 else if( ModifyEvent::TEXT_INSERTED == event.type )
3525 TextInsertedEvent();
3527 else if( ModifyEvent::TEXT_DELETED == event.type )
3529 // Placeholder-text cannot be deleted
3530 if( !mImpl->IsShowingPlaceholderText() )
3537 if( NULL != mImpl->mEventData )
3539 // When the text is being modified, delay cursor blinking
3540 mImpl->mEventData->mDecorator->DelayCursorBlink();
3543 // Discard temporary text
3547 void Controller::TextReplacedEvent()
3549 // The natural size needs to be re-calculated.
3550 mImpl->mRecalculateNaturalSize = true;
3552 // Apply modifications to the model
3553 mImpl->mOperationsPending = ALL_OPERATIONS;
3556 void Controller::TextInsertedEvent()
3558 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
3560 if( NULL == mImpl->mEventData )
3565 mImpl->mEventData->mCheckScrollAmount = true;
3567 // The natural size needs to be re-calculated.
3568 mImpl->mRecalculateNaturalSize = true;
3570 // Apply modifications to the model; TODO - Optimize this
3571 mImpl->mOperationsPending = ALL_OPERATIONS;
3574 void Controller::TextDeletedEvent()
3576 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
3578 if( NULL == mImpl->mEventData )
3583 mImpl->mEventData->mCheckScrollAmount = true;
3585 // The natural size needs to be re-calculated.
3586 mImpl->mRecalculateNaturalSize = true;
3588 // Apply modifications to the model; TODO - Optimize this
3589 mImpl->mOperationsPending = ALL_OPERATIONS;
3592 void Controller::SelectEvent( float x, float y, bool selectAll )
3594 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
3596 if( NULL != mImpl->mEventData )
3600 Event event( Event::SELECT_ALL );
3601 mImpl->mEventData->mEventQueue.push_back( event );
3605 Event event( Event::SELECT );
3606 event.p2.mFloat = x;
3607 event.p3.mFloat = y;
3608 mImpl->mEventData->mEventQueue.push_back( event );
3611 mImpl->mEventData->mCheckScrollAmount = true;
3612 mImpl->mEventData->mIsLeftHandleSelected = true;
3613 mImpl->mEventData->mIsRightHandleSelected = true;
3614 mImpl->RequestRelayout();
3618 bool Controller::BackspaceKeyEvent()
3620 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p DALI_KEY_BACKSPACE\n", this );
3622 bool removed = false;
3624 if( NULL == mImpl->mEventData )
3629 // IMF manager is no longer handling key-events
3630 mImpl->ClearPreEditFlag();
3632 if( EventData::SELECTING == mImpl->mEventData->mState )
3634 removed = RemoveSelectedText();
3636 else if( mImpl->mEventData->mPrimaryCursorPosition > 0 )
3638 // Remove the character before the current cursor position
3639 removed = RemoveText( -1,
3641 UPDATE_INPUT_STYLE );
3646 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3647 !mImpl->IsPlaceholderAvailable() )
3649 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3653 ShowPlaceholderText();
3655 mImpl->mEventData->mUpdateCursorPosition = true;
3656 mImpl->mEventData->mScrollAfterDelete = true;
3662 // private : Helpers.
3664 void Controller::ResetText()
3667 mImpl->mModel->mLogicalModel->mText.Clear();
3669 // We have cleared everything including the placeholder-text
3670 mImpl->PlaceholderCleared();
3672 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3673 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3674 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
3676 // Clear any previous text.
3677 mImpl->mTextUpdateInfo.mClearAll = true;
3679 // The natural size needs to be re-calculated.
3680 mImpl->mRecalculateNaturalSize = true;
3682 // Apply modifications to the model
3683 mImpl->mOperationsPending = ALL_OPERATIONS;
3686 void Controller::ShowPlaceholderText()
3688 if( mImpl->IsPlaceholderAvailable() )
3690 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
3692 if( NULL == mImpl->mEventData )
3697 mImpl->mEventData->mIsShowingPlaceholderText = true;
3699 // Disable handles when showing place-holder text
3700 mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
3701 mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
3702 mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
3704 const char* text( NULL );
3707 // TODO - Switch Placeholder text when changing state
3708 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
3709 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
3711 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
3712 size = mImpl->mEventData->mPlaceholderTextActive.size();
3716 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
3717 size = mImpl->mEventData->mPlaceholderTextInactive.size();
3720 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3721 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3723 // Reset model for showing placeholder.
3724 mImpl->mModel->mLogicalModel->mText.Clear();
3725 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
3727 // Convert text into UTF-32
3728 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
3729 utf32Characters.Resize( size );
3731 // This is a bit horrible but std::string returns a (signed) char*
3732 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
3734 // Transform a text array encoded in utf8 into an array encoded in utf32.
3735 // It returns the actual number of characters.
3736 const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
3737 utf32Characters.Resize( characterCount );
3739 // The characters to be added.
3740 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
3742 // Reset the cursor position
3743 mImpl->mEventData->mPrimaryCursorPosition = 0;
3745 // The natural size needs to be re-calculated.
3746 mImpl->mRecalculateNaturalSize = true;
3748 // Apply modifications to the model
3749 mImpl->mOperationsPending = ALL_OPERATIONS;
3751 // Update the rest of the model during size negotiation
3752 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
3756 void Controller::ClearFontData()
3758 if( mImpl->mFontDefaults )
3760 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
3763 // Set flags to update the model.
3764 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3765 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3766 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
3768 mImpl->mTextUpdateInfo.mClearAll = true;
3769 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
3770 mImpl->mRecalculateNaturalSize = true;
3772 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
3777 UPDATE_LAYOUT_SIZE |
3782 void Controller::ClearStyleData()
3784 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
3785 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
3788 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
3790 // Reset the cursor position
3791 if( NULL != mImpl->mEventData )
3793 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
3795 // Update the cursor if it's in editing mode.
3796 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
3798 mImpl->mEventData->mUpdateCursorPosition = true;
3803 void Controller::ResetScrollPosition()
3805 if( NULL != mImpl->mEventData )
3807 // Reset the scroll position.
3808 mImpl->mModel->mScrollPosition = Vector2::ZERO;
3809 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3813 void Controller::SetControlInterface( ControlInterface* controlInterface )
3815 mImpl->mControlInterface = controlInterface;
3818 bool Controller::ShouldClearFocusOnEscape() const
3820 return mImpl->mShouldClearFocusOnEscape;
3823 // private : Private contructors & copy operator.
3825 Controller::Controller()
3828 mImpl = new Controller::Impl( NULL, NULL );
3831 Controller::Controller( ControlInterface* controlInterface )
3833 mImpl = new Controller::Impl( controlInterface, NULL );
3836 Controller::Controller( ControlInterface* controlInterface,
3837 EditableControlInterface* editableControlInterface )
3839 mImpl = new Controller::Impl( controlInterface,
3840 editableControlInterface );
3843 // The copy constructor and operator are left unimplemented.
3845 // protected : Destructor.
3847 Controller::~Controller()
3854 } // namespace Toolkit